mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-08 20:25:19 +02:00
feat(chat): implement chat tab synchronization and enhance thread activation with new hooks for improved navigation and metadata management
This commit is contained in:
parent
168c0d2f89
commit
08801fe3e8
13 changed files with 276 additions and 85 deletions
|
|
@ -4,12 +4,14 @@ import { reportPanelAtom } from "./report-panel.atom";
|
|||
|
||||
interface CurrentThreadState {
|
||||
id: number | null;
|
||||
searchSpaceId: number | null;
|
||||
visibility: ChatVisibility | null;
|
||||
hasComments: boolean;
|
||||
}
|
||||
|
||||
interface CurrentThreadMetadataPatch {
|
||||
id: number | null;
|
||||
searchSpaceId?: number | null;
|
||||
visibility?: ChatVisibility | null;
|
||||
hasComments?: boolean;
|
||||
}
|
||||
|
|
@ -22,6 +24,7 @@ interface CurrentThreadMetadataUpdate {
|
|||
|
||||
const initialState: CurrentThreadState = {
|
||||
id: null,
|
||||
searchSpaceId: null,
|
||||
visibility: null,
|
||||
hasComments: false,
|
||||
};
|
||||
|
|
@ -32,21 +35,33 @@ export const commentsEnabledAtom = atom(
|
|||
(get) => get(currentThreadAtom).visibility === "SEARCH_SPACE"
|
||||
);
|
||||
|
||||
export const setThreadVisibilityAtom = atom(null, (get, set, newVisibility: ChatVisibility) => {
|
||||
set(currentThreadAtom, { ...get(currentThreadAtom), visibility: newVisibility });
|
||||
});
|
||||
|
||||
export const setCurrentThreadMetadataAtom = atom(
|
||||
null,
|
||||
(get, set, metadata: CurrentThreadMetadataPatch) => {
|
||||
const current = get(currentThreadAtom);
|
||||
const isSameThread = current.id === metadata.id;
|
||||
|
||||
set(currentThreadAtom, {
|
||||
...current,
|
||||
id: metadata.id,
|
||||
visibility: "visibility" in metadata ? (metadata.visibility ?? null) : current.visibility,
|
||||
searchSpaceId:
|
||||
"searchSpaceId" in metadata
|
||||
? (metadata.searchSpaceId ?? null)
|
||||
: isSameThread
|
||||
? current.searchSpaceId
|
||||
: null,
|
||||
visibility:
|
||||
"visibility" in metadata
|
||||
? (metadata.visibility ?? null)
|
||||
: isSameThread
|
||||
? current.visibility
|
||||
: null,
|
||||
hasComments:
|
||||
"hasComments" in metadata ? (metadata.hasComments ?? false) : current.hasComments,
|
||||
"hasComments" in metadata
|
||||
? (metadata.hasComments ?? false)
|
||||
: isSameThread
|
||||
? current.hasComments
|
||||
: false,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue