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:44:39 +02:00
|
|
|
import { useShareInfo } from "./shared_info";
|
2025-12-09 21:50:38 +02:00
|
|
|
import clsx from "clsx";
|
2025-12-09 23:02:21 +02:00
|
|
|
import { t } from "../services/i18n";
|
2025-12-09 21:06:28 +02:00
|
|
|
|
2025-12-09 23:00:41 +02:00
|
|
|
export default function BreadcrumbBadges() {
|
2025-12-09 21:06:28 +02:00
|
|
|
return (
|
|
|
|
|
<div className="breadcrumb-badges">
|
|
|
|
|
<ReadOnlyBadge />
|
2025-12-09 21:44:39 +02:00
|
|
|
<ShareBadge />
|
2025-12-09 21:06:28 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ReadOnlyBadge() {
|
|
|
|
|
const { note, noteContext } = useNoteContext();
|
|
|
|
|
const { isReadOnly, enableEditing } = useIsNoteReadOnly(note, noteContext);
|
|
|
|
|
const isExplicitReadOnly = note?.isLabelTruthy("readOnly");
|
2025-12-10 09:11:28 +02:00
|
|
|
const isTemporarilyEditable = noteContext?.viewScope?.readOnlyTemporarilyDisabled;
|
2025-12-09 21:06:28 +02:00
|
|
|
|
2025-12-10 09:11:28 +02:00
|
|
|
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()}>
|
2025-12-09 23:02:21 +02:00
|
|
|
{isExplicitReadOnly ? t("breadcrumb_badges.read_only_explicit") : t("breadcrumb_badges.read_only_auto")}
|
2025-12-10 09:11:28 +02:00
|
|
|
</Badge>;
|
|
|
|
|
}
|
2025-12-09 21:06:28 +02:00
|
|
|
}
|
|
|
|
|
|
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"}
|
|
|
|
|
>
|
2025-12-09 23:02:21 +02:00
|
|
|
{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 }) {
|
2025-12-09 21:06:28 +02:00
|
|
|
return (
|
2025-12-09 21:50:38 +02:00
|
|
|
<div
|
|
|
|
|
className={clsx("breadcrumb-badge", { "clickable": !!onClick })}
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
>
|
2025-12-09 21:11:30 +02:00
|
|
|
<Icon icon={icon} />
|
2025-12-09 21:06:28 +02:00
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|