refactor(reducers): match state types and reducers

This commit is contained in:
enes 2024-10-08 18:42:34 +02:00
parent d610c79cad
commit ad2ec070be
4 changed files with 7 additions and 15 deletions

View File

@ -8,7 +8,7 @@ const initialState: AuthState = {
const reducer = (
state = initialState,
action: AuthDispatchTypes
): AuthState | null => {
): AuthState => {
switch (action.type) {
case ActionTypes.SET_AUTH_STATE: {
const { loginMethod, nostrLoginAuthMethod, keyPair } = state
@ -48,7 +48,7 @@ const reducer = (
}
case ActionTypes.RESTORE_STATE:
return action.payload.auth
return action.payload.auth || initialState
default:
return state

View File

@ -2,15 +2,7 @@ import * as ActionTypes from '../actionTypes'
import { MetadataDispatchTypes } from './types'
import { Event } from 'nostr-tools'
const initialState: Event = {
content: '',
created_at: 0,
id: '',
kind: 0,
pubkey: '',
sig: '',
tags: []
}
const initialState: Event | null = null
const reducer = (
state = initialState,
@ -23,7 +15,7 @@ const reducer = (
}
case ActionTypes.RESTORE_STATE:
return action.payload.metadata || null
return action.payload.metadata || initialState
default:
return state

View File

@ -10,7 +10,7 @@ const initialState: RelaysState = {
const reducer = (
state = initialState,
action: RelaysDispatchTypes
): RelaysState | null => {
): RelaysState => {
switch (action.type) {
case ActionTypes.SET_RELAY_MAP:
return { ...state, map: action.payload, mapUpdated: Date.now() }
@ -25,7 +25,7 @@ const reducer = (
}
case ActionTypes.RESTORE_STATE:
return action.payload.relays
return action.payload.relays || initialState
default:
return state

View File

@ -12,7 +12,7 @@ const reducer = (
return action.payload
case ActionTypes.RESTORE_STATE:
return action.payload.userRobotImage
return action.payload.userRobotImage || initialState
default:
return state