2025-12-09 21:06:28 +02:00
|
|
|
import "./BreadcrumbBadges.css";
|
|
|
|
|
|
|
|
|
|
import { ComponentChildren } from "preact";
|
|
|
|
|
import { useIsNoteReadOnly, useNoteContext } from "./react/hooks";
|
2025-12-09 21:11:30 +02:00
|
|
|
import Icon from "./react/Icon";
|
2025-12-09 21:06:28 +02:00
|
|
|
|
|
|
|
|
export default function NoteBadges() {
|
|
|
|
|
return (
|
|
|
|
|
<div className="breadcrumb-badges">
|
|
|
|
|
<ReadOnlyBadge />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ReadOnlyBadge() {
|
|
|
|
|
const { note, noteContext } = useNoteContext();
|
|
|
|
|
const { isReadOnly, enableEditing } = useIsNoteReadOnly(note, noteContext);
|
|
|
|
|
const isExplicitReadOnly = note?.isLabelTruthy("readOnly");
|
|
|
|
|
|
|
|
|
|
return (isReadOnly &&
|
2025-12-09 21:11:30 +02:00
|
|
|
<Badge
|
|
|
|
|
icon="bx bx-lock"
|
|
|
|
|
onClick={() => enableEditing()}>
|
2025-12-09 21:06:28 +02:00
|
|
|
{isExplicitReadOnly ? "Read-only" : "Auto read-only"}
|
|
|
|
|
</Badge>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-09 21:11:30 +02:00
|
|
|
function Badge({ icon, children, onClick }: { icon: string, children: ComponentChildren, onClick?: () => void }) {
|
2025-12-09 21:06:28 +02:00
|
|
|
return (
|
|
|
|
|
<div className="breadcrumb-badge" onClick={onClick}>
|
2025-12-09 21:11:30 +02:00
|
|
|
<Icon icon={icon} />
|
2025-12-09 21:06:28 +02:00
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|