2025-12-09 21:06:28 +02:00
|
|
|
import "./BreadcrumbBadges.css";
|
|
|
|
|
|
2025-12-10 09:27:44 +02:00
|
|
|
import { ComponentChildren, MouseEventHandler } from "preact";
|
|
|
|
|
import { useIsNoteReadOnly, useNoteContext, useStaticTooltip } 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-10 09:27:44 +02:00
|
|
|
import { useRef } from "preact/hooks";
|
|
|
|
|
import { goToLinkExt } from "../services/link";
|
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"
|
2025-12-10 09:27:44 +02:00
|
|
|
tooltip={t("breadcrumb_badges.read_only_temporarily_disabled_description")}
|
2025-12-10 09:11:28 +02:00
|
|
|
onClick={() => enableEditing(false)}
|
|
|
|
|
>
|
|
|
|
|
{t("breadcrumb_badges.read_only_temporarily_disabled")}
|
|
|
|
|
</Badge>;
|
|
|
|
|
} else if (isReadOnly) {
|
|
|
|
|
return <Badge
|
|
|
|
|
icon="bx bx-lock-alt"
|
2025-12-10 09:27:44 +02:00
|
|
|
tooltip={isExplicitReadOnly ? t("breadcrumb_badges.read_only_explicit_description") : t("breadcrumb_badges.read_only_auto_description")}
|
|
|
|
|
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();
|
2025-12-10 09:27:44 +02:00
|
|
|
const { isSharedExternally, link, linkHref } = useShareInfo(note);
|
2025-12-09 21:44:39 +02:00
|
|
|
|
|
|
|
|
return (link &&
|
|
|
|
|
<Badge
|
|
|
|
|
icon={isSharedExternally ? "bx bx-world" : "bx bx-link"}
|
2025-12-10 09:27:44 +02:00
|
|
|
tooltip={isSharedExternally ?
|
|
|
|
|
t("breadcrumb_badges.shared_publicly_description", { link }) :
|
|
|
|
|
t("breadcrumb_badges.shared_locally_description", { link })
|
|
|
|
|
}
|
|
|
|
|
onClick={(e) => linkHref && goToLinkExt(e, linkHref)}
|
2025-12-09 21:44:39 +02:00
|
|
|
>
|
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-10 09:27:44 +02:00
|
|
|
function Badge({ icon, children, tooltip, onClick }: { icon: string, tooltip: string, children: ComponentChildren, onClick?: MouseEventHandler<HTMLDivElement> }) {
|
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
useStaticTooltip(containerRef, {
|
|
|
|
|
placement: "bottom",
|
|
|
|
|
fallbackPlacements: [ "bottom" ],
|
|
|
|
|
animation: false,
|
|
|
|
|
html: true,
|
|
|
|
|
title: tooltip
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-09 21:06:28 +02:00
|
|
|
return (
|
2025-12-09 21:50:38 +02:00
|
|
|
<div
|
2025-12-10 09:27:44 +02:00
|
|
|
ref={containerRef}
|
2025-12-09 21:50:38 +02:00
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|