mirror of
https://github.com/zadam/trilium.git
synced 2025-12-18 21:34:24 +01:00
feat(layout/inline-title): template switcher
This commit is contained in:
parent
4c2fe8a846
commit
e0f6ba808c
@ -1755,7 +1755,8 @@
|
||||
"created_on": "Created on <Value />",
|
||||
"last_modified": "Last modified on <Value />",
|
||||
"note_type_switcher_label": "Switch from {{type}} to:",
|
||||
"note_type_switcher_others": "More note types"
|
||||
"note_type_switcher_others": "More note types",
|
||||
"note_type_switcher_templates": "Templates"
|
||||
},
|
||||
"search_result": {
|
||||
"no_notes_found": "No notes have been found for given search parameters.",
|
||||
|
||||
@ -6,6 +6,9 @@ import { ComponentChild } from "preact";
|
||||
import { useEffect, useMemo, useRef, useState } from "preact/hooks";
|
||||
import { Trans } from "react-i18next";
|
||||
|
||||
import FNote from "../../entities/fnote";
|
||||
import attributes from "../../services/attributes";
|
||||
import froca from "../../services/froca";
|
||||
import { t } from "../../services/i18n";
|
||||
import { ViewScope } from "../../services/link";
|
||||
import { NOTE_TYPES, NoteTypeMapping } from "../../services/note_types";
|
||||
@ -168,6 +171,16 @@ function NoteTypeSwitcher() {
|
||||
onClick={() => switchNoteType(note.noteId, noteType)}
|
||||
/>
|
||||
))}
|
||||
<MoreNoteTypes noteId={note.noteId} restNoteTypes={restNoteTypes} />
|
||||
<TemplateNoteTypes noteId={note.noteId} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MoreNoteTypes({ noteId, restNoteTypes }: { noteId: string, restNoteTypes: NoteTypeMapping[] }) {
|
||||
return (
|
||||
<BadgeWithDropdown
|
||||
text={t("note_title.note_type_switcher_others")}
|
||||
icon="bx bx-dots-vertical-rounded"
|
||||
@ -176,13 +189,39 @@ function NoteTypeSwitcher() {
|
||||
<FormListItem
|
||||
key={noteType.type}
|
||||
icon={`bx ${noteType.icon}`}
|
||||
onClick={() => switchNoteType(note.noteId, noteType)}
|
||||
onClick={() => switchNoteType(noteId, noteType)}
|
||||
>{noteType.title}</FormListItem>
|
||||
))}
|
||||
</BadgeWithDropdown>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TemplateNoteTypes({ noteId }: { noteId: string }) {
|
||||
const [ templates, setTemplates ] = useState<FNote[]>([]);
|
||||
|
||||
async function refreshTemplates() {
|
||||
const templateNoteIds = await server.get<string[]>("search-templates");
|
||||
const templateNotes = await froca.getNotes(templateNoteIds);
|
||||
setTemplates(templateNotes);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
refreshTemplates();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<BadgeWithDropdown
|
||||
text={t("note_title.note_type_switcher_templates")}
|
||||
icon="bx bx-copy-alt"
|
||||
>
|
||||
{templates.map(template => (
|
||||
<FormListItem
|
||||
key={template.noteId}
|
||||
icon={template.getIcon()}
|
||||
onClick={() => attributes.setRelation(noteId, "template", template.noteId)}
|
||||
>{template.title}</FormListItem>
|
||||
))}
|
||||
</BadgeWithDropdown>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user