Compare commits

...

1 Commits

Author SHA1 Message Date
alihamuh
b1c60c3a04 core: added note title to noteHistory for saving sessions 2024-03-07 09:35:39 +05:00
8 changed files with 31 additions and 9 deletions

View File

@@ -59,7 +59,7 @@ import { getFormattedDate } from "@notesnook/common";
const PDFPreview = React.lazy(() => import("../pdf-preview")); const PDFPreview = React.lazy(() => import("../pdf-preview"));
type PreviewSession = { type PreviewSession = {
content: { data: string; type: string }; content: { data: string; type: string; title: string };
dateCreated: number; dateCreated: number;
dateEdited: number; dateEdited: number;
}; };
@@ -108,6 +108,7 @@ export default function EditorManager({
const arePropertiesVisible = useStore((store) => store.arePropertiesVisible); const arePropertiesVisible = useStore((store) => store.arePropertiesVisible);
const toggleProperties = useStore((store) => store.toggleProperties); const toggleProperties = useStore((store) => store.toggleProperties);
const isReadonly = useStore((store) => store.session.readonly); const isReadonly = useStore((store) => store.session.readonly);
const setPreviewTitle = useStore((store) => store.setPreviewTitle);
const isFocusMode = useAppStore((store) => store.isFocusMode); const isFocusMode = useAppStore((store) => store.isFocusMode);
const isPreviewSession = !!previewSession.current; const isPreviewSession = !!previewSession.current;
@@ -157,6 +158,7 @@ export default function EditorManager({
const openSession = useCallback(async (noteId: string | number) => { const openSession = useCallback(async (noteId: string | number) => {
await editorstore.get().openSession(noteId); await editorstore.get().openSession(noteId);
previewSession.current = undefined; previewSession.current = undefined;
setPreviewTitle(undefined);
lastSavedTime.current = Date.now(); lastSavedTime.current = Date.now();
setTimestamp(Date.now()); setTimestamp(Date.now());
@@ -228,6 +230,7 @@ export default function EditorManager({
onOpenPreviewSession={async (session: PreviewSession) => { onOpenPreviewSession={async (session: PreviewSession) => {
previewSession.current = session; previewSession.current = session;
setTimestamp(Date.now()); setTimestamp(Date.now());
setPreviewTitle(previewSession.current.content.title);
}} }}
/> />
)} )}

View File

@@ -37,6 +37,7 @@ function TitleBox(props: TitleBoxProps) {
const { readonly } = props; const { readonly } = props;
const inputRef = useRef<HTMLInputElement>(null); const inputRef = useRef<HTMLInputElement>(null);
const id = useStore((store) => store.session.id); const id = useStore((store) => store.session.id);
const previewTitle = useStore((store) => store.previewTitle);
const isMobile = useMobile(); const isMobile = useMobile();
const isTablet = useTablet(); const isTablet = useTablet();
const { editorConfig } = useEditorConfig(); const { editorConfig } = useEditorConfig();
@@ -63,9 +64,9 @@ function TitleBox(props: TitleBoxProps) {
useEffect(() => { useEffect(() => {
if (!inputRef.current) return; if (!inputRef.current) return;
const { title } = useStore.getState().session; const { title } = useStore.getState().session;
inputRef.current.value = title; inputRef.current.value = previewTitle || title;
updateFontSize(title.length); updateFontSize(title.length);
}, [id, updateFontSize]); }, [id, updateFontSize, previewTitle]);
useEffect(() => { useEffect(() => {
if (!inputRef.current) return; if (!inputRef.current) return;

View File

@@ -352,7 +352,7 @@ function Properties(props) {
title="Click to preview" title="Click to preview"
onClick={async () => { onClick={async () => {
toggleProperties(false); toggleProperties(false);
const content = await db.noteHistory.content(session.id); const content = await db.noteHistory.content(session.id);
if (session.locked) { if (session.locked) {
await Vault.askPassword(async (password) => { await Vault.askPassword(async (password) => {

View File

@@ -84,6 +84,7 @@ class EditorStore extends BaseStore {
session = getDefaultSession(); session = getDefaultSession();
arePropertiesVisible = false; arePropertiesVisible = false;
editorMargins = Config.get("editor:margins", true); editorMargins = Config.get("editor:margins", true);
previewTitle = undefined;
init = () => { init = () => {
EV.subscribe(EVENTS.userLoggedOut, () => { EV.subscribe(EVENTS.userLoggedOut, () => {
@@ -316,7 +317,12 @@ class EditorStore extends BaseStore {
*/ */
saveSessionContent = (noteId, sessionId, ignoreEdit, content) => { saveSessionContent = (noteId, sessionId, ignoreEdit, content) => {
const dateEdited = ignoreEdit ? this.get().session.dateEdited : undefined; const dateEdited = ignoreEdit ? this.get().session.dateEdited : undefined;
return this.saveSession(noteId, { sessionId, content, dateEdited }); return this.saveSession(noteId, {
sessionId,
content,
dateEdited,
title: content.title
});
}; };
setTag = (tag) => { setTag = (tag) => {
@@ -329,6 +335,12 @@ class EditorStore extends BaseStore {
}); });
}; };
setPreviewTitle = (previewTitle) => {
this.set((state) => {
state.previewTitle = previewTitle;
});
};
toggleProperties = (toggleState) => { toggleProperties = (toggleState) => {
this.set( this.set(
(state) => (state) =>

View File

@@ -70,7 +70,8 @@ export default class Content extends Collection {
if (content.sessionId) { if (content.sessionId) {
await this._db.noteHistory.add(contentItem.noteId, content.sessionId, { await this._db.noteHistory.add(contentItem.noteId, content.sessionId, {
data: contentItem.data, data: contentItem.data,
type: contentItem.type type: contentItem.type,
title: content.title
}); });
} }
return id; return id;

View File

@@ -32,6 +32,7 @@ import SessionContent from "./session-content";
/** /**
* @typedef Content * @typedef Content
* @property {string} title
* @property {string} data * @property {string} data
* @property {string} type * @property {string} type
*/ */
@@ -91,6 +92,7 @@ export default class NoteHistory extends Collection {
id: sessionId, id: sessionId,
sessionContentId: makeSessionContentId(sessionId), sessionContentId: makeSessionContentId(sessionId),
noteId, noteId,
title: content.title,
dateCreated: oldSession ? oldSession.dateCreated : Date.now(), dateCreated: oldSession ? oldSession.dateCreated : Date.now(),
localOnly: true localOnly: true
}; };

View File

@@ -88,6 +88,7 @@ export default class Notes extends Collection {
note.contentId = await this._db.content.add({ note.contentId = await this._db.content.add({
noteId: id, noteId: id,
title: note.title,
sessionId: note.sessionId, sessionId: note.sessionId,
id: note.contentId, id: note.contentId,
type, type,

View File

@@ -44,14 +44,15 @@ export default class SessionContent extends Collection {
contentType: content.type, contentType: content.type,
compressed: !locked, compressed: !locked,
localOnly: true, localOnly: true,
locked locked,
title: content.title
}); });
} }
/** /**
* *
* @param {string} sessionId * @param {string} sessionId
* @returns {Promise<{content:string;data:string}>} * @returns {Promise<{content:string;data:string;title:string}>}
*/ */
async get(sessionContentId) { async get(sessionContentId) {
if (!sessionContentId) return; if (!sessionContentId) return;
@@ -69,7 +70,8 @@ export default class SessionContent extends Collection {
data: session.compressed data: session.compressed
? await this._db.compressor.decompress(session.data) ? await this._db.compressor.decompress(session.data)
: session.data, : session.data,
type: session.contentType type: session.contentType,
title: session.title
}; };
} }