Add log state related functions
This commit is contained in:
parent
d3a8fa5a7a
commit
5041d34964
27
contexts/log.ts
Normal file
27
contexts/log.ts
Normal 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) }))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user