-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39cd94b
commit 758a89f
Showing
9 changed files
with
106 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/app/beanconqueror/share/create/components/share-card.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import QRCodeCard from "@/components/qrcode-card"; | ||
import {Card, CardContent, CardHeader, CardTitle} from "@/components/ui/card"; | ||
import CopyContainer from "@/components/copy-container"; | ||
|
||
const ShareCard = ({bcUrl, beanLinkUrl}: {bcUrl: string, beanLinkUrl: string}) => ( | ||
<Card className={"w-full"}> | ||
<CardHeader> | ||
<CardTitle>Share or import</CardTitle> | ||
</CardHeader> | ||
<CardContent> | ||
<div className={"flex flex-col space-y-2"}> | ||
<CopyContainer value={beanLinkUrl} /> | ||
<QRCodeCard value={bcUrl} /> | ||
</div> | ||
</CardContent> | ||
</Card> | ||
); | ||
|
||
export default ShareCard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/app/beanconqueror/share/create/util/beanlink-helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
interface BeanLinkResponse { | ||
link: string; | ||
error?: string | undefined, | ||
name: string; | ||
roaster?: string | null; | ||
} | ||
|
||
export async function getBeanLink(link: string): Promise<string> { | ||
const response = await fetch("https://beanl.ink/add", { | ||
method: "POST", | ||
body: JSON.stringify({"link": link}) | ||
}); | ||
const data: BeanLinkResponse = await response.json(); | ||
|
||
if (!!data.error) { | ||
throw new Error(data.error); | ||
} | ||
|
||
return data.link | ||
} | ||
|
||
export async function followBeanLink(link: string): Promise<string> { | ||
const response = await fetch(link); | ||
return response.url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use client" | ||
|
||
import {Button} from "@/components/ui/button"; | ||
import {Check, Copy, LucideIcon} from "lucide-react"; | ||
import {createElement, useState} from "react"; | ||
|
||
const CopyContainer = ({value}: {value: string}) => { | ||
const [icon, setIcon] = useState<LucideIcon>(Copy); | ||
|
||
const onClick = () => { | ||
const writeToClipboard = async () => { | ||
await navigator.clipboard.writeText(value); | ||
setIcon(Check); | ||
setTimeout(() => setIcon(Copy), 5000); | ||
} | ||
|
||
writeToClipboard(); | ||
} | ||
|
||
return ( | ||
<div className={"flex items-center justify-between rounded-lg border bg-card text-card-foreground shadow-sm"}> | ||
<div className={"text-sm p-2"}>{value}</div> | ||
<Button variant={"ghost"} onClick={onClick}> | ||
{createElement(icon)} | ||
</Button> | ||
</div> | ||
) | ||
} | ||
|
||
export default CopyContainer |