unified library options (#168)

* Unified the way options are being handled. now everything uses the LibraryOptionsContext, removed the no-longer used useLibraryOptions hook

* removed query from library options. since it doesn't make sense for this to be cached

* fixed a bug in the useLocalStorage implementation
This commit is contained in:
amr
2022-04-07 12:53:14 +02:00
committed by GitHub
parent ee9c3d8c69
commit 13e6456190
7 changed files with 92 additions and 90 deletions

View File

@@ -8,16 +8,37 @@
import React, { useContext } from 'react';
type ContextType = {
// display options
options: LibraryDisplayOptions;
setOptions: React.Dispatch<React.SetStateAction<LibraryDisplayOptions>>;
options: LibraryOptions;
setOption: <Name extends keyof LibraryOptions>(
name: Name,
value: React.SetStateAction<LibraryOptions[Name]>
) => void;
setOptions: React.Dispatch<React.SetStateAction<LibraryOptions>>;
active: boolean
activeSort: boolean
};
export const DefaultLibraryOptions: LibraryOptions = {
showDownloadBadge: false,
showUnreadBadge: false,
gridLayout: 0,
SourcegridLayout: 0,
downloaded: undefined,
sortDesc: undefined,
sorts: undefined,
unread: undefined,
};
const LibraryOptionsContext = React.createContext<ContextType>({
options: {
showDownloadBadge: false, showUnreadBadge: false, gridLayout: 0, SourcegridLayout: 0,
},
options: DefaultLibraryOptions,
setOption: () => {},
setOptions: () => {},
active: false,
activeSort: false,
});
export default LibraryOptionsContext;