2025-12-12 00:13:25 +02:00
|
|
|
import "./StatusBar.css";
|
|
|
|
|
|
2025-12-12 19:31:00 +02:00
|
|
|
import { Locale } from "@triliumnext/commons";
|
|
|
|
|
import clsx from "clsx";
|
2025-12-12 20:17:07 +02:00
|
|
|
import { type ComponentChildren } from "preact";
|
2025-12-12 19:31:00 +02:00
|
|
|
import { createPortal } from "preact/compat";
|
|
|
|
|
import { useState } from "preact/hooks";
|
|
|
|
|
|
2025-12-12 00:34:47 +02:00
|
|
|
import FNote from "../../entities/fnote";
|
|
|
|
|
import { t } from "../../services/i18n";
|
|
|
|
|
import { openInAppHelpFromUrl } from "../../services/utils";
|
2025-12-12 19:31:00 +02:00
|
|
|
import { formatDateTime } from "../../utils/formatters";
|
|
|
|
|
import Dropdown, { DropdownProps } from "../react/Dropdown";
|
2025-12-12 18:29:40 +02:00
|
|
|
import { FormDropdownDivider, FormListItem } from "../react/FormList";
|
2025-12-12 20:17:07 +02:00
|
|
|
import { useActiveNoteContext } from "../react/hooks";
|
2025-12-12 18:46:34 +02:00
|
|
|
import Icon from "../react/Icon";
|
2025-12-12 19:31:00 +02:00
|
|
|
import { ContentLanguagesModal, useLanguageSwitcher } from "../ribbon/BasicPropertiesTab";
|
|
|
|
|
import { NoteSizeWidget, useNoteMetadata } from "../ribbon/NoteInfoTab";
|
|
|
|
|
import { useProcessedLocales } from "../type_widgets/options/components/LocaleSelector";
|
|
|
|
|
import Breadcrumb from "./Breadcrumb";
|
2025-12-12 20:17:07 +02:00
|
|
|
import NoteContext from "../../components/note_context";
|
2025-12-12 00:34:47 +02:00
|
|
|
|
|
|
|
|
interface StatusBarContext {
|
|
|
|
|
note: FNote;
|
2025-12-12 20:17:07 +02:00
|
|
|
noteContext: NoteContext;
|
2025-12-12 00:34:47 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-12 00:13:25 +02:00
|
|
|
export default function StatusBar() {
|
2025-12-12 20:17:07 +02:00
|
|
|
const { note, noteContext } = useActiveNoteContext();
|
|
|
|
|
const context = note && noteContext && { note, noteContext } satisfies StatusBarContext;
|
2025-12-12 00:34:47 +02:00
|
|
|
|
2025-12-12 00:13:25 +02:00
|
|
|
return (
|
|
|
|
|
<div className="status-bar">
|
2025-12-12 00:34:47 +02:00
|
|
|
{context && <>
|
|
|
|
|
<div className="breadcrumb-row">
|
2025-12-12 20:17:07 +02:00
|
|
|
<Breadcrumb {...context} />
|
2025-12-12 00:34:47 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="actions-row">
|
2025-12-12 19:31:00 +02:00
|
|
|
<NoteInfoBadge {...context} />
|
2025-12-12 00:34:47 +02:00
|
|
|
<LanguageSwitcher {...context} />
|
|
|
|
|
</div>
|
|
|
|
|
</>}
|
2025-12-12 00:13:25 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-12-12 00:34:47 +02:00
|
|
|
|
2025-12-12 18:58:54 +02:00
|
|
|
function StatusBarDropdown({ children, icon, text, buttonClassName, titleOptions, ...dropdownProps }: Omit<DropdownProps, "hideToggleArrow" | "title" | "titlePosition"> & {
|
|
|
|
|
title: string;
|
2025-12-12 18:46:34 +02:00
|
|
|
icon?: string;
|
|
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<Dropdown
|
|
|
|
|
buttonClassName={clsx("status-bar-dropdown-button", buttonClassName)}
|
2025-12-12 18:58:54 +02:00
|
|
|
titlePosition="top"
|
|
|
|
|
titleOptions={{
|
|
|
|
|
...titleOptions,
|
|
|
|
|
popperConfig: {
|
|
|
|
|
...titleOptions?.popperConfig,
|
|
|
|
|
strategy: "fixed"
|
|
|
|
|
}
|
|
|
|
|
}}
|
2025-12-12 18:46:34 +02:00
|
|
|
text={<>
|
|
|
|
|
{icon && (<><Icon icon={icon} /> </>)}
|
|
|
|
|
{text}
|
|
|
|
|
</>}
|
|
|
|
|
{...dropdownProps}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</Dropdown>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-12 19:31:00 +02:00
|
|
|
//#region Language Switcher
|
2025-12-12 00:34:47 +02:00
|
|
|
function LanguageSwitcher({ note }: StatusBarContext) {
|
2025-12-12 18:29:40 +02:00
|
|
|
const [ modalShown, setModalShown ] = useState(false);
|
|
|
|
|
const { locales, DEFAULT_LOCALE, currentNoteLanguage, setCurrentNoteLanguage } = useLanguageSwitcher(note);
|
|
|
|
|
const { activeLocale, processedLocales } = useProcessedLocales(locales, DEFAULT_LOCALE, currentNoteLanguage ?? DEFAULT_LOCALE.id);
|
|
|
|
|
|
2025-12-12 00:34:47 +02:00
|
|
|
return (
|
2025-12-12 18:29:40 +02:00
|
|
|
<>
|
2025-12-12 18:58:54 +02:00
|
|
|
<StatusBarDropdown
|
|
|
|
|
icon="bx bx-globe"
|
|
|
|
|
title={t("status_bar.language_title")}
|
|
|
|
|
text={<span dir={activeLocale?.rtl ? "rtl" : "ltr"}>{getLocaleName(activeLocale)}</span>}
|
|
|
|
|
>
|
2025-12-12 18:29:40 +02:00
|
|
|
{processedLocales.map(locale => {
|
|
|
|
|
if (typeof locale === "object") {
|
|
|
|
|
return <FormListItem
|
|
|
|
|
rtl={locale.rtl}
|
|
|
|
|
checked={locale.id === currentNoteLanguage}
|
|
|
|
|
onClick={() => setCurrentNoteLanguage(locale.id)}
|
|
|
|
|
>{locale.name}</FormListItem>
|
|
|
|
|
} else {
|
|
|
|
|
return <FormDropdownDivider />
|
|
|
|
|
}
|
|
|
|
|
})}
|
|
|
|
|
<FormDropdownDivider />
|
2025-12-12 00:34:47 +02:00
|
|
|
<FormListItem
|
|
|
|
|
onClick={() => openInAppHelpFromUrl("veGu4faJErEM")}
|
|
|
|
|
icon="bx bx-help-circle"
|
|
|
|
|
>{t("note_language.help-on-languages")}</FormListItem>
|
2025-12-12 18:29:40 +02:00
|
|
|
<FormListItem
|
|
|
|
|
onClick={() => setModalShown(true)}
|
|
|
|
|
icon="bx bx-cog"
|
|
|
|
|
>{t("note_language.configure-languages")}</FormListItem>
|
2025-12-12 18:46:34 +02:00
|
|
|
</StatusBarDropdown>
|
2025-12-12 18:29:40 +02:00
|
|
|
{createPortal(
|
|
|
|
|
<ContentLanguagesModal modalShown={modalShown} setModalShown={setModalShown} />,
|
|
|
|
|
document.body
|
2025-12-12 00:34:47 +02:00
|
|
|
)}
|
2025-12-12 18:29:40 +02:00
|
|
|
</>
|
2025-12-12 00:34:47 +02:00
|
|
|
);
|
|
|
|
|
}
|
2025-12-12 18:29:40 +02:00
|
|
|
|
|
|
|
|
export function getLocaleName(locale: Locale | null | undefined) {
|
|
|
|
|
if (!locale) return "";
|
|
|
|
|
if (!locale.id) return "-";
|
2025-12-12 18:53:54 +02:00
|
|
|
if (locale.name.length <= 4 || locale.rtl) return locale.name; // Some locales like Japanese and Chinese look better than their ID.
|
|
|
|
|
return locale.id
|
|
|
|
|
.replace("_", "-")
|
|
|
|
|
.toLocaleUpperCase();
|
2025-12-12 18:29:40 +02:00
|
|
|
}
|
2025-12-12 19:31:00 +02:00
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
//#region Note info
|
|
|
|
|
export function NoteInfoBadge({ note }: { note: FNote | null | undefined }) {
|
|
|
|
|
const { metadata, ...sizeProps } = useNoteMetadata(note);
|
|
|
|
|
|
|
|
|
|
return (note &&
|
|
|
|
|
<StatusBarDropdown
|
|
|
|
|
icon="bx bx-info-circle"
|
|
|
|
|
title={t("status_bar.note_info_title")}
|
|
|
|
|
dropdownContainerClassName="dropdown-note-info"
|
|
|
|
|
dropdownOptions={{ autoClose: "outside" }}
|
|
|
|
|
>
|
|
|
|
|
<ul>
|
|
|
|
|
<NoteInfoValue text={t("note_info_widget.created")} value={formatDateTime(metadata?.dateCreated)} />
|
|
|
|
|
<NoteInfoValue text={t("note_info_widget.modified")} value={formatDateTime(metadata?.dateModified)} />
|
|
|
|
|
<NoteInfoValue text={t("note_info_widget.type")} value={<span>{note.type} {note.mime && <span>({note.mime})</span>}</span>} />
|
|
|
|
|
<NoteInfoValue text={t("note_info_widget.note_id")} value={<code>{note.noteId}</code>} />
|
|
|
|
|
<NoteInfoValue text={t("note_info_widget.note_size")} title={t("note_info_widget.note_size_info")} value={<NoteSizeWidget {...sizeProps} />} />
|
|
|
|
|
</ul>
|
|
|
|
|
</StatusBarDropdown>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function NoteInfoValue({ text, title, value }: { text: string; title?: string, value: ComponentChildren }) {
|
|
|
|
|
return (
|
|
|
|
|
<li>
|
|
|
|
|
<strong title={title}>{text}{": "}</strong>
|
|
|
|
|
<span>{value}</span>
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
//#endregion
|