diff --git a/resources/js/app.js b/resources/js/app.js
index f1f0cd6..d82701e 100644
--- a/resources/js/app.js
+++ b/resources/js/app.js
@@ -1,10 +1,8 @@
// Storage paths
- const DATA_FILE = 'jottings.json';
- const METADATA_FILE = 'jottings.meta.json';
+ const DATA_FILE = 'jottings.json';
const PERSONAL_DIC_FILE = 'personal.dic';
// Global state
- let currentDocId = null;
let currentDocName = null;
let autoSaveTimer = null;
@@ -608,32 +606,13 @@ async function writeNotes(notes) {
await Neutralino.filesystem.writeFile(path, JSON.stringify(notes, null, 2));
}
- async function readMeta() {
- try {
- const path = await getDataPath(METADATA_FILE);
- const content = await Neutralino.filesystem.readFile(path);
- return JSON.parse(content);
- } catch (e) {
- if (e.code === 'NE_FS_NOPATHE' || e.code === 'NE_FS_FILRDER') {
- return { nextId: 1 };
- }
- throw e;
- }
- }
-
- async function writeMeta(meta) {
- const path = await getDataPath(METADATA_FILE);
- await Neutralino.filesystem.writeFile(path, JSON.stringify(meta, null, 2));
- }
-
- async function getNextId() {
- const meta = await readMeta();
- return meta.nextId;
- }
-
- async function incrementNextId(usedId) {
- const meta = { nextId: usedId + 1 };
- await writeMeta(meta);
+ function generateJotName() {
+ const now = new Date();
+ const day = String(now.getDate()).padStart(2, '0');
+ const month = now.toLocaleString('en-GB', { month: 'short' });
+ const year = String(now.getFullYear()).slice(-2);
+ const time = now.toLocaleTimeString('en-GB', { hour12: false });
+ return `Jot ${day} ${month} ${year} ${time}`;
}
// DOCUMENT LIST
@@ -653,7 +632,7 @@ async function loadDocuments() {
notes.forEach(doc => {
const div = document.createElement("div");
- div.className = "doc-single-line" + (doc.id === currentDocId ? " active-doc" : "");
+ div.className = "doc-single-line" + (doc.name === currentDocName ? " active-doc" : "");
const line1 = document.createElement("div");
line1.className = "doc-line1";
@@ -686,13 +665,12 @@ async function loadDocuments() {
loadBtn.onclick = async function() {
try {
const notes = await readNotes();
- const note = notes.find(n => n.id === doc.id);
+ const note = notes.find(n => n.name === doc.name);
if (note) {
//Clear any stale auto-save - they were firing against wrong doc
clearTimeout(autoSaveTimer);
setEditorText(note.content);
updateCounts(note.content);
- currentDocId = doc.id;
currentDocName = doc.name;
loadDocuments();
updateStatus();
@@ -702,8 +680,8 @@ async function loadDocuments() {
}
};
- deleteBtn.onclick = function() { deleteDocument(doc.id); };
- renameBtn.onclick = function() { renameDocument(doc.id, doc.name); };
+ deleteBtn.onclick = function() { deleteDocument(doc.name); };
+ renameBtn.onclick = function() { renameDocument(doc.name); };
line3.appendChild(loadBtn);
line3.appendChild(deleteBtn);
@@ -721,21 +699,18 @@ async function saveDocument(text) {
try {
let notes = await readNotes();
- if (currentDocId !== null) {
- const index = notes.findIndex(n => n.id === currentDocId);
+ if (currentDocName !== null) {
+ const index = notes.findIndex(n => n.name === currentDocName);
if (index !== -1) {
notes[index].content = text;
notes[index].updated = new Date().toISOString();
await writeNotes(notes);
}
} else {
- const newId = await getNextId();
- await incrementNextId(newId);
-
- const now = new Date().toISOString();
+ const now = new Date().toISOString();
+ const name = generateJotName();
const newNote = {
- id: newId,
- name: `Jot ${newId}`,
+ name,
content: text,
created: now,
updated: now
@@ -743,8 +718,7 @@ async function saveDocument(text) {
notes.push(newNote);
await writeNotes(notes);
- currentDocId = newId;
- currentDocName = newNote.name;
+ currentDocName = name;
}
await loadDocuments();
@@ -754,18 +728,17 @@ async function saveDocument(text) {
}
}
- async function deleteDocument(id) {
+ async function deleteDocument(name) {
if (!confirm("Delete this document?")) return;
try {
let notes = await readNotes();
- notes = notes.filter(n => n.id !== id);
+ notes = notes.filter(n => n.name !== name);
await writeNotes(notes);
- if (currentDocId === id) {
+ if (currentDocName === name) {
//Clear any stale auto-save - they were firing against wrong doc
clearTimeout(autoSaveTimer);
- currentDocId = null;
currentDocName = null;
setEditorText('');
updateCounts('');
@@ -778,21 +751,21 @@ async function deleteDocument(id) {
}
}
- async function renameDocument(id, currentName) {
- const newName = prompt("Enter a new name for this jot:", currentName);
+ async function renameDocument(name) {
+ const newName = prompt("Enter a new name for this jot:", name);
if (newName === null) return;
const trimmed = newName.trim();
if (!trimmed) { alert("Name cannot be empty"); return; }
try {
let notes = await readNotes();
- const note = notes.find(n => n.id === id);
+ const note = notes.find(n => n.name === name);
if (note) {
note.name = trimmed;
await writeNotes(notes);
}
- if (id === currentDocId) {
+ if (name === currentDocName) {
currentDocName = trimmed;
updateStatus();
}
@@ -828,7 +801,7 @@ async function exportDocument() {
document.getElementById("docStatus").textContent = `Exported ${shortName}`;
setTimeout(() => {
- if (currentDocId !== null) {
+ if (currentDocName !== null) {
document.getElementById("docStatus").textContent = `Editing: ${currentDocName}`;
} else {
document.getElementById("docStatus").textContent = "New Jot";
@@ -854,7 +827,7 @@ function updateCounts(text) {
function updateStatus() {
const status = document.getElementById("docStatus");
- status.textContent = currentDocId !== null
+ status.textContent = currentDocName !== null
? `Editing: ${currentDocName}`
: "New Jot";
}
@@ -871,7 +844,6 @@ document.getElementById("newBtn").onclick = function() {
clearTimeout(autoSaveTimer);
setEditorText('');
updateCounts('');
- currentDocId = null;
currentDocName = null;
loadDocuments();
updateStatus();
@@ -895,7 +867,7 @@ editor.addEventListener("input", function() {
updateCounts(text);
scheduleSpellcheck();
- if (currentDocId === null) return;
+ if (currentDocName === null) return;
clearTimeout(autoSaveTimer);
autoSaveTimer = setTimeout(async function() {
@@ -904,7 +876,7 @@ editor.addEventListener("input", function() {
try {
let notes = await readNotes();
- const index = notes.findIndex(n => n.id === currentDocId);
+ const index = notes.findIndex(n => n.name === currentDocName);
if (index !== -1) {
notes[index].content = t;
notes[index].updated = new Date().toISOString();