import "./StatusBar.css"; import { Locale } from "@triliumnext/commons"; import clsx from "clsx"; import { type ComponentChildren } from "preact"; import { createPortal } from "preact/compat"; import { useState } from "preact/hooks"; import FNote from "../../entities/fnote"; import { t } from "../../services/i18n"; import { openInAppHelpFromUrl } from "../../services/utils"; import { formatDateTime } from "../../utils/formatters"; import Dropdown, { DropdownProps } from "../react/Dropdown"; import { FormDropdownDivider, FormListItem } from "../react/FormList"; import { useActiveNoteContext } from "../react/hooks"; import Icon from "../react/Icon"; import { ContentLanguagesModal, useLanguageSwitcher } from "../ribbon/BasicPropertiesTab"; import { NoteSizeWidget, useNoteMetadata } from "../ribbon/NoteInfoTab"; import { useProcessedLocales } from "../type_widgets/options/components/LocaleSelector"; import Breadcrumb from "./Breadcrumb"; import NoteContext from "../../components/note_context"; interface StatusBarContext { note: FNote; noteContext: NoteContext; } export default function StatusBar() { const { note, noteContext } = useActiveNoteContext(); const context = note && noteContext && { note, noteContext } satisfies StatusBarContext; return (
{context && <>
}
); } function StatusBarDropdown({ children, icon, text, buttonClassName, titleOptions, ...dropdownProps }: Omit & { title: string; icon?: string; }) { return ( {icon && (<> )} {text} } {...dropdownProps} > {children} ); } //#region Language Switcher function LanguageSwitcher({ note }: StatusBarContext) { const [ modalShown, setModalShown ] = useState(false); const { locales, DEFAULT_LOCALE, currentNoteLanguage, setCurrentNoteLanguage } = useLanguageSwitcher(note); const { activeLocale, processedLocales } = useProcessedLocales(locales, DEFAULT_LOCALE, currentNoteLanguage ?? DEFAULT_LOCALE.id); return ( <> {getLocaleName(activeLocale)}} > {processedLocales.map(locale => { if (typeof locale === "object") { return setCurrentNoteLanguage(locale.id)} >{locale.name} } else { return } })} openInAppHelpFromUrl("veGu4faJErEM")} icon="bx bx-help-circle" >{t("note_language.help-on-languages")} setModalShown(true)} icon="bx bx-cog" >{t("note_language.configure-languages")} {createPortal( , document.body )} ); } export function getLocaleName(locale: Locale | null | undefined) { if (!locale) return ""; if (!locale.id) return "-"; 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(); } //#endregion //#region Note info export function NoteInfoBadge({ note }: { note: FNote | null | undefined }) { const { metadata, ...sizeProps } = useNoteMetadata(note); return (note &&
    {note.type} {note.mime && ({note.mime})}} /> {note.noteId}} /> } />
); } function NoteInfoValue({ text, title, value }: { text: string; title?: string, value: ComponentChildren }) { return (
  • {text}{": "} {value}
  • ); } //#endregion