Skip to content

Commit b657ef9

Browse files
committed
moved share to dialog 'ui
1 parent 2623635 commit b657ef9

4 files changed

Lines changed: 135 additions & 3 deletions

File tree

‎frontend/src/feature/quote/dialog/add-edit.quote.dialog.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @not in use
12
import {
23
Dialog,
34
DialogContent,
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
2+
import {
3+
Dialog,
4+
DialogContent,
5+
DialogDescription,
6+
DialogFooter,
7+
DialogHeader,
8+
DialogTitle,
9+
DialogTrigger,
10+
} from "@/components/ui/dialog"
11+
import { useRef, useState } from "react";
12+
import { Button } from "@/components/ui/button";
13+
import type { QuoteFormData } from "@/model/quote.model";
14+
import { ArrowLeftIcon, CircleArrowDown, LoaderCircle, Save, Share } from "lucide-react";
15+
import useBackground, { type Pri_set, type TextureKey } from "@/hook/use-background.hook";
16+
import { sanitizeHTML } from "@/helper/sanitize-html";
17+
import { cn } from "@/lib/utils";
18+
import { ListTags } from "@/feature/quote/list.tags";
19+
import { toPng } from "html-to-image"
20+
21+
interface Props {
22+
quoteFormData: QuoteFormData
23+
}
24+
25+
export function ShareBackground(props: Props) {
26+
const { quoteFormData } = props
27+
const { buildStyle } = useBackground()
28+
const noteRef = useRef<HTMLDivElement>(null)
29+
const [downloading, setDownloading] = useState(false)
30+
const cardStyle = buildStyle(quoteFormData.texture!, quoteFormData.pri_set!)
31+
32+
const exportAsImage = async () => {
33+
if (!noteRef.current) return
34+
setDownloading(true)
35+
const dataUrl = await toPng(noteRef.current, {
36+
pixelRatio: 2, // crisp image
37+
//backgroundColor: "#fff"
38+
cacheBust: true,
39+
backgroundColor: cardStyle.backgroundColor
40+
})
41+
42+
const link = document.createElement("a")
43+
link.download = "note-by-pri-" + new Date().getTime() + "-.png"
44+
link.href = dataUrl
45+
link.click()
46+
setTimeout(() => {
47+
setDownloading(false)
48+
}, 500);
49+
}
50+
51+
return (
52+
<Dialog >
53+
<DialogTrigger asChild>
54+
<Button variant="outline" size="icon">
55+
<Share />
56+
</Button>
57+
</DialogTrigger>
58+
59+
<DialogContent className="p-4" aria-describedby="Choose Background">
60+
<DialogHeader>
61+
<DialogTitle>Share</DialogTitle>
62+
<DialogDescription>
63+
Share it with your close one.
64+
</DialogDescription>
65+
</DialogHeader>
66+
<div className="flex flex-col gap-4">
67+
68+
{/* Live preview */}
69+
<div className="w-full rounded-lg bg-transparent overflow-auto max-h-[65dvh]"
70+
ref={noteRef}
71+
>
72+
<div
73+
style={cardStyle}
74+
className={
75+
cn(
76+
"border p-2 bg-card rounded-xl ",
77+
"flex flex-col justify-between items-start gap-2",
78+
"",
79+
)
80+
81+
}>
82+
<div className="
83+
tiptap
84+
prose-sm
85+
removed-prose
86+
removed-sm:prose-base
87+
removed-lg:prose-lg
88+
removed-xl:prose-2xl
89+
removed-prose-foreground
90+
"> {/* IMPORTANT */}
91+
<div dangerouslySetInnerHTML={{ __html: sanitizeHTML(quoteFormData.text!) }}></div>
92+
</div>
93+
<div className="flex w-full items-end justify-between gap-2">
94+
<ListTags tags={quoteFormData?.tags?.map((tag, i) => { return { id: i, name: tag } }) || []} />
95+
96+
</div>
97+
</div>
98+
</div>
99+
100+
{/* Action */}
101+
102+
<div className="flex items-center justify-between gap-4 ">
103+
104+
<div className="flex flex-col gap-4">
105+
<Button
106+
className=""
107+
variant={"outline"}
108+
onClick={(e) => {
109+
e.preventDefault()
110+
exportAsImage()
111+
}}
112+
aria-label="Download quote"
113+
size={"lg"}
114+
>
115+
{downloading ? <LoaderCircle className="animate-spin" /> : <CircleArrowDown />}
116+
</Button>
117+
<p className="text-xs">
118+
{downloading ? "Downloading" : "Download"}
119+
</p>
120+
</div>
121+
122+
</div>
123+
</div>
124+
125+
</DialogContent>
126+
</Dialog>
127+
);
128+
}

‎frontend/src/feature/quote/drawer/share.drawer.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @not in use
12
import {
23
Drawer,
34
DrawerTitle,
@@ -88,9 +89,10 @@ export default function ShareBackground(props: Props) {
8889
</div>
8990

9091
{/* Live preview */}
91-
<div className="w-full border rounded-lg overflow-hidden shadow">
92+
<div className="w-full rounded-lg bg-transparent overflow-auto max-h-[70dvh]"
93+
ref={noteRef}
94+
>
9295
<div
93-
ref={noteRef}
9496
style={cardStyle}
9597
className={
9698
cn(

‎frontend/src/page/quote/quote.page.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { getAllQuotes, addQuote, updateQuote, deleteQuote, getAllQuote } from '@
1818
import { addOrGetTag } from '@/db/tag.db'
1919
import { useBlocker } from "@tanstack/react-router"
2020
import ChooseBackground from "@/feature/quote/drawer/choose-background.drawer"
21-
import ShareBackground from "@/feature/quote/drawer/share.drawer"
21+
import {ShareBackground } from "@/feature/quote/dialog/share.dialog"
22+
2223
import { toPng } from "html-to-image"
2324
import { ListTags } from "@/feature/quote/list.tags";
2425

0 commit comments

Comments
 (0)