From c29b4e173e77ea954d2e4c6e241b2ae813a7ed98 Mon Sep 17 00:00:00 2001 From: reya Date: Wed, 17 Jan 2024 08:50:43 +0700 Subject: [PATCH] feat: polish --- apps/desktop/src/routes/auth/create.tsx | 72 +++++++++++-------- apps/desktop/src/routes/auth/login.tsx | 4 +- apps/desktop/src/routes/settings/profile.tsx | 4 +- packages/ark/src/ark.ts | 6 +- packages/ui/src/avatarUploadButton.tsx | 5 +- packages/ui/src/layouts/auth.tsx | 5 +- packages/ui/src/onboarding/finish.tsx | 5 -- .../ui/src/onboarding/profileSettings.tsx | 8 +++ 8 files changed, 60 insertions(+), 49 deletions(-) diff --git a/apps/desktop/src/routes/auth/create.tsx b/apps/desktop/src/routes/auth/create.tsx index 8cb8caa1..f51616a7 100644 --- a/apps/desktop/src/routes/auth/create.tsx +++ b/apps/desktop/src/routes/auth/create.tsx @@ -9,11 +9,12 @@ import NDK, { NDKPrivateKeySigner, } from "@nostr-dev-kit/ndk"; import * as Select from "@radix-ui/react-select"; -import { downloadDir } from "@tauri-apps/api/path"; +import { desktopDir } from "@tauri-apps/api/path"; import { Window } from "@tauri-apps/api/window"; import { save } from "@tauri-apps/plugin-dialog"; import { writeTextFile } from "@tauri-apps/plugin-fs"; import { useSetAtom } from "jotai"; +import { nanoid } from "nanoid"; import { getPublicKey, nip19 } from "nostr-tools"; import { useState } from "react"; import { useForm } from "react-hook-form"; @@ -66,18 +67,20 @@ export function CreateAccountScreen() { ark.updateNostrSigner({ signer }); - const downloadPath = await downloadDir(); - const fileName = `nostr_keys_${new Date().getTime().toString(36)}.txt`; + const downloadPath = await desktopDir(); + const fileName = `nostr_keys_${nanoid(4)}.txt`; const filePath = await save({ defaultPath: `${downloadPath}/${fileName}`, }); - if (filePath) { - await writeTextFile( - filePath, - `Nostr account, generated by Lume (lume.nu)\nPublic key: ${npub}\nPrivate key: ${nsec}`, - ); - } // else { user cancel action } + if (!filePath) { + return toast.info("You need to save account keys before continue."); + } + + await writeTextFile( + filePath, + `Nostr Account\nGenerated by Lume (lume.nu)\n---\nPublic key: ${npub}\nPrivate key: ${nsec}`, + ); await storage.createAccount({ pubkey: pubkey, @@ -180,8 +183,8 @@ export function CreateAccountScreen() { Let's get you set up on Nostr.

- With an account on Nostr, you'll be able to travel across all nostr - clients, all your data are synced. + Get started with familiar way, but all data belong to you and you + have ability controls everything.

{!services ? ( @@ -221,7 +224,7 @@ export function CreateAccountScreen() { - + @@ -254,28 +257,35 @@ export function CreateAccountScreen() { /> - +
+ +
-
-
-
-
-
- - Or - +
+
+
+
+
+
+ + Or + +
+ + More compatible with other Nostr clients +
diff --git a/apps/desktop/src/routes/settings/profile.tsx b/apps/desktop/src/routes/settings/profile.tsx index 99e48ed4..82b31d10 100644 --- a/apps/desktop/src/routes/settings/profile.tsx +++ b/apps/desktop/src/routes/settings/profile.tsx @@ -88,8 +88,8 @@ export function ProfileSettingScreen() { if (publish) { // invalid cache await storage.clearProfileCache(ark.account.pubkey); - await queryClient.invalidateQueries({ - queryKey: ["user", ark.account.pubkey], + await queryClient.setQueryData(["user", ark.account.pubkey], () => { + return content; }); // reset state diff --git a/packages/ark/src/ark.ts b/packages/ark/src/ark.ts index 5148b854..f256426f 100644 --- a/packages/ark/src/ark.ts +++ b/packages/ark/src/ark.ts @@ -105,7 +105,11 @@ export class Ark { public getCleanPubkey(pubkey: string) { try { - let hexstring = pubkey.replace("nostr:", "").split("'")[0].split(".")[0]; + let hexstring = pubkey + .replace("nostr:", "") + .split("'")[0] + .split(".")[0] + .split("?")[0]; if ( hexstring.startsWith("npub1") || diff --git a/packages/ui/src/avatarUploadButton.tsx b/packages/ui/src/avatarUploadButton.tsx index 2b3fc738..7bd71346 100644 --- a/packages/ui/src/avatarUploadButton.tsx +++ b/packages/ui/src/avatarUploadButton.tsx @@ -17,13 +17,10 @@ export function AvatarUploadButton({ setLoading(true); const image = await ark.upload({ fileExts: [] }); - if (image) { setPicture(image); setLoading(false); } - - return; } catch (e) { setLoading(false); toast.error(e); @@ -34,7 +31,7 @@ export function AvatarUploadButton({
diff --git a/packages/ui/src/onboarding/finish.tsx b/packages/ui/src/onboarding/finish.tsx index dd613f10..8d505373 100644 --- a/packages/ui/src/onboarding/finish.tsx +++ b/packages/ui/src/onboarding/finish.tsx @@ -7,7 +7,6 @@ import { useSetAtom } from "jotai"; import { useState } from "react"; export function OnboardingFinishScreen() { - const ark = useArk(); const queryClient = useQueryClient(); const setOnboarding = useSetAtom(onboardingAtom); @@ -19,10 +18,6 @@ export function OnboardingFinishScreen() { const queryCache = queryClient.getQueryCache(); const queryKeys = queryCache.getAll().map((cache) => cache.queryKey); - await queryClient.refetchQueries({ - queryKey: ["user", ark.account.pubkey], - }); - for (const key of queryKeys) { await queryClient.refetchQueries({ queryKey: key }); } diff --git a/packages/ui/src/onboarding/profileSettings.tsx b/packages/ui/src/onboarding/profileSettings.tsx index 1ec9b659..7cc4322a 100644 --- a/packages/ui/src/onboarding/profileSettings.tsx +++ b/packages/ui/src/onboarding/profileSettings.tsx @@ -2,6 +2,7 @@ import { useArk } from "@lume/ark"; import { ArrowLeftIcon, LoaderIcon } from "@lume/icons"; import { useStorage } from "@lume/storage"; import { NDKKind, NDKUserProfile } from "@nostr-dev-kit/ndk"; +import { useQueryClient } from "@tanstack/react-query"; import { motion } from "framer-motion"; import { minidenticon } from "minidenticons"; import { useState } from "react"; @@ -16,6 +17,7 @@ export function OnboardingProfileSettingsScreen() { const ark = useArk(); const storage = useStorage(); + const queryClient = useQueryClient(); const navigate = useNavigate(); const { register, handleSubmit } = useForm(); @@ -52,6 +54,12 @@ export function OnboardingProfileSettingsScreen() { }); if (publish) { + // invalid cache + await storage.clearProfileCache(ark.account.pubkey); + await queryClient.setQueryData(["user", ark.account.pubkey], () => { + return profile; + }); + setLoading(false); navigate("/follow"); }