fix: avoid persisting threads and messages on local storage (#5249)
This commit is contained in:
parent
3accef8c92
commit
079f206044
@ -1,7 +1,5 @@
|
|||||||
import { create } from 'zustand'
|
import { create } from 'zustand'
|
||||||
import { ThreadMessage } from '@janhq/core'
|
import { ThreadMessage } from '@janhq/core'
|
||||||
import { createJSONStorage, persist } from 'zustand/middleware'
|
|
||||||
import { localStorageKey } from '@/constants/localStorage'
|
|
||||||
import {
|
import {
|
||||||
createMessage,
|
createMessage,
|
||||||
deleteMessage as deleteMessageExt,
|
deleteMessage as deleteMessageExt,
|
||||||
@ -16,9 +14,7 @@ type MessageState = {
|
|||||||
deleteMessage: (threadId: string, messageId: string) => void
|
deleteMessage: (threadId: string, messageId: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useMessages = create<MessageState>()(
|
export const useMessages = create<MessageState>()((set, get) => ({
|
||||||
persist(
|
|
||||||
(set, get) => ({
|
|
||||||
messages: {},
|
messages: {},
|
||||||
getMessages: (threadId) => {
|
getMessages: (threadId) => {
|
||||||
return get().messages[threadId] || []
|
return get().messages[threadId] || []
|
||||||
@ -65,10 +61,4 @@ export const useMessages = create<MessageState>()(
|
|||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
}),
|
}))
|
||||||
{
|
|
||||||
name: localStorageKey.messages,
|
|
||||||
storage: createJSONStorage(() => localStorage),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
import { create } from 'zustand'
|
import { create } from 'zustand'
|
||||||
import { persist, createJSONStorage } from 'zustand/middleware'
|
|
||||||
import { localStorageKey } from '@/constants/localStorage'
|
|
||||||
import { ulid } from 'ulidx'
|
import { ulid } from 'ulidx'
|
||||||
import { createThread, deleteThread, updateThread } from '@/services/threads'
|
import { createThread, deleteThread, updateThread } from '@/services/threads'
|
||||||
import { Fzf } from 'fzf'
|
import { Fzf } from 'fzf'
|
||||||
@ -30,9 +28,7 @@ type ThreadState = {
|
|||||||
searchIndex: Fzf<Thread[]> | null
|
searchIndex: Fzf<Thread[]> | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useThreads = create<ThreadState>()(
|
export const useThreads = create<ThreadState>()((set, get) => ({
|
||||||
persist(
|
|
||||||
(set, get) => ({
|
|
||||||
threads: {},
|
threads: {},
|
||||||
searchIndex: null,
|
searchIndex: null,
|
||||||
setThreads: (threads) => {
|
setThreads: (threads) => {
|
||||||
@ -150,9 +146,7 @@ export const useThreads = create<ThreadState>()(
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
getFavoriteThreads: () => {
|
getFavoriteThreads: () => {
|
||||||
return Object.values(get().threads).filter(
|
return Object.values(get().threads).filter((thread) => thread.isFavorite)
|
||||||
(thread) => thread.isFavorite
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
getThreadById: (threadId: string) => {
|
getThreadById: (threadId: string) => {
|
||||||
return get().threads[threadId]
|
return get().threads[threadId]
|
||||||
@ -275,7 +269,7 @@ export const useThreads = create<ThreadState>()(
|
|||||||
|
|
||||||
// Update all other threads to increment their order by 1
|
// Update all other threads to increment their order by 1
|
||||||
const updatedThreads = { ...state.threads }
|
const updatedThreads = { ...state.threads }
|
||||||
Object.keys(updatedThreads).forEach(id => {
|
Object.keys(updatedThreads).forEach((id) => {
|
||||||
if (id !== threadId) {
|
if (id !== threadId) {
|
||||||
const otherThread = updatedThreads[id]
|
const otherThread = updatedThreads[id]
|
||||||
updatedThreads[id] = {
|
updatedThreads[id] = {
|
||||||
@ -301,10 +295,4 @@ export const useThreads = create<ThreadState>()(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}),
|
}))
|
||||||
{
|
|
||||||
name: localStorageKey.threads,
|
|
||||||
storage: createJSONStorage(() => localStorage),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user