-
Notifications
You must be signed in to change notification settings - Fork 31
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 #57 from nini22P/dev
Improve metadata persistence
- Loading branch information
Showing
6 changed files
with
122 additions
and
98 deletions.
There are no files selected for viewing
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
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,24 @@ | ||
import { MetaData } from '../types/MetaData' | ||
import { filePathConvert } from '../utils' | ||
import { get, set, clear, entries, createStore } from 'idb-keyval' | ||
|
||
const useLocalMetaDataStore = () => { | ||
|
||
const metaDataStore = createStore('metadata', 'metadata-store') | ||
|
||
const getLocalMetaData = async (filePath: MetaData['path']) => { | ||
const metaData = await get(filePathConvert(filePath), metaDataStore) | ||
return metaData ? JSON.parse(metaData) : null | ||
} | ||
|
||
const setLocalMetaData = async (metaData: MetaData) => await set(filePathConvert(metaData.path), JSON.stringify(metaData), metaDataStore) | ||
|
||
const getAllLocalMetaData = async () => await entries(metaDataStore) | ||
|
||
const clearLocalMetaData = async () => await clear(metaDataStore) | ||
|
||
return { getLocalMetaData, setLocalMetaData, getAllLocalMetaData, clearLocalMetaData } | ||
|
||
} | ||
|
||
export default useLocalMetaDataStore |
This file was deleted.
Oops, something went wrong.