Files
Trilium/apps/client/src/widgets/BreadcrumbBadges.tsx

65 lines
2.0 KiB
TypeScript
Raw Normal View History

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:44:39 +02:00
import { useShareInfo } from "./shared_info";
import clsx from "clsx";
import { t } from "../services/i18n";
export default function BreadcrumbBadges() {
return (
<div className="breadcrumb-badges">
<ReadOnlyBadge />
2025-12-09 21:44:39 +02:00
<ShareBadge />
</div>
);
}
function ReadOnlyBadge() {
const { note, noteContext } = useNoteContext();
const { isReadOnly, enableEditing } = useIsNoteReadOnly(note, noteContext);
const isExplicitReadOnly = note?.isLabelTruthy("readOnly");
const isTemporarilyEditable = noteContext?.viewScope?.readOnlyTemporarilyDisabled;
if (isTemporarilyEditable) {
return <Badge
icon="bx bx-lock-open-alt"
onClick={() => enableEditing(false)}
>
{t("breadcrumb_badges.read_only_temporarily_disabled")}
</Badge>;
} else if (isReadOnly) {
return <Badge
icon="bx bx-lock-alt"
2025-12-09 21:11:30 +02:00
onClick={() => enableEditing()}>
{isExplicitReadOnly ? t("breadcrumb_badges.read_only_explicit") : t("breadcrumb_badges.read_only_auto")}
</Badge>;
}
}
2025-12-09 21:44:39 +02:00
function ShareBadge() {
const { note } = useNoteContext();
const { isSharedExternally, link } = useShareInfo(note);
return (link &&
<Badge
icon={isSharedExternally ? "bx bx-world" : "bx bx-link"}
>
{isSharedExternally ? t("breadcrumb_badges.shared_publicly") : t("breadcrumb_badges.shared_locally")}
2025-12-09 21:44:39 +02:00
</Badge>
);
}
2025-12-09 21:11:30 +02:00
function Badge({ icon, children, onClick }: { icon: string, children: ComponentChildren, onClick?: () => void }) {
return (
<div
className={clsx("breadcrumb-badge", { "clickable": !!onClick })}
onClick={onClick}
>
2025-12-09 21:11:30 +02:00
<Icon icon={icon} />&nbsp;
{children}
</div>
);
}