mirror of
https://github.com/zadam/trilium.git
synced 2025-12-12 02:14:25 +01:00
feat(breadcrumb): basic navigation in separator
This commit is contained in:
parent
a02235f2bd
commit
c4285772b3
@ -10,4 +10,11 @@
|
|||||||
color: inherit;
|
color: inherit;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
flex-direction: column;
|
||||||
|
list-style-type: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import { Fragment } from "preact/jsx-runtime";
|
import { Fragment } from "preact/jsx-runtime";
|
||||||
import "./Breadcrumb.css";
|
import "./Breadcrumb.css";
|
||||||
import ActionButton from "./react/ActionButton";
|
import { useChildNotes, useNoteContext } from "./react/hooks";
|
||||||
import { useNoteContext } from "./react/hooks";
|
|
||||||
import NoteLink from "./react/NoteLink";
|
import NoteLink from "./react/NoteLink";
|
||||||
import Dropdown from "./react/Dropdown";
|
import Dropdown from "./react/Dropdown";
|
||||||
import Icon from "./react/Icon";
|
import Icon from "./react/Icon";
|
||||||
|
import { FormListItem } from "./react/FormList";
|
||||||
|
import NoteContext from "../components/note_context";
|
||||||
|
|
||||||
export default function Breadcrumb() {
|
export default function Breadcrumb() {
|
||||||
const { noteContext } = useNoteContext();
|
const { noteContext } = useNoteContext();
|
||||||
@ -15,7 +16,7 @@ export default function Breadcrumb() {
|
|||||||
{notePath.map(item => (
|
{notePath.map(item => (
|
||||||
<Fragment key={item}>
|
<Fragment key={item}>
|
||||||
<BreadcrumbItem notePath={item} />
|
<BreadcrumbItem notePath={item} />
|
||||||
<BreadcrumbSeparator notePath={item} />
|
<BreadcrumbSeparator notePath={item} noteContext={noteContext} />
|
||||||
</Fragment>
|
</Fragment>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@ -31,7 +32,7 @@ function BreadcrumbItem({ notePath }: { notePath: string }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function BreadcrumbSeparator({ notePath }: { notePath: string}) {
|
function BreadcrumbSeparator({ notePath, noteContext }: { notePath: string, noteContext: NoteContext | undefined }) {
|
||||||
return (
|
return (
|
||||||
<Dropdown
|
<Dropdown
|
||||||
text={<Icon icon="bx bx-chevron-right" />}
|
text={<Icon icon="bx bx-chevron-right" />}
|
||||||
@ -39,11 +40,31 @@ function BreadcrumbSeparator({ notePath }: { notePath: string}) {
|
|||||||
buttonClassName="icon-action"
|
buttonClassName="icon-action"
|
||||||
hideToggleArrow
|
hideToggleArrow
|
||||||
>
|
>
|
||||||
Content goes here.
|
<BreadcrumbSeparatorDropdownContent notePath={notePath} noteContext={noteContext} />
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function BreadcrumbSeparatorDropdownContent({ notePath, noteContext }: { notePath: string, noteContext: NoteContext | undefined }) {
|
||||||
|
const notePathComponents = notePath.split("/");
|
||||||
|
const parentNoteId = notePathComponents.pop();
|
||||||
|
const childNotes = useChildNotes(parentNoteId);
|
||||||
|
const notePathPrefix = notePathComponents.join("/"); // last item was removed already.
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ul class="breadcrumb-child-list">
|
||||||
|
{childNotes.map((note) => (
|
||||||
|
<li key={note.noteId}>
|
||||||
|
<FormListItem
|
||||||
|
icon={note.getIcon()}
|
||||||
|
onClick={() => noteContext?.setNote(`${notePathPrefix}/${note.noteId}`)}
|
||||||
|
>{note.title}</FormListItem>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function buildNotePaths(notePathArray: string[] | undefined) {
|
function buildNotePaths(notePathArray: string[] | undefined) {
|
||||||
if (!notePathArray) return [];
|
if (!notePathArray) return [];
|
||||||
|
|
||||||
|
|||||||
@ -886,12 +886,15 @@ async function isNoteReadOnly(note: FNote, noteContext: NoteContext) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useChildNotes(parentNoteId: string) {
|
export function useChildNotes(parentNoteId: string | undefined) {
|
||||||
const [ childNotes, setChildNotes ] = useState<FNote[]>([]);
|
const [ childNotes, setChildNotes ] = useState<FNote[]>([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async function() {
|
(async function() {
|
||||||
const parentNote = await froca.getNote(parentNoteId);
|
let childNotes: FNote[] | undefined;
|
||||||
const childNotes = await parentNote?.getChildNotes();
|
if (parentNoteId) {
|
||||||
|
const parentNote = await froca.getNote(parentNoteId);
|
||||||
|
childNotes = await parentNote?.getChildNotes();
|
||||||
|
}
|
||||||
setChildNotes(childNotes ?? []);
|
setChildNotes(childNotes ?? []);
|
||||||
})();
|
})();
|
||||||
}, [ parentNoteId ]);
|
}, [ parentNoteId ]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user