mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-06 20:15:17 +02:00
feat(chat): Introduce centralized thread metadata management and update chat visibility handling with new hooks for thread mutations
This commit is contained in:
parent
0cfe5e52bd
commit
8b704b2fef
10 changed files with 832 additions and 105 deletions
|
|
@ -8,6 +8,18 @@ interface CurrentThreadState {
|
|||
hasComments: boolean;
|
||||
}
|
||||
|
||||
interface CurrentThreadMetadataPatch {
|
||||
id: number | null;
|
||||
visibility?: ChatVisibility | null;
|
||||
hasComments?: boolean;
|
||||
}
|
||||
|
||||
interface CurrentThreadMetadataUpdate {
|
||||
id: number;
|
||||
visibility?: ChatVisibility | null;
|
||||
hasComments?: boolean;
|
||||
}
|
||||
|
||||
const initialState: CurrentThreadState = {
|
||||
id: null,
|
||||
visibility: null,
|
||||
|
|
@ -24,6 +36,37 @@ export const setThreadVisibilityAtom = atom(null, (get, set, newVisibility: Chat
|
|||
set(currentThreadAtom, { ...get(currentThreadAtom), visibility: newVisibility });
|
||||
});
|
||||
|
||||
export const setCurrentThreadMetadataAtom = atom(
|
||||
null,
|
||||
(get, set, metadata: CurrentThreadMetadataPatch) => {
|
||||
const current = get(currentThreadAtom);
|
||||
|
||||
set(currentThreadAtom, {
|
||||
...current,
|
||||
id: metadata.id,
|
||||
visibility: "visibility" in metadata ? (metadata.visibility ?? null) : current.visibility,
|
||||
hasComments:
|
||||
"hasComments" in metadata ? (metadata.hasComments ?? false) : current.hasComments,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export const patchCurrentThreadMetadataAtom = atom(
|
||||
null,
|
||||
(get, set, patch: CurrentThreadMetadataUpdate) => {
|
||||
const current = get(currentThreadAtom);
|
||||
if (current.id !== patch.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
set(currentThreadAtom, {
|
||||
...current,
|
||||
visibility: "visibility" in patch ? (patch.visibility ?? null) : current.visibility,
|
||||
hasComments: "hasComments" in patch ? (patch.hasComments ?? false) : current.hasComments,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export const resetCurrentThreadAtom = atom(null, (_, set) => {
|
||||
set(currentThreadAtom, initialState);
|
||||
set(reportPanelAtom, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue