A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: support customizable monograph title (#8491)
01zulfi9396a06a8923
diff --git a/apps/mobile/app/components/sheets/publish-note/index.tsx b/apps/mobile/app/components/sheets/publish-note/index.tsxindex 992bee604..829896fa8 100644--- a/apps/mobile/app/components/sheets/publish-note/index.tsx+++ b/apps/mobile/app/components/sheets/publish-note/index.tsx@@ -78,12 +78,15 @@ const PublishNoteSheet = ({const isFeatureAvailable = useIsFeatureAvailable("monographAnalytics");const [isLocked, setIsLocked] = useState(false);const [publishing, setPublishing] = useState(false);+ const customTitle = useRef<string>("");const pwdInput = useRef<TextInput>(null);+ const titleInput = useRef<TextInput>(null);const passwordValue = useRef<string>(undefined);const monographData = useAsync(async () => {return fetchMonographData(note?.id);}, []);const monograph = monographData.result?.monograph;+ customTitle.current = monograph?.title || note.title || "";const publishUrl = monograph && `${hosts.MONOGRAPH_HOST}/${monograph?.id}`;const isPublished = db.monographs.monograph(note?.id);@@ -108,7 +111,7 @@ const PublishNoteSheet = ({try {if (note?.id) {if (isLocked && !passwordValue.current) return;- await db.monographs.publish(note.id, {+ await db.monographs.publish(note.id, customTitle.current, {selfDestruct: selfDestruct,password: isLocked ? passwordValue.current : undefined});@@ -129,7 +132,6 @@ const PublishNoteSheet = ({setPublishLoading(false);};-const setPublishLoading = (value: boolean) => {setPublishing(value);};@@ -245,6 +247,13 @@ const PublishNoteSheet = ({</TouchableOpacity>) : null}+ <Input+ fwdRef={titleInput}+ onChangeText={(value) => (customTitle.current = value)}+ defaultValue={customTitle.current}+ placeholder={strings.noteTitle()}+ />+<TouchableOpacityonPress={() => {if (publishing) return;diff --git a/apps/web/src/components/publish-view/index.tsx b/apps/web/src/components/publish-view/index.tsxindex 6e878c176..bd7bc8610 100644--- a/apps/web/src/components/publish-view/index.tsx+++ b/apps/web/src/components/publish-view/index.tsx@@ -56,6 +56,7 @@ function PublishView(props: PublishViewProps) {current: number;}>();const passwordInput = useRef<HTMLInputElement>(null);+ const titleInput = useRef<HTMLInputElement>(null);const publishNote = useStore((store) => store.publish);const unpublishNote = useStore((store) => store.unpublish);const [monograph, setMonograph] = useState(props.monograph);@@ -125,6 +126,26 @@ function PublishView(props: PublishViewProps) {borderRadius: "default"}}>+ <Flex+ sx={{+ alignItems: "center",+ justifyContent: "space-between",+ px: 1,+ height: 30,++ "& label": { width: "auto", flexShrink: 0 }+ }}+ >+ <Text variant="body">{strings.title()}</Text>+ <Input+ ref={titleInput}+ type="text"+ variant="clean"+ placeholder={strings.enterTitle()}+ defaultValue={monograph ? monograph.title : note.title}+ sx={{ textAlign: "right", p: 0 }}+ />+ </Flex>{monograph?.publishedAt ? (<Flexsx={{@@ -286,8 +307,14 @@ function PublishView(props: PublishViewProps) {try {setStatus({ action: "publish" });const password = passwordInput.current?.value;+ const title = titleInput.current?.value;++ if (!title || title.trim().length === 0) {+ showToast("error", "Title cannot be empty.");+ return;+ }- await publishNote(note.id, {+ await publishNote(note.id, title, {selfDestruct,password});@@ -425,6 +452,7 @@ type ResolvedMonograph = {selfDestruct: boolean;publishedAt?: number;password?: string;+ title: string;};async function resolveMonograph(@@ -436,6 +464,7 @@ async function resolveMonograph(id: monographId,selfDestruct: !!monograph.selfDestruct,publishedAt: monograph.datePublished,+ title: monograph.title,password: monograph.password? await db.monographs.decryptPassword(monograph.password): undefineddiff --git a/apps/web/src/stores/monograph-store.ts b/apps/web/src/stores/monograph-store.tsindex c8592cc01..63d9f2722 100644--- a/apps/web/src/stores/monograph-store.ts+++ b/apps/web/src/stores/monograph-store.ts@@ -33,8 +33,8 @@ class MonographStore extends BaseStore<MonographStore> {this.set({ monographs: grouping });};- publish = async (noteId: string, opts: PublishOptions) => {- const publishId = await db.monographs.publish(noteId, opts);+ publish = async (noteId: string, title: string, opts: PublishOptions) => {+ const publishId = await db.monographs.publish(noteId, title, opts);await this.get().refresh();await noteStore.refreshContext();return publishId;diff --git a/packages/core/__e2e__/monographs.test.js b/packages/core/__e2e__/monographs.test.jsindex 0e8397507..def6ba82a 100644--- a/packages/core/__e2e__/monographs.test.js+++ b/packages/core/__e2e__/monographs.test.js@@ -51,14 +51,14 @@ test(await login(db);await db.monographs.refresh();- const monographId = await db.monographs.publish(id);+ const title = "mono";+ const monographId = await db.monographs.publish(id, title);expect(await db.monographs.all.has(id)).toBeTruthy();const monograph = await db.monographs.get(monographId);- const note = await db.notes.note(id);expect(monograph.id).toBe(monographId);- expect(monograph.title).toBe(note.title);+ expect(monograph.title).toBe(title);await logout(db);}),@@ -72,14 +72,13 @@ test(await login(db);await db.monographs.refresh();- const monographId = await db.monographs.publish(id);+ const title = "mono";+ const monographId = await db.monographs.publish(id, title);let monograph = await db.monographs.get(monographId);- const note = await db.notes.note(id);- expect(monograph.title).toBe(note.title);+ expect(monograph.title).toBe(title);- const editedTitle = "EDITED TITLE OF MY NOTE!";- await db.notes.add({ id, title: editedTitle });- await db.monographs.publish(id);+ const editedTitle = "monograph";+ await db.monographs.publish(id, editedTitle);monograph = await db.monographs.get(monographId);expect(monograph.title).toBe(editedTitle);diff --git a/packages/core/src/api/monographs.ts b/packages/core/src/api/monographs.tsindex 53e11cc10..5df586979 100644--- a/packages/core/src/api/monographs.ts+++ b/packages/core/src/api/monographs.ts@@ -41,7 +41,10 @@ export type MonographAnalytics = {totalViews: number;};-export type PublishOptions = { password?: string; selfDestruct?: boolean };+export type PublishOptions = {+ password?: string;+ selfDestruct?: boolean;+};export class Monographs {monographs: string[] = [];constructor(private readonly db: Database) {}@@ -73,7 +76,9 @@ export class Monographs {/*** Publish a note as a monograph*/- async publish(noteId: string, opts: PublishOptions = {}) {+ async publish(noteId: string, title: string, opts: PublishOptions = {}) {+ if (title === "") throw new Error("Title cannot be empty.");+if (!this.monographs.length) await this.refresh();const update = !!this.isPublished(noteId);@@ -102,7 +107,7 @@ export class Monographs {const monographPasswordsKey = await this.db.user.getMonographPasswordsKey();const monograph: MonographApiRequest = {id: noteId,- title: note.title,+ title,userId: user.id,selfDestruct: opts.selfDestruct || false,...(opts.passworddiff --git a/packages/intl/locale/en.po b/packages/intl/locale/en.poindex 874a3b267..76bd9c844 100644--- a/packages/intl/locale/en.po+++ b/packages/intl/locale/en.po@@ -2588,6 +2588,10 @@ msgstr "Enter the gift code to redeem your subscription."msgid "Enter the recovery code to continue logging in"msgstr "Enter the recovery code to continue logging in"+#: src/strings.ts:2617+msgid "Enter title"+msgstr "Enter title"+#: src/strings.ts:1492msgid "Enter verification code sent to your new email"msgstr "Enter verification code sent to your new email"diff --git a/packages/intl/locale/pseudo-LOCALE.po b/packages/intl/locale/pseudo-LOCALE.poindex 687649e1d..a3edcaa0f 100644--- a/packages/intl/locale/pseudo-LOCALE.po+++ b/packages/intl/locale/pseudo-LOCALE.po@@ -2577,6 +2577,10 @@ msgstr ""msgid "Enter the recovery code to continue logging in"msgstr ""+#: src/strings.ts:2617+msgid "Enter title"+msgstr ""+#: src/strings.ts:1492msgid "Enter verification code sent to your new email"msgstr ""diff --git a/packages/intl/src/strings.ts b/packages/intl/src/strings.tsindex 45e25df72..c143b1962 100644--- a/packages/intl/src/strings.ts+++ b/packages/intl/src/strings.ts@@ -2613,5 +2613,6 @@ Use this if changes from other devices are not appearing on this device. This wiaddToHome: () => t`Add to home`,clickToSave: () => t`Click to save`,lineHeight: () => t`Line height`,- lineHeightDesc: () => t`Adjust the line height of the editor`+ lineHeightDesc: () => t`Adjust the line height of the editor`,+ enterTitle: () => t`Enter title`};