From 587fd7301b79f0295433670df58cda92b5ad7baa Mon Sep 17 00:00:00 2001 From: reya <123083837+reyamir@users.noreply.github.com> Date: Sun, 4 Aug 2024 10:23:15 +0700 Subject: [PATCH] feat: improve some functions --- src-tauri/src/commands/account.rs | 11 ++++++- src-tauri/src/main.rs | 8 ++--- src/commands.ts | 8 +++++ src/routes/$account.chats.$id.lazy.tsx | 10 ++++-- src/routes/$account.chats.lazy.tsx | 44 ++++++++++++++------------ src/routes/index.lazy.tsx | 33 ++++++++++++++++--- 6 files changed, 79 insertions(+), 35 deletions(-) diff --git a/src-tauri/src/commands/account.rs b/src-tauri/src/commands/account.rs index 9fc9fab..16e857c 100644 --- a/src-tauri/src/commands/account.rs +++ b/src-tauri/src/commands/account.rs @@ -45,6 +45,15 @@ pub async fn get_metadata(id: String, state: State<'_, Nostr>) -> Result Result<(), String> { + let keyring = Entry::new("coop", &id).map_err(|e| e.to_string())?; + let _ = keyring.delete_credential(); + + Ok(()) +} + #[tauri::command] #[specta::specta] pub async fn create_account( @@ -258,7 +267,7 @@ pub async fn login( .get_events_from( urls.clone(), vec![Filter::new().kind(Kind::TextNote).limit(0)], - None, + Some(Duration::from_secs(5)), ) .await; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 146783d..774fa72 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -19,17 +19,13 @@ pub struct Nostr { } // TODO: Allow user config bootstrap relays. -pub const BOOTSTRAP_RELAYS: [&str; 4] = [ - "wss://relay.damus.io/", - "wss://relay.nostr.net/", - "wss://relay.0xchat.com/", - "wss://auth.nostr1.com/", -]; +pub const BOOTSTRAP_RELAYS: [&str; 2] = ["wss://relay.damus.io/", "wss://relay.nostr.net/"]; fn main() { let invoke_handler = { let builder = tauri_specta::ts::builder().commands(tauri_specta::collect_commands![ login, + delete_account, create_account, import_key, connect_account, diff --git a/src/commands.ts b/src/commands.ts index 59d04c1..5acc5ea 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -12,6 +12,14 @@ try { else return { status: "error", error: e as any }; } }, +async deleteAccount(id: string) : Promise> { +try { + return { status: "ok", data: await TAURI_INVOKE("delete_account", { id }) }; +} catch (e) { + if(e instanceof Error) throw e; + else return { status: "error", error: e as any }; +} +}, async createAccount(name: string, picture: string | null) : Promise> { try { return { status: "ok", data: await TAURI_INVOKE("create_account", { name, picture }) }; diff --git a/src/routes/$account.chats.$id.lazy.tsx b/src/routes/$account.chats.$id.lazy.tsx index 8a766a1..d947487 100644 --- a/src/routes/$account.chats.$id.lazy.tsx +++ b/src/routes/$account.chats.$id.lazy.tsx @@ -2,7 +2,8 @@ import { commands } from "@/commands"; import { cn, getReceivers, groupEventByDate, time } from "@/commons"; import { Spinner } from "@/components/spinner"; import { User } from "@/components/user"; -import { ArrowUp } from "@phosphor-icons/react"; +import { CoopIcon } from "@/icons/coop"; +import { ArrowUp, Paperclip } from "@phosphor-icons/react"; import * as ScrollArea from "@radix-ui/react-scroll-area"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import { createLazyFileRoute } from "@tanstack/react-router"; @@ -233,6 +234,9 @@ function List() { -1.5; }} > +
+ +
{isLoading ? ( <>
@@ -313,12 +317,12 @@ function Form() { ) : (
- {/*
-
*/} +
- {isLoading || !isSync ? ( + {isLoading ? ( <> {[...Array(5).keys()].map((i) => (
- {!isSync ? ( -
-
- - - - Syncing message... -
-
- ) : null} + {!isSync && !data ? : null} +
+ + + + Syncing message... +
+
+ ); +} + function Compose() { const [isOpen, setIsOpen] = useState(false); const [target, setTarget] = useState(""); diff --git a/src/routes/index.lazy.tsx b/src/routes/index.lazy.tsx index 6b4ce51..1273632 100644 --- a/src/routes/index.lazy.tsx +++ b/src/routes/index.lazy.tsx @@ -3,9 +3,9 @@ import { npub } from "@/commons"; import { Frame } from "@/components/frame"; import { Spinner } from "@/components/spinner"; import { User } from "@/components/user"; -import { Plus } from "@phosphor-icons/react"; +import { Plus, X } from "@phosphor-icons/react"; import { Link, createLazyFileRoute } from "@tanstack/react-router"; -import { useMemo, useState, useTransition } from "react"; +import { useEffect, useMemo, useState, useTransition } from "react"; export const Route = createLazyFileRoute("/")({ component: Screen, @@ -25,9 +25,18 @@ function Screen() { [], ); + const [accounts, setAccounts] = useState([]); const [value, setValue] = useState(""); const [isPending, startTransition] = useTransition(); + const deleteAccount = async (npub: string) => { + const res = await commands.deleteAccount(npub); + + if (res.status === "ok") { + setAccounts((prev) => prev.filter((item) => item !== npub)); + } + }; + const loginWith = async (npub: string) => { setValue(npub); startTransition(async () => { @@ -51,6 +60,10 @@ function Screen() { }); }; + useEffect(() => { + setAccounts(context.accounts); + }, [context.accounts]); + return (
- {context.accounts.map((account) => ( + {accounts.map((account) => (
loginWith(account)} onKeyDown={() => loginWith(account)} - className="flex items-center justify-between hover:bg-black/5 dark:hover:bg-white/5" + className="group flex items-center justify-between hover:bg-black/5 dark:hover:bg-white/5" > @@ -86,7 +99,17 @@ function Screen() {
- {value === account && isPending ? : null} + {value === account && isPending ? ( + + ) : ( + + )}
))}