From e84176e940d6d7cac01f4b3fb01c4af78b557fcc Mon Sep 17 00:00:00 2001 From: ppc Date: Thu, 22 Aug 2024 08:22:01 +0100 Subject: [PATCH] add share button to page footer --- amnet-web/src/pages/card-in-screen.tsx | 84 +++++++++++++++++--------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/amnet-web/src/pages/card-in-screen.tsx b/amnet-web/src/pages/card-in-screen.tsx index 7251f83..35875c6 100644 --- a/amnet-web/src/pages/card-in-screen.tsx +++ b/amnet-web/src/pages/card-in-screen.tsx @@ -1,4 +1,4 @@ -import {useEffect, useState} from "react"; +import {useEffect, useMemo, useState} from "react"; import {useNavigate, useParams} from "react-router-dom"; import {useLiveQuery} from "dexie-react-hooks"; import {CircleDot, CircleCheckBig, Home, Nfc, Wallet, WifiOff} from "lucide-react"; @@ -28,6 +28,7 @@ import {LoadingIndicator} from "@/components/loading-indicator"; import {CardCreationDialog} from "@/components/card-creation-form"; import {NoCardsNotification} from "@/components/no-cards-notification"; import {IncognitoStorageWarning} from "@/components/incognito-warning.tsx"; +import {Separator} from "@/components/ui/separator.tsx"; /* eslint-disable @typescript-eslint/no-explicit-any */ @@ -87,11 +88,15 @@ function ServerCardInPage() { const cards = useLiveQuery(() => db.cards.toArray()); const [server, setServer] = useState(null); - const [cardInStatus, setCardInStatus] = useState(false); - const [connectionError, setConnectionError] = useState(false); - const [selectedCard, setSelectedCard] = useState(null); const [serverReloadCounter, setServerReloadCounter] = useState(0); + const [cardInStatus, setCardInStatus] = useState(false); + const [selectedCard, setSelectedCard] = useState(null); + + const [connectionError, setConnectionError] = useState(false); + + const shareUrl = useMemo(() => `${location.origin}/#/servers/add?address=${encodeURIComponent(server?.address ?? "")}`, [server]); + // select newest card useEffect(() => setSelectedCard(cards?.sort((a, b) => b.lastUsed - a.lastUsed)[0] ?? null), [cards]); useEffect(() => { @@ -147,7 +152,8 @@ function ServerCardInPage() { There was an issue connecting to {server.address}. - Please check the game is running and setServerReloadCounter(serverReloadCounter + 1)}>try again. + Please check the game is running and setServerReloadCounter(serverReloadCounter + 1)}>try again. : } @@ -183,31 +189,51 @@ function ServerCardInPage() { )} - + {server?.id && ( - - -

Delete {server.serverName}

-
- - - Confirm Deletion - - You'll need to re-enter the server information if you want to use it in the - future... - - - - Cancel - { - await db.servers.delete(server.id); - navigate('/'); - }}> - Continue - - - -
+
+ {location.protocol === "https:" ? ( +

navigator.share({url: shareUrl})}> + Share +

+ ) : ( +

navigator.clipboard.writeText(shareUrl).then(() => { + toast({ + description: "Server URL has been copied to clipboard.", + duration: 2500 + }) + })}> + Copy URL +

+ )} + + + +

Delete {server.serverName}

+
+ + + Confirm Deletion + + You'll need to re-enter the server information if you want to use it in the + future... + + + + Cancel + { + await db.servers.delete(server.id); + navigate('/'); + }}> + Continue + + + +
+
)}