}}</span>
<input
v-show="editMode"
- v-model="newTitle"
+ v-model.trim="newTitle"
class="flex-1 bg-theme-background outline-none"
placeholder="Title"
/>
} else {
newTitle.value = "";
note.value = new Note();
- editMode.value = true;
+ editHandler();
loadingIndicator.value.setLoaded();
}
}
+// Helpers
function entityTooLargeToast(entityName) {
toast.add(
getToastOptions(
toast.add(
getToastOptions(
`Invalid ${entityName}`,
- "Due to filename restrictions, the following characters are not allowed: <>:\"/\\|?*",
+ 'Due to filename restrictions, the following characters are not allowed: <>:"/\\|?*',
true,
),
);
}
+function setBeforeUnloadConfirmation(enable = true) {
+ if (enable) {
+ window.onbeforeunload = () => {
+ return true;
+ };
+ } else {
+ window.onbeforeunload = null;
+ }
+}
+
+// Button Handlers
function editHandler() {
+ setBeforeUnloadConfirmation(true);
newTitle.value = note.value.title;
editMode.value = true;
}
isDeleteModalVisible.value = true;
}
-function deleteConfirmedHandler() {
- deleteNote(note.value.title)
- .then(() => {
- toast.add(getToastOptions("Success", "Note deleted."));
- router.push({ name: "home" });
- })
- .catch((error) => {
- apiErrorHandler(error, toast);
- });
-}
-
function cancelHandler() {
+ setBeforeUnloadConfirmation(false);
editMode.value = false;
if (!props.title) {
router.push({ name: "home" });
}
function saveHandler() {
+ // Empty Title Validation
+ if (!newTitle.value) {
+ toast.add(
+ getToastOptions("Invalid", "Cannot save note without a title", true),
+ );
+ return;
+ }
+
+ // Invalid Character Validation
if (reservedFilenameCharacters.test(newTitle.value)) {
badFilenameToast("Title");
return;
}
+
let newContent = toastEditor.value.getMarkdown();
if (isNewNote.value) {
saveNew(newTitle.value, newContent);
}
}
+// Additional Logic
+function deleteConfirmedHandler() {
+ deleteNote(note.value.title)
+ .then(() => {
+ toast.add(getToastOptions("Success", "Note deleted."));
+ router.push({ name: "home" });
+ })
+ .catch((error) => {
+ apiErrorHandler(error, toast);
+ });
+}
+
function saveNew(newTitle, newContent) {
createNote(newTitle, newContent)
.then((data) => {
}
function noteSaveSuccess() {
+ setBeforeUnloadConfirmation(false);
editMode.value = false;
toast.add(getToastOptions("Success", "Note saved successfully."));
}
-#!/bin/sh\r
-\r
-[ "$EXEC_TOOL" ] || EXEC_TOOL=gosu\r
-[ "$FLATNOTES_PORT" ] || FLATNOTES_PORT=8080\r
-\r
-set -e\r
-\r
-echo "\\r
-======================================\r
-======== Welcome to flatnotes ========\r
-======================================\r
-\r
-If you enjoy using flatnotes, please\r
-consider sponsoring the project at:\r
-\r
-https://sponsor.flatnotes.io\r
-\r
-It would really make my day 🙏.\r
-\r
-──────────────────────────────────────\r
-"\r
-\r
-flatnotes_command="python -m \\r
- uvicorn \\r
- main:app \\r
- --app-dir server \\r
- --host 0.0.0.0 \\r
- --port ${FLATNOTES_PORT} \\r
- --proxy-headers \\r
- --forwarded-allow-ips '*'"\r
-\r
-if [ `id -u` -eq 0 ] && [ `id -g` -eq 0 ]; then\r
- echo Setting file permissions...\r
- chown -R ${PUID}:${PGID} ${FLATNOTES_PATH}\r
-\r
- echo Starting flatnotes as user ${PUID}...\r
- exec ${EXEC_TOOL} ${PUID}:${PGID} ${flatnotes_command}\r
-\r
-else\r
- echo "A user was set by docker, skipping file permission changes."\r
- echo Starting flatnotes as user $(id -u)...\r
- exec ${flatnotes_command}\r
-fi\r
+#!/bin/sh
+
+[ "$EXEC_TOOL" ] || EXEC_TOOL=gosu
+[ "$FLATNOTES_PORT" ] || FLATNOTES_PORT=8080
+
+set -e
+
+echo "\
+======================================
+======== Welcome to flatnotes ========
+======================================
+
+If you enjoy using flatnotes, please
+consider sponsoring the project at:
+
+https://sponsor.flatnotes.io
+
+It would really make my day 🙏.
+
+──────────────────────────────────────
+"
+
+flatnotes_command="python -m \
+ uvicorn \
+ main:app \
+ --app-dir server \
+ --host 0.0.0.0 \
+ --port ${FLATNOTES_PORT} \
+ --proxy-headers \
+ --forwarded-allow-ips '*'"
+
+if [ `id -u` -eq 0 ] && [ `id -g` -eq 0 ]; then
+ echo Setting file permissions...
+ chown -R ${PUID}:${PGID} ${FLATNOTES_PATH}
+
+ echo Starting flatnotes as user ${PUID}...
+ exec ${EXEC_TOOL} ${PUID}:${PGID} ${flatnotes_command}
+
+else
+ echo "A user was set by docker, skipping file permission changes."
+ echo Starting flatnotes as user $(id -u)...
+ exec ${flatnotes_command}
+fi
-#!/bin/sh\r
-\r
-curl -f http://localhost:${FLATNOTES_PORT}/health || exit 1\r
+#!/bin/sh
+
+curl -f http://localhost:${FLATNOTES_PORT}/health || exit 1