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

57 lines
1.6 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");
return (isReadOnly &&
2025-12-09 21:11:30 +02:00
<Badge
icon="bx bx-lock"
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>
);
}