Download apps/readest-app/src/app/reader/hooks/useProgressAutoSave.ts from echodict/readest: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/datasets/echodict/readest/resolve/main/apps/readest-app/src/app/reader/hooks/useProgressAutoSave.ts
- Command line
-
hf download hf://datasets/echodict/readest/apps/readest-app/src/app/reader/hooks/useProgressAutoSave.ts
-
curl -L -o useProgressAutoSave.ts https://huggingface.co/datasets/echodict/readest/resolve/main/apps/readest-app/src/app/reader/hooks/useProgressAutoSave.ts
1.04 kB
| import { useCallback, useEffect } from 'react'; | |
| import { useEnv } from '@/context/EnvContext'; | |
| import { useBookDataStore } from '@/store/bookDataStore'; | |
| import { useReaderStore } from '@/store/readerStore'; | |
| import { useSettingsStore } from '@/store/settingsStore'; | |
| import { throttle } from '@/utils/throttle'; | |
| export const useProgressAutoSave = (bookKey: string) => { | |
| const { envConfig } = useEnv(); | |
| const { getConfig, saveConfig } = useBookDataStore(); | |
| const { getProgress } = useReaderStore(); | |
| const progress = getProgress(bookKey); | |
| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| const saveBookConfig = useCallback( | |
| throttle(() => { | |
| setTimeout(async () => { | |
| const config = getConfig(bookKey)!; | |
| const settings = useSettingsStore.getState().settings; | |
| await saveConfig(envConfig, bookKey, config, settings); | |
| }, 5000); | |
| }, 10000), | |
| [], | |
| ); | |
| useEffect(() => { | |
| saveBookConfig(); | |
| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| }, [progress, bookKey]); | |
| }; | |