Download apps/readest-app/src/hooks/useLibrary.ts from echodict/readest: direct link, hf CLI and curl.
- Browser
- Download file 959 Bytes
-
https://huggingface.co/datasets/echodict/readest/resolve/main/apps/readest-app/src/hooks/useLibrary.ts
- Command line
-
hf download hf://datasets/echodict/readest/apps/readest-app/src/hooks/useLibrary.ts
-
curl -L -o useLibrary.ts https://huggingface.co/datasets/echodict/readest/resolve/main/apps/readest-app/src/hooks/useLibrary.ts
959 Bytes
| import { useEffect, useRef, useState } from 'react'; | |
| import { useEnv } from '@/context/EnvContext'; | |
| import { useLibraryStore } from '@/store/libraryStore'; | |
| import { useSettingsStore } from '@/store/settingsStore'; | |
| export const useLibrary = () => { | |
| const { envConfig } = useEnv(); | |
| const { setLibrary } = useLibraryStore(); | |
| const { setSettings } = useSettingsStore(); | |
| const [libraryLoaded, setLibraryLoaded] = useState(false); | |
| const isInitiating = useRef(false); | |
| useEffect(() => { | |
| if (isInitiating.current) return; | |
| isInitiating.current = true; | |
| const initLibrary = async () => { | |
| const appService = await envConfig.getAppService(); | |
| const settings = await appService.loadSettings(); | |
| setSettings(settings); | |
| setLibrary(await appService.loadLibraryBooks()); | |
| setLibraryLoaded(true); | |
| }; | |
| initLibrary(); | |
| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| }, []); | |
| return { libraryLoaded }; | |
| }; | |