diff --git a/apps/client/src/components/locale-combobox.tsx b/apps/client/src/components/locale-combobox.tsx new file mode 100644 index 00000000..e9d6de14 --- /dev/null +++ b/apps/client/src/components/locale-combobox.tsx @@ -0,0 +1,71 @@ +import { t } from "@lingui/macro"; +import { Check } from "@phosphor-icons/react"; +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + ScrollArea, +} from "@reactive-resume/ui"; +import { cn } from "@reactive-resume/utils"; +import fuzzy from "fuzzy"; +import { useMemo, useState } from "react"; + +import { useLanguages } from "../services/resume/translation"; + +type Props = { + value: string; + onValueChange: (locale: string) => void; +}; + +export const LocaleCombobox = ({ value, onValueChange }: Props) => { + const { languages } = useLanguages(); + const [search, setSearch] = useState(""); + + const options = useMemo(() => { + return fuzzy.filter(search, languages, { + extract: (lang) => `${lang.name} ${lang.locale}`, + }); + }, [search, languages]); + + return ( + + + {t`No results found`} + + +
+ {options.map(({ original }) => ( + { + const result = options.find( + ({ original }) => original.locale.trim().toLowerCase() === selectedValue, + ); + + if (!result) return null; + + onValueChange(result.original.locale); + }} + > + + {original.name} ({original.locale}) + + ))} +
+
+
+
+ ); +}; diff --git a/apps/client/src/components/locale-switch.tsx b/apps/client/src/components/locale-switch.tsx index d8afc324..58d3e684 100644 --- a/apps/client/src/components/locale-switch.tsx +++ b/apps/client/src/components/locale-switch.tsx @@ -1,35 +1,15 @@ -import { t } from "@lingui/macro"; import { useLingui } from "@lingui/react"; -import { Check, Translate } from "@phosphor-icons/react"; -import { - Button, - Command, - CommandEmpty, - CommandGroup, - CommandInput, - CommandItem, - Popover, - PopoverContent, - PopoverTrigger, - ScrollArea, -} from "@reactive-resume/ui"; -import { cn } from "@reactive-resume/utils"; +import { Translate } from "@phosphor-icons/react"; +import { Button, Popover, PopoverContent, PopoverTrigger } from "@reactive-resume/ui"; import { useState } from "react"; import { changeLanguage } from "../providers/locale"; -import { useLanguages } from "../services/resume/translation"; +import { LocaleCombobox } from "./locale-combobox"; export const LocaleSwitch = () => { const { i18n } = useLingui(); - const { languages } = useLanguages(); - const [open, setOpen] = useState(false); - const options = languages.map((language) => ({ - label: language.name, - value: language.locale, - })); - return ( @@ -38,40 +18,13 @@ export const LocaleSwitch = () => { - - - {t`No results found`} - - -
- {options.map((option) => ( - { - const option = options.find( - (option) => option.value.toLowerCase().trim() === selectedValue, - ); - - if (!option) return null; - - await changeLanguage(option.value); - setOpen(false); - }} - > - - {option.label} ({option.value}) - - ))} -
-
-
-
+ { + await changeLanguage(locale); + setOpen(false); + }} + />
); diff --git a/apps/client/src/pages/dashboard/settings/_sections/profile.tsx b/apps/client/src/pages/dashboard/settings/_sections/profile.tsx index dce3785f..5a7de999 100644 --- a/apps/client/src/pages/dashboard/settings/_sections/profile.tsx +++ b/apps/client/src/pages/dashboard/settings/_sections/profile.tsx @@ -9,7 +9,7 @@ import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { z } from "zod"; -import { useLanguages } from "@/client/services/resume/translation"; +import { LocaleCombobox } from "@/client/components/locale-combobox"; import { useUpdateUser, useUser } from "@/client/services/user"; const formSchema = z.object({ @@ -21,7 +21,6 @@ type FormValues = z.infer; export const ProfileSettings = () => { const { user } = useUser(); - const { languages } = useLanguages(); const { theme, setTheme } = useTheme(); const { updateUser, loading } = useUpdateUser(); @@ -95,19 +94,7 @@ export const ProfileSettings = () => { {t`Language`}
- ({ - label: ( - <> - {name} ({locale}) - - ), - value: locale, - }))} - /> +
diff --git a/apps/client/src/pages/home/sections/faq/index.tsx b/apps/client/src/pages/home/sections/faq/index.tsx index f70eb773..924ce151 100644 --- a/apps/client/src/pages/home/sections/faq/index.tsx +++ b/apps/client/src/pages/home/sections/faq/index.tsx @@ -160,10 +160,10 @@ const Question4 = () => { className="no-underline" href={`https://crowdin.com/translate/reactive-resume/all/en-${language.editorCode}`} > -
+
{language.name} - {language.progress && ( + {language.progress !== undefined && ( = 0.6.0'} + dev: false + /gensync@1.0.0-beta.2: resolution: {integrity: sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==} engines: {node: '>=6.9.0'}