refactor
This commit is contained in:
parent
b69432610b
commit
088363d548
|
|
@ -2248,22 +2248,9 @@ function noteApp() {
|
|||
setTimeout(() => this.scrollToAnchor(anchor), 100);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Note doesn't exist - offer to create it
|
||||
if (confirm(this.t('notes.create_from_link', { path: 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));
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (confirm(this.t('notes.create_from_link', { path: notePath }))) {
|
||||
// Note doesn't exist - create it (reuses createNote with duplicate check)
|
||||
this.createNote(null, notePath);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -2839,7 +2826,13 @@ function noteApp() {
|
|||
// UNIFIED CREATION FUNCTIONS (reusable from anywhere)
|
||||
// =====================================================
|
||||
|
||||
async createNote(folderPath = null) {
|
||||
async createNote(folderPath = null, directPath = null) {
|
||||
let notePath;
|
||||
|
||||
if (directPath) {
|
||||
// Direct path provided (e.g., from wiki link) - skip prompting
|
||||
notePath = directPath.endsWith('.md') ? directPath : `${directPath}.md`;
|
||||
} else {
|
||||
// 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;
|
||||
|
|
@ -2871,17 +2864,17 @@ function noteApp() {
|
|||
|
||||
const validatedName = validation.sanitized;
|
||||
|
||||
let notePath;
|
||||
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);
|
||||
if (existingNote) {
|
||||
alert(this.t('notes.already_exists', { name: validatedName }));
|
||||
alert(this.t('notes.already_exists', { name: notePath }));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -2893,9 +2886,9 @@ function noteApp() {
|
|||
});
|
||||
|
||||
if (response.ok) {
|
||||
if (targetFolder) {
|
||||
this.expandedFolders.add(targetFolder);
|
||||
}
|
||||
// Expand parent folder if note is in a subfolder
|
||||
const folderPart = notePath.includes('/') ? notePath.substring(0, notePath.lastIndexOf('/')) : '';
|
||||
if (folderPart) this.expandedFolders.add(folderPart);
|
||||
await this.loadNotes();
|
||||
await this.loadNote(notePath);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue