refactor
This commit is contained in:
parent
b69432610b
commit
088363d548
105
frontend/app.js
105
frontend/app.js
|
|
@ -2248,22 +2248,9 @@ function noteApp() {
|
||||||
setTimeout(() => this.scrollToAnchor(anchor), 100);
|
setTimeout(() => this.scrollToAnchor(anchor), 100);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else if (confirm(this.t('notes.create_from_link', { path: notePath }))) {
|
||||||
// Note doesn't exist - offer to create it
|
// Note doesn't exist - create it (reuses createNote with duplicate check)
|
||||||
if (confirm(this.t('notes.create_from_link', { path: notePath }))) {
|
this.createNote(null, notePath);
|
||||||
const newPath = notePath.endsWith('.md') ? notePath : `${notePath}.md`;
|
|
||||||
fetch(`/api/notes/${newPath}`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ content: '' })
|
|
||||||
}).then(response => {
|
|
||||||
if (response.ok) {
|
|
||||||
const folderPath = newPath.includes('/') ? newPath.substring(0, newPath.lastIndexOf('/')) : '';
|
|
||||||
if (folderPath) this.expandedFolders.add(folderPath);
|
|
||||||
this.loadNotes().then(() => this.loadNote(newPath));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -2839,49 +2826,55 @@ function noteApp() {
|
||||||
// UNIFIED CREATION FUNCTIONS (reusable from anywhere)
|
// UNIFIED CREATION FUNCTIONS (reusable from anywhere)
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
async createNote(folderPath = null) {
|
async createNote(folderPath = null, directPath = null) {
|
||||||
// Use provided folder path, or dropdown target folder context, or homepage folder
|
|
||||||
// Note: Check dropdownTargetFolder !== null to distinguish between '' (root) and not set
|
|
||||||
let targetFolder;
|
|
||||||
if (folderPath !== null) {
|
|
||||||
targetFolder = folderPath;
|
|
||||||
} else if (this.dropdownTargetFolder !== null && this.dropdownTargetFolder !== undefined) {
|
|
||||||
targetFolder = this.dropdownTargetFolder; // Can be '' for root or a folder path
|
|
||||||
} else {
|
|
||||||
targetFolder = this.selectedHomepageFolder || '';
|
|
||||||
}
|
|
||||||
this.closeDropdown();
|
|
||||||
|
|
||||||
const promptText = targetFolder
|
|
||||||
? this.t('notes.prompt_name_in_folder', { folder: targetFolder })
|
|
||||||
: this.t('notes.prompt_name_with_path');
|
|
||||||
|
|
||||||
const noteName = prompt(promptText);
|
|
||||||
if (!noteName) return;
|
|
||||||
|
|
||||||
// Validate the name/path (may contain / for paths when no target folder)
|
|
||||||
const validation = targetFolder
|
|
||||||
? FilenameValidator.validateFilename(noteName)
|
|
||||||
: FilenameValidator.validatePath(noteName);
|
|
||||||
|
|
||||||
if (!validation.valid) {
|
|
||||||
alert(this.getValidationErrorMessage(validation, 'note'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const validatedName = validation.sanitized;
|
|
||||||
|
|
||||||
let notePath;
|
let notePath;
|
||||||
if (targetFolder) {
|
|
||||||
notePath = `${targetFolder}/${validatedName}.md`;
|
if (directPath) {
|
||||||
|
// Direct path provided (e.g., from wiki link) - skip prompting
|
||||||
|
notePath = directPath.endsWith('.md') ? directPath : `${directPath}.md`;
|
||||||
} else {
|
} else {
|
||||||
notePath = validatedName.endsWith('.md') ? validatedName : `${validatedName}.md`;
|
// Use provided folder path, or dropdown target folder context, or homepage folder
|
||||||
|
// Note: Check dropdownTargetFolder !== null to distinguish between '' (root) and not set
|
||||||
|
let targetFolder;
|
||||||
|
if (folderPath !== null) {
|
||||||
|
targetFolder = folderPath;
|
||||||
|
} else if (this.dropdownTargetFolder !== null && this.dropdownTargetFolder !== undefined) {
|
||||||
|
targetFolder = this.dropdownTargetFolder; // Can be '' for root or a folder path
|
||||||
|
} else {
|
||||||
|
targetFolder = this.selectedHomepageFolder || '';
|
||||||
|
}
|
||||||
|
this.closeDropdown();
|
||||||
|
|
||||||
|
const promptText = targetFolder
|
||||||
|
? this.t('notes.prompt_name_in_folder', { folder: targetFolder })
|
||||||
|
: this.t('notes.prompt_name_with_path');
|
||||||
|
|
||||||
|
const noteName = prompt(promptText);
|
||||||
|
if (!noteName) return;
|
||||||
|
|
||||||
|
// Validate the name/path (may contain / for paths when no target folder)
|
||||||
|
const validation = targetFolder
|
||||||
|
? FilenameValidator.validateFilename(noteName)
|
||||||
|
: FilenameValidator.validatePath(noteName);
|
||||||
|
|
||||||
|
if (!validation.valid) {
|
||||||
|
alert(this.getValidationErrorMessage(validation, 'note'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const validatedName = validation.sanitized;
|
||||||
|
|
||||||
|
if (targetFolder) {
|
||||||
|
notePath = `${targetFolder}/${validatedName}.md`;
|
||||||
|
} else {
|
||||||
|
notePath = validatedName.endsWith('.md') ? validatedName : `${validatedName}.md`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CRITICAL: Check if note already exists
|
// CRITICAL: Check if note already exists (applies to both prompt and direct path)
|
||||||
const existingNote = this.notes.find(note => note.path === notePath);
|
const existingNote = this.notes.find(note => note.path === notePath);
|
||||||
if (existingNote) {
|
if (existingNote) {
|
||||||
alert(this.t('notes.already_exists', { name: validatedName }));
|
alert(this.t('notes.already_exists', { name: notePath }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2893,9 +2886,9 @@ function noteApp() {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
if (targetFolder) {
|
// Expand parent folder if note is in a subfolder
|
||||||
this.expandedFolders.add(targetFolder);
|
const folderPart = notePath.includes('/') ? notePath.substring(0, notePath.lastIndexOf('/')) : '';
|
||||||
}
|
if (folderPart) this.expandedFolders.add(folderPart);
|
||||||
await this.loadNotes();
|
await this.loadNotes();
|
||||||
await this.loadNote(notePath);
|
await this.loadNote(notePath);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue