Skip to content

Commit 49b1112

Browse files
committed
core: support customizable monograph title
Signed-off-by: 01zulfi <[email protected]>
1 parent 693311a commit 49b1112

File tree

7 files changed

+63
-22
lines changed

7 files changed

+63
-22
lines changed

apps/web/src/components/publish-view/index.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function PublishView(props: PublishViewProps) {
5151
current: number;
5252
}>();
5353
const passwordInput = useRef<HTMLInputElement>(null);
54+
const titleInput = useRef<HTMLInputElement>(null);
5455
const publishNote = useStore((store) => store.publish);
5556
const unpublishNote = useStore((store) => store.unpublish);
5657

@@ -65,6 +66,10 @@ function PublishView(props: PublishViewProps) {
6566
setIsPasswordProtected(!!monograph.password);
6667
setSelfDestruct(!!monograph.selfDestruct);
6768

69+
if (titleInput.current) {
70+
titleInput.current.value = monograph.title;
71+
}
72+
6873
if (monograph.password) {
6974
const password = await db.monographs.decryptPassword(
7075
monograph.password
@@ -192,6 +197,19 @@ function PublishView(props: PublishViewProps) {
192197
{strings.monographDesc()}
193198
</Text>
194199
)}
200+
<Field
201+
inputRef={titleInput}
202+
id="monograph-title"
203+
label={strings.monographTitle()}
204+
placeholder={strings.enterMonographTitle()}
205+
defaultValue={publishId ? "" : note.title}
206+
sx={{
207+
my: 1,
208+
"& > label": {
209+
fontSize: "body"
210+
}
211+
}}
212+
/>
195213
<Toggle
196214
title={strings.monographSelfDestructHeading()}
197215
tip={strings.monographSelfDestructDesc()}
@@ -231,8 +249,9 @@ function PublishView(props: PublishViewProps) {
231249
try {
232250
setIsPublishing(true);
233251
const password = passwordInput.current?.value;
252+
const title = titleInput.current?.value ?? "";
234253

235-
const publishId = await publishNote(note.id, {
254+
const publishId = await publishNote(note.id, title, {
236255
selfDestruct,
237256
password
238257
});

apps/web/src/stores/monograph-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class MonographStore extends BaseStore<MonographStore> {
3333
this.set({ monographs: grouping });
3434
};
3535

36-
publish = async (noteId: string, opts: PublishOptions) => {
37-
const publishId = await db.monographs.publish(noteId, opts);
36+
publish = async (noteId: string, title: string, opts: PublishOptions) => {
37+
const publishId = await db.monographs.publish(noteId, title, opts);
3838
await this.get().refresh();
3939
await noteStore.refreshContext();
4040
return publishId;

packages/core/__e2e__/monographs.test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ test(
5151
await login(db);
5252
await db.monographs.refresh();
5353

54-
const monographId = await db.monographs.publish(id);
54+
const title = "mono";
55+
const monographId = await db.monographs.publish(id, title);
5556

5657
expect(await db.monographs.all.has(id)).toBeTruthy();
5758

5859
const monograph = await db.monographs.get(monographId);
59-
const note = await db.notes.note(id);
6060
expect(monograph.id).toBe(monographId);
61-
expect(monograph.title).toBe(note.title);
61+
expect(monograph.title).toBe(title);
6262

6363
await logout(db);
6464
}),
@@ -72,14 +72,13 @@ test(
7272
await login(db);
7373
await db.monographs.refresh();
7474

75-
const monographId = await db.monographs.publish(id);
75+
const title = "mono";
76+
const monographId = await db.monographs.publish(id, title);
7677
let monograph = await db.monographs.get(monographId);
77-
const note = await db.notes.note(id);
78-
expect(monograph.title).toBe(note.title);
78+
expect(monograph.title).toBe(title);
7979

80-
const editedTitle = "EDITED TITLE OF MY NOTE!";
81-
await db.notes.add({ id, title: editedTitle });
82-
await db.monographs.publish(id);
80+
const editedTitle = "monograph";
81+
await db.monographs.publish(id, editedTitle);
8382
monograph = await db.monographs.get(monographId);
8483
expect(monograph.title).toBe(editedTitle);
8584

packages/core/src/api/monographs.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ type MonographApiRequest = (UnencryptedMonograph | EncryptedMonograph) & {
3838
userId: string;
3939
};
4040

41-
export type PublishOptions = { password?: string; selfDestruct?: boolean };
41+
export type PublishOptions = {
42+
password?: string;
43+
selfDestruct?: boolean;
44+
};
4245
export class Monographs {
4346
monographs: string[] = [];
4447
constructor(private readonly db: Database) {}
@@ -70,7 +73,9 @@ export class Monographs {
7073
/**
7174
* Publish a note as a monograph
7275
*/
73-
async publish(noteId: string, opts: PublishOptions = {}) {
76+
async publish(noteId: string, title: string, opts: PublishOptions = {}) {
77+
if (title === "") throw new Error("Title cannot be empty.");
78+
7479
if (!this.monographs.length) await this.refresh();
7580

7681
const update = !!this.isPublished(noteId);
@@ -99,7 +104,7 @@ export class Monographs {
99104
const monographPasswordsKey = await this.db.user.getMonographPasswordsKey();
100105
const monograph: MonographApiRequest = {
101106
id: noteId,
102-
title: note.title,
107+
title,
103108
userId: user.id,
104109
selfDestruct: opts.selfDestruct || false,
105110
...(opts.password

packages/intl/locale/en.po

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,6 +2448,10 @@ msgstr "Enter full name"
24482448
msgid "Enter fullscreen"
24492449
msgstr "Enter fullscreen"
24502450

2451+
#: src/strings.ts:2496
2452+
msgid "Enter monograph title"
2453+
msgstr "Enter monograph title"
2454+
24512455
#: src/strings.ts:1489
24522456
msgid "Enter notebook description"
24532457
msgstr "Enter notebook description"
@@ -3717,6 +3721,10 @@ msgstr "Monday"
37173721
msgid "Monograph server"
37183722
msgstr "Monograph server"
37193723

3724+
#: src/strings.ts:2495
3725+
msgid "Monograph title"
3726+
msgstr "Monograph title"
3727+
37203728
#: src/strings.ts:869
37213729
msgid "Monograph URL copied"
37223730
msgstr "Monograph URL copied"
@@ -3956,7 +3964,7 @@ msgstr "No links found"
39563964
msgid "No note history available for this device."
39573965
msgstr "No note history available for this device."
39583966

3959-
#: src/strings.ts:2489
3967+
#: src/strings.ts:2492
39603968
msgid "No notebooks selected to move"
39613969
msgstr "No notebooks selected to move"
39623970

@@ -5309,11 +5317,11 @@ msgstr "Scan the QR code with your authenticator app"
53095317
msgid "School work"
53105318
msgstr "School work"
53115319

5312-
#: src/strings.ts:2491
5320+
#: src/strings.ts:2494
53135321
msgid "Scroll to bottom"
53145322
msgstr "Scroll to bottom"
53155323

5316-
#: src/strings.ts:2490
5324+
#: src/strings.ts:2493
53175325
msgid "Scroll to top"
53185326
msgstr "Scroll to top"
53195327

packages/intl/locale/pseudo-LOCALE.po

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,6 +2437,10 @@ msgstr ""
24372437
msgid "Enter fullscreen"
24382438
msgstr ""
24392439

2440+
#: src/strings.ts:2496
2441+
msgid "Enter monograph title"
2442+
msgstr ""
2443+
24402444
#: src/strings.ts:1489
24412445
msgid "Enter notebook description"
24422446
msgstr ""
@@ -3697,6 +3701,10 @@ msgstr ""
36973701
msgid "Monograph server"
36983702
msgstr ""
36993703

3704+
#: src/strings.ts:2495
3705+
msgid "Monograph title"
3706+
msgstr ""
3707+
37003708
#: src/strings.ts:869
37013709
msgid "Monograph URL copied"
37023710
msgstr ""
@@ -3936,7 +3944,7 @@ msgstr ""
39363944
msgid "No note history available for this device."
39373945
msgstr ""
39383946

3939-
#: src/strings.ts:2489
3947+
#: src/strings.ts:2492
39403948
msgid "No notebooks selected to move"
39413949
msgstr ""
39423950

@@ -5283,11 +5291,11 @@ msgstr ""
52835291
msgid "School work"
52845292
msgstr ""
52855293

5286-
#: src/strings.ts:2491
5294+
#: src/strings.ts:2494
52875295
msgid "Scroll to bottom"
52885296
msgstr ""
52895297

5290-
#: src/strings.ts:2490
5298+
#: src/strings.ts:2493
52915299
msgid "Scroll to top"
52925300
msgstr ""
52935301

packages/intl/src/strings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2491,5 +2491,7 @@ Use this if changes from other devices are not appearing on this device. This wi
24912491
paragraphs: () => t`Paragraphs`,
24922492
noNotebooksSelectedToMove: () => t`No notebooks selected to move`,
24932493
scrollToTop: () => t`Scroll to top`,
2494-
scrollToBottom: () => t`Scroll to bottom`
2494+
scrollToBottom: () => t`Scroll to bottom`,
2495+
monographTitle: () => t`Monograph title`,
2496+
enterMonographTitle: () => t`Enter monograph title`
24952497
};

0 commit comments

Comments
 (0)