Move scrubbing vtt parsing to a hook

This commit is contained in:
Zoe Roux 2024-01-24 12:35:26 +01:00
parent 7193a599b7
commit 5efcfb8b61

View File

@ -31,9 +31,9 @@ import { toTimerString } from "./left-buttons";
type Thumb = { to: number; url: string; x: number; y: number; width: number; height: number };
export const BottomScrubber = ({ url }: { url: string }) => {
const { css } = useYoshiki();
const { data, error } = useFetch(BottomScrubber.query(url));
export const useScrubber = (url: string) => {
const { data, error } = useFetch(useScrubber.query(url));
// TODO: put the info here on the react-query cache to prevent multiples runs of this
const info = useMemo(() => {
if (!data) return [];
@ -67,6 +67,21 @@ export const BottomScrubber = ({ url }: { url: string }) => {
return ret;
}, [data]);
return { info, error } as const;
};
useScrubber.query = (url: string): QueryIdentifier<string> => ({
path: ["video", url, "thumbnails.vtt"],
parser: null!,
options: {
plainText: true,
},
});
export const BottomScrubber = ({ url }: { url: string }) => {
const { css } = useYoshiki();
const { info, error } = useScrubber(url);
const progress = useAtomValue(progressAtom);
const duration = useAtomValue(durationAtom);
@ -142,11 +157,3 @@ export const BottomScrubber = ({ url }: { url: string }) => {
</View>
);
};
BottomScrubber.query = (url: string): QueryIdentifier<string> => ({
path: ["video", url, "thumbnails.vtt"],
parser: null!,
options: {
plainText: true,
},
});