mirror of
https://github.com/zadam/trilium.git
synced 2025-12-12 10:24:23 +01:00
fix(status_bar): language selector not updating properly
This commit is contained in:
parent
6e8e10323f
commit
1ab89d0db0
@ -1,19 +1,25 @@
|
|||||||
|
import "./NoteStatusBar.css";
|
||||||
|
|
||||||
import { t } from "../services/i18n";
|
import { t } from "../services/i18n";
|
||||||
import { openInAppHelpFromUrl } from "../services/utils";
|
import { openInAppHelpFromUrl } from "../services/utils";
|
||||||
import "./NoteStatusBar.css";
|
|
||||||
import { FormListItem } from "./react/FormList";
|
import { FormListItem } from "./react/FormList";
|
||||||
|
import { useNoteContext } from "./react/hooks";
|
||||||
import { NoteLanguageSelector } from "./ribbon/BasicPropertiesTab";
|
import { NoteLanguageSelector } from "./ribbon/BasicPropertiesTab";
|
||||||
|
|
||||||
export default function NoteStatusBar() {
|
export default function NoteStatusBar() {
|
||||||
|
const { note } = useNoteContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="note-status-bar">
|
<div className="note-status-bar">
|
||||||
<NoteLanguageSelector extraChildren={(
|
<NoteLanguageSelector
|
||||||
|
note={note}
|
||||||
|
extraChildren={(
|
||||||
<FormListItem
|
<FormListItem
|
||||||
onClick={() => openInAppHelpFromUrl("veGu4faJErEM")}
|
onClick={() => openInAppHelpFromUrl("veGu4faJErEM")}
|
||||||
icon="bx bx-help-circle"
|
icon="bx bx-help-circle"
|
||||||
>{t("note_language.help-on-languages")}</FormListItem>
|
>{t("note_language.help-on-languages")}</FormListItem>
|
||||||
)} />
|
)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -330,7 +330,7 @@ function NoteLanguageSwitch({ note }: { note?: FNote | null }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function NoteLanguageSelector({ note, extraChildren }: { note?: FNote | null, extraChildren?: ComponentChildren }) {
|
export function NoteLanguageSelector({ note, extraChildren }: { note: FNote | null | undefined, extraChildren?: ComponentChildren }) {
|
||||||
const [ modalShown, setModalShown ] = useState(false);
|
const [ modalShown, setModalShown ] = useState(false);
|
||||||
const [ languages ] = useTriliumOption("languages");
|
const [ languages ] = useTriliumOption("languages");
|
||||||
const DEFAULT_LOCALE = {
|
const DEFAULT_LOCALE = {
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import { Locale } from "@triliumnext/commons";
|
import { Locale } from "@triliumnext/commons";
|
||||||
|
import { ComponentChildren } from "preact";
|
||||||
|
import { useMemo } from "preact/hooks";
|
||||||
|
|
||||||
import Dropdown from "../../../react/Dropdown";
|
import Dropdown from "../../../react/Dropdown";
|
||||||
import { FormDropdownDivider, FormListItem } from "../../../react/FormList";
|
import { FormDropdownDivider, FormListItem } from "../../../react/FormList";
|
||||||
import { ComponentChildren } from "preact";
|
|
||||||
import { useMemo, useState } from "preact/hooks";
|
|
||||||
|
|
||||||
export function LocaleSelector({ id, locales, currentValue, onChange, defaultLocale, extraChildren }: {
|
export function LocaleSelector({ id, locales, currentValue, onChange, defaultLocale, extraChildren }: {
|
||||||
id?: string;
|
id?: string;
|
||||||
@ -12,7 +13,7 @@ export function LocaleSelector({ id, locales, currentValue, onChange, defaultLoc
|
|||||||
defaultLocale?: Locale,
|
defaultLocale?: Locale,
|
||||||
extraChildren?: ComponentChildren
|
extraChildren?: ComponentChildren
|
||||||
}) {
|
}) {
|
||||||
const [ activeLocale, setActiveLocale ] = useState(defaultLocale?.id === currentValue ? defaultLocale : locales.find(l => l.id === currentValue));
|
const activeLocale = defaultLocale?.id === currentValue ? defaultLocale : locales.find(l => l.id === currentValue);
|
||||||
|
|
||||||
const processedLocales = useMemo(() => {
|
const processedLocales = useMemo(() => {
|
||||||
const leftToRightLanguages = locales.filter((l) => !l.rtl);
|
const leftToRightLanguages = locales.filter((l) => !l.rtl);
|
||||||
@ -48,7 +49,6 @@ export function LocaleSelector({ id, locales, currentValue, onChange, defaultLoc
|
|||||||
rtl={locale.rtl}
|
rtl={locale.rtl}
|
||||||
checked={locale.id === currentValue}
|
checked={locale.id === currentValue}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setActiveLocale(locale);
|
|
||||||
onChange(locale.id);
|
onChange(locale.id);
|
||||||
}}
|
}}
|
||||||
>{locale.name}</FormListItem>
|
>{locale.name}</FormListItem>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user