From 83a6d23c4a27cf9b856b1f8279896f284d73e8b6 Mon Sep 17 00:00:00 2001 From: reya <123083837+reyamir@users.noreply.github.com> Date: Mon, 5 Aug 2024 09:09:14 +0700 Subject: [PATCH] feat: add delete account --- src/routes/$account.chats.lazy.tsx | 12 ++++--- src/routes/index.lazy.tsx | 53 +++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/routes/$account.chats.lazy.tsx b/src/routes/$account.chats.lazy.tsx index 504d044..fc192d0 100644 --- a/src/routes/$account.chats.lazy.tsx +++ b/src/routes/$account.chats.lazy.tsx @@ -184,7 +184,7 @@ function ChatList() { to="/$account/chats/$id" params={{ account, id: item.pubkey }} > - {({ isActive }) => ( + {({ isActive, isTransitioning }) => ( - - {ago(item.created_at)} - + {isTransitioning ? ( + + ) : ( + + {ago(item.created_at)} + + )} diff --git a/src/routes/index.lazy.tsx b/src/routes/index.lazy.tsx index 358fbeb..f05e383 100644 --- a/src/routes/index.lazy.tsx +++ b/src/routes/index.lazy.tsx @@ -3,10 +3,17 @@ import { npub } from "@/commons"; import { Frame } from "@/components/frame"; import { Spinner } from "@/components/spinner"; import { User } from "@/components/user"; -import { ArrowRight, Plus, X } from "@phosphor-icons/react"; +import { ArrowRight, DotsThree, Plus } from "@phosphor-icons/react"; import { Link, createLazyFileRoute } from "@tanstack/react-router"; +import { Menu, MenuItem } from "@tauri-apps/api/menu"; import { message } from "@tauri-apps/plugin-dialog"; -import { useEffect, useMemo, useState, useTransition } from "react"; +import { + useCallback, + useEffect, + useMemo, + useState, + useTransition, +} from "react"; export const Route = createLazyFileRoute("/")({ component: Screen, @@ -31,11 +38,11 @@ function Screen() { const [password, setPassword] = useState(""); const [isPending, startTransition] = useTransition(); - const deleteAccount = async (npub: string) => { - const res = await commands.deleteAccount(npub); + const deleteAccount = async (account: string) => { + const res = await commands.deleteAccount(account); if (res.status === "ok") { - setAccounts((prev) => prev.filter((item) => item !== npub)); + setAccounts((prev) => prev.filter((item) => item !== account)); } }; @@ -69,6 +76,26 @@ function Screen() { }); }; + const showContextMenu = useCallback( + async (e: React.MouseEvent, account: string) => { + e.stopPropagation(); + + const menuItems = await Promise.all([ + MenuItem.new({ + text: "Delete account", + action: async () => await deleteAccount(account), + }), + ]); + + const menu = await Menu.new({ + items: menuItems, + }); + + await menu.popup().catch((e) => console.error(e)); + }, + [], + ); + useEffect(() => { setAccounts(context.accounts); }, [context.accounts]); @@ -126,17 +153,25 @@ function Screen() {
{value === account ? ( isPending ? ( - + ) : ( ) - ) : null} + ) : ( + + )}
))} @@ -149,7 +184,7 @@ function Screen() { - Add an account + New account