From 2e4f3b81402a17483eeb754bc21a8bb048c3836d Mon Sep 17 00:00:00 2001 From: ppc Date: Sat, 10 Aug 2024 13:39:22 +0100 Subject: [PATCH] abstract card design to component, fix text truncation --- aimenet-web/src/components/aime-card.tsx | 42 ++++++++--------- aimenet-web/src/components/am-card.tsx | 40 ++++++++++++++++ .../components/{footer.tsx => am-footer.tsx} | 2 +- aimenet-web/src/pages/card-in-screen.tsx | 27 ++++------- aimenet-web/src/pages/card-manager.tsx | 4 +- aimenet-web/src/pages/server-listing.tsx | 46 ++++++++----------- 6 files changed, 90 insertions(+), 71 deletions(-) create mode 100644 aimenet-web/src/components/am-card.tsx rename aimenet-web/src/components/{footer.tsx => am-footer.tsx} (83%) diff --git a/aimenet-web/src/components/aime-card.tsx b/aimenet-web/src/components/aime-card.tsx index 2c5f423..7a9b442 100644 --- a/aimenet-web/src/components/aime-card.tsx +++ b/aimenet-web/src/components/aime-card.tsx @@ -3,29 +3,27 @@ import TimeAgo from "react-timeago"; import {CreditCard, History} from "lucide-react"; import {AimeCard} from "@/lib/database"; -import {Card} from "@/components/ui/card"; +import {useMediaQuery} from "@/hooks/use-media-query.tsx"; +import {AMCard, AMCardActionProps, AMCardDetail} from "@/components/am-card.tsx"; + +export function AimeCardEntry(props: AMCardActionProps & { card: AimeCard, children?: Readonly }) { + const isDesktop = useMediaQuery("(min-width: 512px)"); -export function AimeCardEntry(props: { card: AimeCard, children?: Readonly }) { return ( - -
-
-

{props.card.name}

-
- {props.card.lastUsed > 0 && ( -
- - -
- )} -
- - {props.card.id.match(/.{1,4}/g)?.join(" ")} -
-
-
- {props.children} -
-
+ + {props.card.lastUsed > 0 && ( + + + + + )} + + + {isDesktop + ? props.card.id.match(/.{1,4}/g)?.join(" ") + : `•••• ${props.card.id.substring(props.card.id.length - 4)}`} + + + ); } \ No newline at end of file diff --git a/aimenet-web/src/components/am-card.tsx b/aimenet-web/src/components/am-card.tsx new file mode 100644 index 0000000..0d33253 --- /dev/null +++ b/aimenet-web/src/components/am-card.tsx @@ -0,0 +1,40 @@ +import React from "react"; +import {ChevronRight} from "lucide-react"; +import {Card} from "@/components/ui/card.tsx"; +import {Button} from "@/components/ui/button.tsx"; + +export interface AMCardActionProps { + actionIcon?: Readonly, + actionClicked?: () => void, + actionDisabled?: boolean, +} + +export function AMCard(props: AMCardActionProps & { title: string, children: Readonly }) { + return ( + +
+
+

+ {props.title} +

+
+ {props.children} +
+
+ {props.actionClicked && ( + + )} +
+
+ ) +} + +export function AMCardDetail(props: { children?: Readonly }) { + return ( +
+ {props.children} +
+ ) +} \ No newline at end of file diff --git a/aimenet-web/src/components/footer.tsx b/aimenet-web/src/components/am-footer.tsx similarity index 83% rename from aimenet-web/src/components/footer.tsx rename to aimenet-web/src/components/am-footer.tsx index b39dded..e868556 100644 --- a/aimenet-web/src/components/footer.tsx +++ b/aimenet-web/src/components/am-footer.tsx @@ -1,4 +1,4 @@ -export function Footer() { +export function AMFooter() { return (
AimeNet © ppc {new Date().getUTCFullYear()}
); diff --git a/aimenet-web/src/pages/card-in-screen.tsx b/aimenet-web/src/pages/card-in-screen.tsx index 537892b..110af95 100644 --- a/aimenet-web/src/pages/card-in-screen.tsx +++ b/aimenet-web/src/pages/card-in-screen.tsx @@ -6,12 +6,11 @@ import {ChevronRight, Circle, CircleCheckBig, Home, Plus, ServerOff, Wallet} fro import {AimeCard, AimeServer, db} from "@/lib/database"; import {getServerInfo, serverCardIn} from "@/lib/aime-net"; -import {Footer} from "@/components/footer"; +import {AMFooter} from "@/components/am-footer.tsx"; import {Button} from "@/components/ui/button"; import {useToast} from "@/components/ui/use-toast"; import {Separator} from "@/components/ui/separator"; import {Alert, AlertDescription, AlertTitle} from "@/components/ui/alert"; -import {Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from "@/components/ui/tooltip"; import {AimeCardEntry} from "@/components/aime-card"; import {LoadingIndicator} from "@/components/loading-indicator"; @@ -43,6 +42,7 @@ async function performCardInAction(card: AimeCard, server: AimeServer, setCardIn setTimeout(() => setCardInStatus(false), 1000); } } + /* eslint-enable @typescript-eslint/no-explicit-any */ function CardList(props: { cards: ReadonlyArray | null, cardSelected: (card: AimeCard) => void }) { @@ -62,27 +62,18 @@ function CardList(props: { cards: ReadonlyArray | null, cardSelected: - {props.cards?.length ? props.cards.map(x => - - - - - - -

Select Card

-
-
-
-
) : } + {!props.cards?.length + ? + : props.cards.map(x => } + actionClicked={() => props.cardSelected(x)}/>)} ); } function ServerCardInPage() { const {toast} = useToast(); const {serverId} = useParams<{ serverId: string }>(); - + const navigate = useNavigate(); const cards = useLiveQuery(() => db.cards.toArray()); @@ -182,7 +173,7 @@ function ServerCardInPage() { }}/> )} -