Add log state related functions

This commit is contained in:
Serkan Reis 2023-05-03 21:16:51 +03:00
parent d3a8fa5a7a
commit 5041d34964

27
contexts/log.ts Normal file
View File

@ -0,0 +1,27 @@
import create from 'zustand'
export interface LogItem {
id: string
message: string
type?: string
timestamp?: Date
code?: number
source?: string
connectedWallet?: string
}
export const useLogStore = create(() => ({
itemList: [] as LogItem[],
}))
export const setLogItemList = (list: LogItem[]) => {
useLogStore.setState({ itemList: list })
}
export const addLogItem = (item: LogItem) => {
useLogStore.setState((prev) => ({ itemList: [...prev.itemList, item] }))
}
export const removeLogItem = (id: string) => {
useLogStore.setState((prev) => ({ itemList: prev.itemList.filter((item) => item.id !== id) }))
}