-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Vafilor/feat/image-cache
Cache image icons when viewing files in icon mode
- Loading branch information
Showing
22 changed files
with
1,090 additions
and
27 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import useAwaitValue from "app/hooks/useAwaitValue"; | ||
import FileSystemClient from "app/services/filesystem-client"; | ||
import ImageFile from "../file-view/image-file"; | ||
import Rectangle from "../loading/rectangle"; | ||
|
||
type Props = Omit< | ||
React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, | ||
"src" | "width" | "height"> & { src: string, width: number, height: number } | ||
|
||
export default function IconImage({ src, width, height, ...otherProps }: Props) { | ||
const { value: cachedImagePath, loading, error } = useAwaitValue(() => FileSystemClient.instance.getImageIconPath(src, width, height)); | ||
|
||
if (loading) { | ||
return <Rectangle width={width} height={height} /> | ||
} | ||
|
||
if (error) { | ||
return <div>Error</div>; | ||
} | ||
|
||
return <ImageFile | ||
src={cachedImagePath} | ||
width={width} | ||
height={height} | ||
{...otherProps} | ||
/> | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import useAwaitValue from "app/hooks/useAwaitValue"; | ||
import FileSystemClient from "app/services/filesystem-client"; | ||
import PathClient from "app/services/path" | ||
import { useEffect, useRef } from "react"; | ||
|
||
interface Props { | ||
src: string; | ||
} | ||
|
||
export default function HeicImageFile({ src }: Props) { | ||
const ref = useRef<HTMLCanvasElement | null>(null); | ||
|
||
const data = useAwaitValue(() => FileSystemClient.instance.getHeicFile( | ||
PathClient.instance.toLocalURL(src)) | ||
); | ||
|
||
useEffect(() => { | ||
if (!ref.current) { | ||
return; | ||
} | ||
|
||
if (!data.value) { | ||
return; | ||
} | ||
|
||
const context = ref.current.getContext('2d'); | ||
if (!context) { | ||
return; | ||
} | ||
|
||
ref.current.width = data.value.width; | ||
ref.current.height = data.value.height; | ||
|
||
const imageData = new ImageData(data.value.data, data.value.width, data.value.height); | ||
|
||
context.putImageData(imageData, 0, 0); | ||
}, [data]); | ||
|
||
return ( | ||
<canvas ref={ref}></canvas> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Rectangle from "./rectangle"; | ||
|
||
interface Props { | ||
width?: number | string; | ||
height?: number | string; | ||
count: number; | ||
gap: number; | ||
className?: string; | ||
} | ||
|
||
export function RectangleList({ width, height, count, gap, className }: Props) { | ||
return ( | ||
<div className={"flex flex-col" + (className || "")} style={{ gap, width }}> | ||
{(new Array(count).fill(0)).map((_, index) => ( | ||
<Rectangle key={index} width={width} height={height} /> | ||
))} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
interface Props { | ||
width?: number | string; | ||
height?: number | string; | ||
} | ||
|
||
export default function Rectangle({ width, height }: Props) { | ||
return ( | ||
<div className="animate-pulse rounded bg-slate-200" style={{ width, height }}> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { access, constants } from "node:fs/promises"; | ||
|
||
export async function fileExists(path: string): Promise<boolean> { | ||
try { | ||
await access(path, constants.F_OK); | ||
return true; | ||
} catch (e: unknown) { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.