mirror of
https://github.com/docmost/docmost.git
synced 2025-11-19 07:41:09 +10:00
websocket updates
* sync page title on icon via websocket * sync on page tree too
This commit is contained in:
@ -15,6 +15,8 @@ import { useDebouncedValue } from "@mantine/hooks";
|
||||
import { useAtom } from "jotai";
|
||||
import { treeDataAtom } from "@/features/page/tree/atoms/tree-data-atom";
|
||||
import { updateTreeNodeName } from "@/features/page/tree/utils";
|
||||
import { useQueryEmit } from "@/features/websocket/use-query-emit.ts";
|
||||
import { History } from "@tiptap/extension-history";
|
||||
|
||||
export interface TitleEditorProps {
|
||||
pageId: string;
|
||||
@ -28,6 +30,7 @@ export function TitleEditor({ pageId, title }: TitleEditorProps) {
|
||||
const pageEditor = useAtomValue(pageEditorAtom);
|
||||
const [, setTitleEditor] = useAtom(titleEditorAtom);
|
||||
const [treeData, setTreeData] = useAtom(treeDataAtom);
|
||||
const emit = useQueryEmit();
|
||||
|
||||
const titleEditor = useEditor({
|
||||
extensions: [
|
||||
@ -41,6 +44,9 @@ export function TitleEditor({ pageId, title }: TitleEditorProps) {
|
||||
Placeholder.configure({
|
||||
placeholder: "Untitled",
|
||||
}),
|
||||
History.configure({
|
||||
depth: 20,
|
||||
}),
|
||||
],
|
||||
onCreate({ editor }) {
|
||||
if (editor) {
|
||||
@ -59,6 +65,15 @@ export function TitleEditor({ pageId, title }: TitleEditorProps) {
|
||||
if (debouncedTitle !== "") {
|
||||
updatePageMutation.mutate({ pageId, title: debouncedTitle });
|
||||
|
||||
setTimeout(() => {
|
||||
emit({
|
||||
operation: "updateOne",
|
||||
entity: ["pages"],
|
||||
id: pageId,
|
||||
payload: { title: debouncedTitle },
|
||||
});
|
||||
}, 50);
|
||||
|
||||
const newTreeData = updateTreeNodeName(treeData, pageId, debouncedTitle);
|
||||
setTreeData(newTreeData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user