move code to utils/file

This commit is contained in:
lloydzhou
2024-07-15 20:26:03 +08:00
parent 33450ce429
commit 5df09d5e2a
4 changed files with 40 additions and 32 deletions

View File

@@ -29,10 +29,9 @@ import {
showConfirm,
showImageModal,
showModal,
IndexDBImage,
} from "@/app/components/ui-lib";
import { func } from "prop-types";
import { useFileDB } from "@/app/utils/file";
import { useFileDB, IndexDBImage } from "@/app/utils/file";
function getSdTaskStatus(item: any) {
let s: string;

View File

@@ -511,29 +511,3 @@ export function Selector<T>(props: {
</div>
);
}
export function IndexDBImage({ src, alt, onClick, db, className }) {
const [data, setData] = useState(src);
const imgId = useMemo(
() => src.replace("indexeddb://", "").split("@").pop(),
[src],
);
useEffect(() => {
db.getByID(imgId)
.then(({ data }) => {
setData(`data:image/png;base64,${data}`);
})
.catch((e) => {
setData(src);
});
}, [src, imgId]);
return (
<img
className={className}
src={data}
alt={alt}
onClick={(e) => onClick(data, e)}
/>
);
}