Expose note title in the app

This commit is contained in:
Adrian Gruntkowski 2025-02-09 00:03:01 +01:00
parent 6235cd677d
commit 77a9f148cf
5 changed files with 45 additions and 1 deletions

View file

@ -67,6 +67,7 @@
<note-form mode="add" id="new-note"> <note-form mode="add" id="new-note">
<div class="note"> <div class="note">
<p class="title"></p>
<p class="content"></p> <p class="content"></p>
<div class="toolbar"> <div class="toolbar">
<button class="add"></button> <button class="add"></button>
@ -96,6 +97,7 @@
<dialog id="edit-note-dialog"> <dialog id="edit-note-dialog">
<note-form mode="edit" id="edit-note"> <note-form mode="edit" id="edit-note">
<div class="note"> <div class="note">
<p class="title"></p>
<p class="content"></p> <p class="content"></p>
<div class="toolbar"> <div class="toolbar">
<button class="save">💾</button> <button class="save">💾</button>

View file

@ -552,6 +552,7 @@ class NoteForm extends HTMLElement {
this.note = { this.note = {
type: "note", type: "note",
title: "",
content: "", content: "",
reminder: null, reminder: null,
}; };
@ -559,6 +560,7 @@ class NoteForm extends HTMLElement {
connectedCallback() { connectedCallback() {
this.mode = this.attributes.mode.value; this.mode = this.attributes.mode.value;
this.titleField = this.querySelector(".title");
this.content = this.querySelector(".content"); this.content = this.querySelector(".content");
this.tasklistModeButton = this.querySelector(".tasklist-mode"); this.tasklistModeButton = this.querySelector(".tasklist-mode");
this.noteModeButton = this.querySelector(".note-mode"); this.noteModeButton = this.querySelector(".note-mode");
@ -656,10 +658,12 @@ class NoteForm extends HTMLElement {
} }
this.addEventListener("contentChange", () => { this.addEventListener("contentChange", () => {
this.#setNote("title", this.titleField.firstChild.value);
this.#setNote("content", this.content.firstChild.value); this.#setNote("content", this.content.firstChild.value);
}); });
this.#updateUI(); this.#updateUI();
this.#setTitle();
this.#setContent(); this.#setContent();
} }
@ -667,12 +671,14 @@ class NoteForm extends HTMLElement {
this.note = note; this.note = note;
this.reminderPicker.value = note.reminder; this.reminderPicker.value = note.reminder;
this.#updateUI(); this.#updateUI();
this.#setTitle();
this.#setContent(); this.#setContent();
} }
#reset() { #reset() {
this.note = { this.note = {
type: "note", type: "note",
title: "",
content: "", content: "",
reminder: null, reminder: null,
}; };
@ -680,6 +686,7 @@ class NoteForm extends HTMLElement {
this.reminderPicker.value = null; this.reminderPicker.value = null;
this.#updateUI(); this.#updateUI();
this.#setTitle();
this.#setContent(); this.#setContent();
} }
@ -723,6 +730,12 @@ class NoteForm extends HTMLElement {
} }
} }
#setTitle() {
const title = html`<editable-area></editable-area>`;
this.titleField.replaceChildren(title);
title.value = this.note.title;
}
#setContent() { #setContent() {
const contentFun = const contentFun =
contentMap[`${this.note.type}_${typeof this.note.content}`]; contentMap[`${this.note.type}_${typeof this.note.content}`];

View file

@ -209,10 +209,21 @@ function renderNote(note) {
container.classList.add("note"); container.classList.add("note");
container.classList.add("readonly"); container.classList.add("readonly");
if (note.title && note.title !== "") {
const title = document.createElement("p");
title.classList.add("title");
title.replaceChildren(...renderText(note.title));
container.appendChild(title);
}
if (note.type === "note") { if (note.type === "note") {
container.replaceChildren(...renderText(note.content)); const body = document.createElement("p");
body.classList.add("body");
body.replaceChildren(...renderText(note.content));
container.appendChild(body);
} else if (note.type === "tasklist") { } else if (note.type === "tasklist") {
const list = document.createElement("ul"); const list = document.createElement("ul");
list.classList.add("body");
note.content.forEach((task) => { note.content.forEach((task) => {
const item = document.createElement("li"); const item = document.createElement("li");

View file

@ -5,6 +5,7 @@ function notesEqual(n1, n2) {
return ( return (
n1.id === n2.id && n1.id === n2.id &&
n1.type === n2.type && n1.type === n2.type &&
n1.title === n2.title &&
n1.content === n2.content && n1.content === n2.content &&
n1.deleted === n2.deleted && n1.deleted === n2.deleted &&
n1.reminder?.enabled === n2.reminder?.enabled && n1.reminder?.enabled === n2.reminder?.enabled &&
@ -119,6 +120,7 @@ class WebNoteStore {
const draftTemplate = { const draftTemplate = {
id: "draft", id: "draft",
type: "note", type: "note",
title: "",
content: "", content: "",
reminder: null, reminder: null,
}; };
@ -209,6 +211,7 @@ export class SyncedNoteStore extends EventTarget {
const entry = { const entry = {
id: "id_" + now, id: "id_" + now,
type: note.type, type: note.type,
title: note.title,
content: note.content, content: note.content,
reminder: note.reminder reminder: note.reminder
? { ? {

View file

@ -243,6 +243,16 @@ task-list ul {
/* Note form */ /* Note form */
note-form:focus-within .title {
display: block;
}
note-form .title {
display: none;
font-size: 1.2em;
font-weight: bold;
}
note-form .content { note-form .content {
min-height: 2.5em; min-height: 2.5em;
} }
@ -302,6 +312,11 @@ button {
padding: 4px 8px; padding: 4px 8px;
} }
.note.readonly .title {
font-size: 1.2em;
font-weight: bold;
}
.note.readonly ul { .note.readonly ul {
display: flex; display: flex;
flex-direction: column; flex-direction: column;