From 13d9fab6fe325d07c2408ecda7578382e75f3b5b Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Mon, 28 Oct 2024 17:07:43 +0530 Subject: [PATCH] chore: handle sharable links --- examples/buddybook/src/App.tsx | 5 --- .../src/components/Chain/SignChain.tsx | 11 ++++-- .../src/components/Chain/View/ChainList.tsx | 18 ++++------ examples/buddybook/src/components/QRCode.tsx | 35 ++++++++++++++++--- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/examples/buddybook/src/App.tsx b/examples/buddybook/src/App.tsx index 497a472..3361086 100644 --- a/examples/buddybook/src/App.tsx +++ b/examples/buddybook/src/App.tsx @@ -41,13 +41,8 @@ function App() { useEffect(() => { if (isWakuLoading || !node || node.libp2p.getConnections().length === 0 || chainsData.length > 0 || isListening) return; - - setTimeout(() => { setIsListening(true); startMessageListening(); - }, 3000); - - }, [node, isWakuLoading, wakuStatus]) const handleTelemetryOptIn = (optIn: boolean) => { diff --git a/examples/buddybook/src/components/Chain/SignChain.tsx b/examples/buddybook/src/components/Chain/SignChain.tsx index 49f1c98..a018fbd 100644 --- a/examples/buddybook/src/components/Chain/SignChain.tsx +++ b/examples/buddybook/src/components/Chain/SignChain.tsx @@ -124,7 +124,7 @@ const SignChain: React.FC = ({ block, chainsData, onSuccess }) = {alreadySigned ? 'Already Signed' : 'Sign Chain'} - + Sign Chain @@ -133,7 +133,14 @@ const SignChain: React.FC = ({ block, chainsData, onSuccess }) = : 'Review the block details and sign to add your signature to the chain.'} - +
+
+

Block Details

+

{block.title}

+

{block.description}

+
+ +
{error &&

{error}

} diff --git a/examples/buddybook/src/components/Chain/View/ChainList.tsx b/examples/buddybook/src/components/Chain/View/ChainList.tsx index c896d72..cf1bfca 100644 --- a/examples/buddybook/src/components/Chain/View/ChainList.tsx +++ b/examples/buddybook/src/components/Chain/View/ChainList.tsx @@ -4,7 +4,7 @@ import { type BlockPayload } from '@/lib/waku'; import SignChain from '@/components/Chain/SignChain'; import { useEnsName } from 'wagmi'; import { Button } from '@/components/ui/button'; -import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger, DialogDescription } from "@/components/ui/dialog"; import QRCode from '@/components/QRCode'; import { Loader2 } from "lucide-react"; @@ -23,7 +23,7 @@ const ChainList: React.FC = ({ chainsData, onChainUpdate, isLoad const childBlocks = chainsData.filter(b => b.parentBlockUUID === block.blockUUID); const totalSignatures = block.signatures.length + childBlocks.reduce((acc, child) => acc + child.signatures.length, 0); - const shareUrl = `${window.location.origin}/sign/${block.chainUUID ?? block.blockUUID}/${block.blockUUID}`; + const shareUrl = `${window.location.origin}/sign/${block.chainUUID}/${block.blockUUID}`; return (
  • @@ -62,17 +62,11 @@ const ChainList: React.FC = ({ chainsData, onChainUpdate, isLoad Share this Chain + + Share this chain with others to collect their signatures. + -
    - -

    {shareUrl}

    - -
    +
  • diff --git a/examples/buddybook/src/components/QRCode.tsx b/examples/buddybook/src/components/QRCode.tsx index a8b24c7..f25f948 100644 --- a/examples/buddybook/src/components/QRCode.tsx +++ b/examples/buddybook/src/components/QRCode.tsx @@ -1,16 +1,43 @@ -import React from 'react'; +import React, { useState } from 'react'; import { QRCodeSVG } from 'qrcode.react'; +import { Button } from "@/components/ui/button"; +import { Check, Copy } from "lucide-react"; interface QRCodeProps { - text: string; + data?: any; + text?: string; width?: number; height?: number; } -const QRCode: React.FC = ({ text, width = 256, height = 256 }) => { +const QRCode: React.FC = ({ data, text, width = 256, height = 256 }) => { + const [copied, setCopied] = useState(false); + const shareUrl = text || (data ? `${window.location.origin}/sign/${data.chainUUID}/${data.blockUUID}` : ''); + + const handleCopy = async () => { + await navigator.clipboard.writeText(shareUrl); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + }; + return (
    - + +
    + + +
    ); };