From 47835ed85700295e86558f1af6310f52d08db22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E5=AE=AE=E8=93=AE?= <123083837+reyamir@users.noreply.github.com> Date: Thu, 16 May 2024 14:13:07 +0700 Subject: [PATCH] feat: improve ui for multi-account (#188) --- apps/desktop2/src/routes/$account.tsx | 117 ++++++++++++++++++++------ apps/desktop2/src/routes/index.tsx | 8 +- 2 files changed, 97 insertions(+), 28 deletions(-) diff --git a/apps/desktop2/src/routes/$account.tsx b/apps/desktop2/src/routes/$account.tsx index f1c034f9..930cacdf 100644 --- a/apps/desktop2/src/routes/$account.tsx +++ b/apps/desktop2/src/routes/$account.tsx @@ -1,4 +1,10 @@ -import { BellIcon, ComposeFilledIcon, PlusIcon, SearchIcon } from "@lume/icons"; +import { + BellIcon, + ComposeFilledIcon, + HorizontalDotsIcon, + PlusIcon, + SearchIcon, +} from "@lume/icons"; import { Event, Kind } from "@lume/types"; import { User } from "@/components/user"; import { @@ -10,8 +16,9 @@ import { import { Outlet, createFileRoute } from "@tanstack/react-router"; import { invoke } from "@tauri-apps/api/core"; import { getCurrent } from "@tauri-apps/api/window"; -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { toast } from "sonner"; +import * as Popover from "@radix-ui/react-popover"; export const Route = createFileRoute("/$account")({ beforeLoad: async ({ context }) => { @@ -40,8 +47,8 @@ function Screen() { @@ -74,10 +81,25 @@ function Screen() { } function Accounts() { - const navigate = Route.useNavigate(); const { ark, accounts } = Route.useRouteContext(); const { account } = Route.useParams(); + const [windowWidth, setWindowWidth] = useState(null); + + const navigate = Route.useNavigate(); + const sortedList = useMemo(() => { + const list = accounts; + + for (const [i, item] of list.entries()) { + if (item === account) { + list.splice(i, 1); + list.unshift(item); + } + } + + return list; + }, [accounts]); + const changeAccount = async (npub: string) => { if (npub === account) { return await ark.open_profile(account); @@ -93,29 +115,76 @@ function Accounts() { } }; + const getWindowDimensions = () => { + const { innerWidth: width, innerHeight: height } = window; + return { + width, + height, + }; + }; + + useEffect(() => { + function handleResize() { + setWindowWidth(getWindowDimensions().width); + } + + if (!windowWidth) setWindowWidth(getWindowDimensions().width); + window.addEventListener("resize", handleResize); + + return () => window.removeEventListener("resize", handleResize); + }, []); + return (
- {accounts.map((user) => ( - - ))} + > + + + + + ))} + {accounts.length >= 3 && windowWidth <= 700 ? ( + + + + + + + {sortedList.slice(2).map((user) => ( + + ))} + + + + + ) : null}
); } diff --git a/apps/desktop2/src/routes/index.tsx b/apps/desktop2/src/routes/index.tsx index 45117877..a312e91c 100644 --- a/apps/desktop2/src/routes/index.tsx +++ b/apps/desktop2/src/routes/index.tsx @@ -18,7 +18,7 @@ export const Route = createFileRoute("/")({ if (!accounts.length) { throw redirect({ - to: "/landing", + to: "/landing/", replace: true, }); } @@ -68,7 +68,7 @@ function Screen() {

{currentDate}

Welcome back!

-
+
{loading ? (
@@ -89,10 +89,10 @@ function Screen() { ))} - +
- +

Add