useDb hook

This commit is contained in:
2023-02-01 19:48:35 +00:00
parent 48407d9198
commit 59ff5de651
7 changed files with 210 additions and 205 deletions

View File

@ -61,8 +61,14 @@ export interface UserPreferences {
*/
imgProxyConfig: ImgProxySettings | null
}
export type DbType = "indexdDb" | "redux";
export interface LoginStore {
/**
* Which db we will use to cache data
*/
useDb: DbType,
/**
* If there is no login
*/
@ -146,6 +152,7 @@ const DefaultImgProxy = {
};
export const InitState = {
useDb: "redux",
loggedOut: undefined,
publicKey: undefined,
privateKey: undefined,
@ -186,7 +193,8 @@ const LoginSlice = createSlice({
name: "Login",
initialState: InitState,
reducers: {
init: (state) => {
init: (state, action: PayloadAction<DbType>) => {
state.useDb = action.payload;
state.privateKey = window.localStorage.getItem(PrivateKeyItem) ?? undefined;
if (state.privateKey) {
window.localStorage.removeItem(PublicKeyItem); // reset nip07 if using private key