web: update tab/window title for locked & conflicted notes

This commit is contained in:
Abdullah Atta
2023-03-20 17:23:11 +05:00
committed by Abdullah Atta
parent e6f1320b1d
commit c85d623e1c
2 changed files with 25 additions and 17 deletions

View File

@@ -35,7 +35,7 @@ function DiffViewer(props) {
const setIsEditorOpen = useAppStore((store) => store.setIsEditorOpen);
const sync = useAppStore((store) => store.sync);
const clearSession = useEditorStore((store) => store.clearSession);
const openSession = useEditorStore((store) => store.openSession);
const [conflictedNote, setConflictedNote] = useState();
const [remoteContent, setRemoteContent] = useState();
const [localContent, setLocalContent] = useState();
@@ -98,7 +98,10 @@ function DiffViewer(props) {
hashNavigate(`/notes/create`, { replace: true });
return;
}
notesStore.setSelectedNote(noteId);
await openSession(noteId);
setIsEditorOpen(true);
note = note.data;
const content = await db.content.raw(note.contentId);
@@ -114,12 +117,7 @@ function DiffViewer(props) {
setHtmlDiff({ before: content.data, after: content.conflicted.data });
})();
}, [noteId, resolveConflict]);
useEffect(() => {
clearSession(false);
setIsEditorOpen(true);
}, [setIsEditorOpen, clearSession]);
}, [noteId, openSession, setIsEditorOpen, resolveConflict]);
if (!conflictedNote || !localContent || !remoteContent) return null;
return (

View File

@@ -23,20 +23,25 @@ import * as Icon from "../icons";
import { db } from "../../common/db";
import { useStore as useEditorStore } from "../../stores/editor-store";
import { useStore as useAppStore } from "../../stores/app-store";
import { useStore as useNoteStore } from "../../stores/note-store";
import Field from "../field";
import { showToast } from "../../utils/toast";
function Unlock(props) {
const { noteId } = props;
const note = useMemo(() => db.notes.note(noteId)?.data, [noteId]);
const passwordRef = useRef();
const [isWrong, setIsWrong] = useState(false);
const [isUnlocking, setIsUnlocking] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const passwordRef = useRef();
const note = useMemo(
() => !isLoading && db.notes.note(noteId)?.data,
[noteId, isLoading]
);
const openLockedSession = useEditorStore((store) => store.openLockedSession);
const clearSession = useEditorStore((store) => store.clearSession);
const openSession = useEditorStore((store) => store.openSession);
const setIsEditorOpen = useAppStore((store) => store.setIsEditorOpen);
const setSelectedNote = useNoteStore((store) => store.setSelectedNote);
const submit = useCallback(async () => {
setIsUnlocking(true);
@@ -58,10 +63,15 @@ function Unlock(props) {
}, [setIsWrong, noteId, openLockedSession]);
useEffect(() => {
clearSession(false);
setIsEditorOpen(true);
setTimeout(() => setSelectedNote(noteId));
}, [clearSession, setIsEditorOpen, setSelectedNote, noteId]);
(async () => {
setIsLoading(true);
await openSession(noteId);
setIsEditorOpen(true);
setIsLoading(false);
})();
}, [openSession, setIsEditorOpen, noteId]);
return (
<Flex