From 23482531c573e10904bd027bff5eb5effdc230ce Mon Sep 17 00:00:00 2001 From: reya Date: Mon, 29 Jan 2024 14:57:00 +0700 Subject: [PATCH] feat: migrate settings screen to i18n --- apps/desktop/src/router.tsx | 9 -- apps/desktop/src/routes/settings/about.tsx | 8 +- apps/desktop/src/routes/settings/advanced.tsx | 10 +- apps/desktop/src/routes/settings/backup.tsx | 8 +- .../settings/components/avatarUpload.tsx | 5 +- .../settings/components/contactCard.tsx | 45 -------- .../settings/components/coverUpload.tsx | 5 +- .../routes/settings/components/postCard.tsx | 60 ---------- .../settings/components/profileCard.tsx | 77 ------------- .../routes/settings/components/relayCard.tsx | 46 -------- .../settings/components/walletConnectForm.tsx | 62 ----------- .../routes/settings/components/zapCard.tsx | 51 --------- .../src/routes/settings/editContact.tsx | 34 ------ apps/desktop/src/routes/settings/general.tsx | 104 ++++++------------ apps/desktop/src/routes/settings/nwc.tsx | 16 +-- apps/desktop/src/routes/settings/profile.tsx | 25 ++--- packages/ui/src/layouts/settings.tsx | 17 ++- src-tauri/locales/en.json | 83 +++++++++++++- 18 files changed, 175 insertions(+), 490 deletions(-) delete mode 100644 apps/desktop/src/routes/settings/components/contactCard.tsx delete mode 100644 apps/desktop/src/routes/settings/components/postCard.tsx delete mode 100644 apps/desktop/src/routes/settings/components/profileCard.tsx delete mode 100644 apps/desktop/src/routes/settings/components/relayCard.tsx delete mode 100644 apps/desktop/src/routes/settings/components/walletConnectForm.tsx delete mode 100644 apps/desktop/src/routes/settings/components/zapCard.tsx delete mode 100644 apps/desktop/src/routes/settings/editContact.tsx diff --git a/apps/desktop/src/router.tsx b/apps/desktop/src/router.tsx index a840b26f..23844d38 100644 --- a/apps/desktop/src/router.tsx +++ b/apps/desktop/src/router.tsx @@ -59,15 +59,6 @@ export default function Router() { return { Component: ProfileSettingScreen }; }, }, - { - path: "edit-contact", - async lazy() { - const { EditContactScreen } = await import( - "./routes/settings/editContact" - ); - return { Component: EditContactScreen }; - }, - }, { path: "backup", async lazy() { diff --git a/apps/desktop/src/routes/settings/about.tsx b/apps/desktop/src/routes/settings/about.tsx index 784eb1fe..db0b386c 100644 --- a/apps/desktop/src/routes/settings/about.tsx +++ b/apps/desktop/src/routes/settings/about.tsx @@ -2,10 +2,12 @@ import { getVersion } from "@tauri-apps/api/app"; import { relaunch } from "@tauri-apps/plugin-process"; import { Update, check } from "@tauri-apps/plugin-updater"; import { useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; import { toast } from "sonner"; export function AboutScreen() { + const [t] = useTranslation(); const [version, setVersion] = useState(""); const [newUpdate, setNewUpdate] = useState(null); @@ -34,7 +36,7 @@ export function AboutScreen() {

Lume

- Version {version} + {t("settings.about.version")} {version}

@@ -44,7 +46,7 @@ export function AboutScreen() { onClick={() => checkUpdate()} className="inline-flex h-9 w-full items-center justify-center rounded-lg bg-blue-500 text-sm font-medium text-white hover:bg-blue-600" > - Check for update + {t("settings.about.checkUpdate")} ) : ( )} { await storage.clearCache(); @@ -13,16 +15,18 @@ export function AdvancedSettingScreen() {
- Cache + {t("settings.advanced.cache.title")} +
+
+ {t("settings.advanced.cache.subtitle")}
-
Use for boost up nostr connection
diff --git a/apps/desktop/src/routes/settings/backup.tsx b/apps/desktop/src/routes/settings/backup.tsx index 129d46bc..aa095b44 100644 --- a/apps/desktop/src/routes/settings/backup.tsx +++ b/apps/desktop/src/routes/settings/backup.tsx @@ -3,11 +3,13 @@ import { EyeOffIcon } from "@lume/icons"; import { useStorage } from "@lume/storage"; import { nip19 } from "nostr-tools"; import { useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; export function BackupSettingScreen() { const ark = useArk(); const storage = useStorage(); + const [t] = useTranslation(); const [privkey, setPrivkey] = useState(null); const [showPassword, setShowPassword] = useState(false); @@ -29,7 +31,9 @@ export function BackupSettingScreen() {
{privkey ? (
-
Private key
+
+ {t("settings.backup.privkey.title")} +
removePrivkey()} className="mt-2 inline-flex h-11 w-full items-center justify-center gap-2 rounded-lg bg-red-200 dark:bg-red-800 px-6 font-medium text-red-500 hover:bg-red-500 hover:text-white focus:outline-none dark:hover:text-white" > - Remove private key + {t("settings.backup.privkey.button")}
) : null} diff --git a/apps/desktop/src/routes/settings/components/avatarUpload.tsx b/apps/desktop/src/routes/settings/components/avatarUpload.tsx index 54ae1618..601f43f6 100644 --- a/apps/desktop/src/routes/settings/components/avatarUpload.tsx +++ b/apps/desktop/src/routes/settings/components/avatarUpload.tsx @@ -1,10 +1,13 @@ import { useArk } from "@lume/ark"; import { LoaderIcon } from "@lume/icons"; import { useState } from "react"; +import { useTranslation } from "react-i18next"; import { toast } from "sonner"; export function AvatarUpload({ setPicture }) { const ark = useArk(); + + const [t] = useTranslation(); const [loading, setLoading] = useState(false); const upload = async () => { @@ -36,7 +39,7 @@ export function AvatarUpload({ setPicture }) { {loading ? ( ) : ( - "Change avatar" + t("user.avatarButton") )} ); diff --git a/apps/desktop/src/routes/settings/components/contactCard.tsx b/apps/desktop/src/routes/settings/components/contactCard.tsx deleted file mode 100644 index 9af13390..00000000 --- a/apps/desktop/src/routes/settings/components/contactCard.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { useArk } from "@lume/ark"; -import { EditIcon, LoaderIcon } from "@lume/icons"; -import { compactNumber } from "@lume/utils"; -import { useQuery } from "@tanstack/react-query"; -import { Link } from "react-router-dom"; - -export function ContactCard() { - const ark = useArk(); - const { status, data } = useQuery({ - queryKey: ["contacts"], - queryFn: async () => { - const contacts = await ark.getUserContacts(); - return contacts; - }, - refetchOnWindowFocus: false, - }); - - return ( -
- {status === "pending" ? ( -
- -
- ) : ( -
-

- {compactNumber.format(data.length)} -

-
-

- Contacts -

- - - Edit - -
-
- )} -
- ); -} diff --git a/apps/desktop/src/routes/settings/components/coverUpload.tsx b/apps/desktop/src/routes/settings/components/coverUpload.tsx index 88f1ebf8..bdeb7868 100644 --- a/apps/desktop/src/routes/settings/components/coverUpload.tsx +++ b/apps/desktop/src/routes/settings/components/coverUpload.tsx @@ -1,10 +1,13 @@ import { useArk } from "@lume/ark"; import { LoaderIcon } from "@lume/icons"; import { useState } from "react"; +import { useTranslation } from "react-i18next"; import { toast } from "sonner"; export function CoverUpload({ setBanner }) { const ark = useArk(); + + const [t] = useTranslation(); const [loading, setLoading] = useState(false); const upload = async () => { @@ -36,7 +39,7 @@ export function CoverUpload({ setBanner }) { {loading ? ( ) : ( - "Change cover" + t("user.coverButton") )} ); diff --git a/apps/desktop/src/routes/settings/components/postCard.tsx b/apps/desktop/src/routes/settings/components/postCard.tsx deleted file mode 100644 index f828d4a0..00000000 --- a/apps/desktop/src/routes/settings/components/postCard.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import { useArk } from "@lume/ark"; -import { LoaderIcon } from "@lume/icons"; -import { compactNumber } from "@lume/utils"; -import { useQuery } from "@tanstack/react-query"; -import { fetch } from "@tauri-apps/plugin-http"; -import { Link } from "react-router-dom"; - -export function PostCard() { - const ark = useArk(); - const { status, data } = useQuery({ - queryKey: ["user-stats", ark.account.pubkey], - queryFn: async ({ signal }: { signal: AbortSignal }) => { - const res = await fetch( - `https://api.nostr.band/v0/stats/profile/${ark.account.pubkey}`, - { - signal, - }, - ); - - if (!res.ok) { - throw new Error("Error"); - } - - return await res.json(); - }, - refetchOnWindowFocus: false, - refetchOnMount: false, - refetchOnReconnect: false, - staleTime: Infinity, - }); - - return ( -
- {status === "pending" ? ( -
- -
- ) : ( -
-

- {compactNumber.format( - data.stats[ark.account.pubkey].pub_note_count, - )} -

-
-

- Posts -

- - View - -
-
- )} -
- ); -} diff --git a/apps/desktop/src/routes/settings/components/profileCard.tsx b/apps/desktop/src/routes/settings/components/profileCard.tsx deleted file mode 100644 index 7b949df4..00000000 --- a/apps/desktop/src/routes/settings/components/profileCard.tsx +++ /dev/null @@ -1,77 +0,0 @@ -import { useArk, useProfile } from "@lume/ark"; -import { EditIcon, LoaderIcon } from "@lume/icons"; -import { displayNpub } from "@lume/utils"; -import * as Avatar from "@radix-ui/react-avatar"; -import { writeText } from "@tauri-apps/plugin-clipboard-manager"; -import { minidenticon } from "minidenticons"; -import { nip19 } from "nostr-tools"; -import { Link } from "react-router-dom"; - -export function ProfileCard() { - const ark = useArk(); - const svgURI = `data:image/svg+xml;utf8,${encodeURIComponent( - minidenticon(ark.account.pubkey, 90, 50), - )}`; - - const { isLoading, user } = useProfile(ark.account.pubkey); - - const copyNpub = async () => { - return await writeText(nip19.npubEncode(ark.account.pubkey)); - }; - - return ( -
- {isLoading ? ( -
- -
- ) : ( -
-
- - - - Edit - -
-
- - - - {ark.account.pubkey} - - -
-

- {user?.display_name || user?.name} -

-

- {user?.nip05 || displayNpub(ark.account.pubkey, 16)} -

-
-
-
- )} -
- ); -} diff --git a/apps/desktop/src/routes/settings/components/relayCard.tsx b/apps/desktop/src/routes/settings/components/relayCard.tsx deleted file mode 100644 index c170a2cc..00000000 --- a/apps/desktop/src/routes/settings/components/relayCard.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { useArk } from "@lume/ark"; -import { EditIcon, LoaderIcon } from "@lume/icons"; -import { compactNumber } from "@lume/utils"; -import { useQuery } from "@tanstack/react-query"; -import { Link } from "react-router-dom"; - -export function RelayCard() { - const ark = useArk(); - - const { status, data } = useQuery({ - queryKey: ["relays", ark.account.pubkey], - queryFn: async () => { - const relays = await ark.getUserRelays({}); - return relays; - }, - refetchOnWindowFocus: false, - }); - - return ( -
- {status === "pending" ? ( -
- -
- ) : ( -
-

- {compactNumber.format(data?.relays?.length || 0)} -

-
-

- Relays -

- - - Edit - -
-
- )} -
- ); -} diff --git a/apps/desktop/src/routes/settings/components/walletConnectForm.tsx b/apps/desktop/src/routes/settings/components/walletConnectForm.tsx deleted file mode 100644 index 6553b72f..00000000 --- a/apps/desktop/src/routes/settings/components/walletConnectForm.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import { useArk } from "@lume/ark"; -import { LoaderIcon } from "@lume/icons"; -import { useStorage } from "@lume/storage"; -import { useState } from "react"; -import { toast } from "sonner"; - -export function NWCForm({ setWalletConnectURL }) { - const ark = useArk(); - const storage = useStorage(); - - const [uri, setUri] = useState(""); - const [loading, setLoading] = useState(false); - - const submit = async () => { - try { - setLoading(true); - - if (!uri.startsWith("nostr+walletconnect:")) { - toast.error( - "Connect URI is required and must start with format nostr+walletconnect:, please check again", - ); - setLoading(false); - return; - } - - const uriObj = new URL(uri); - const params = new URLSearchParams(uriObj.search); - - if (params.has("relay") && params.has("secret")) { - await storage.createPrivkey(`${ark.account.pubkey}-nwc`, uri); - setWalletConnectURL(uri); - setLoading(false); - } else { - setLoading(false); - toast.error("Connect URI is not valid, please check again"); - return; - } - } catch (e) { - setLoading(false); - toast.error(String(e)); - } - }; - - return ( -
-