Skip to content

Commit 4c09ba1

Browse files
committed
Display tags or created at or updated at based on user
1 parent eb7a428 commit 4c09ba1

9 files changed

Lines changed: 191 additions & 89 deletions

File tree

‎frontend/src/feature/quote/card/quote.card.tsx‎

Lines changed: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import useBackground from "@/hook/use-background.hook";
66
import { cn } from "@/lib/utils";
77
import type { Quote, QuoteDetails } from "@/model/quote.model";
88
import { Link } from "@tanstack/react-router";
9-
import { Check, Copy, Maximize2, PenIcon, Trash , Save, CircleArrowDown, LoaderCircle } from "lucide-react";
9+
import { Check, Copy, Maximize2, PenIcon, Trash, Save, CircleArrowDown, LoaderCircle } from "lucide-react";
1010
import { useState, useRef } from "react";
1111
import { toPng } from "html-to-image"
12+
import { ListTags } from "@/feature/quote/list.tags";
13+
import { useShowCardInfo } from "@/hook/use-show-card-info.hook";
1214

1315
interface Props {
1416
quote: QuoteDetails;
@@ -21,34 +23,46 @@ const QuoteCard = (props: Props) => {
2123
const [copying, setCopying] = useState(false)
2224
const [downloading, setDownloading] = useState(false)
2325
const { buildStyle } = useBackground()
24-
const noteRef = useRef<HTMLDivElement>(null)
26+
const { info: infoType, setInfo } = useShowCardInfo()
27+
28+
const noteRef = useRef<HTMLDivElement>(null)
2529

2630
const cardStyle = buildStyle(quote.texture!, quote.pri_set!)
27-
const exportAsImage = async () => {
28-
if (!noteRef.current) return
29-
setDownloading(true)
30-
const dataUrl = await toPng(noteRef.current, {
31-
pixelRatio: 2, // crisp image
32-
//backgroundColor: "#fff"
33-
cacheBust: true,
34-
backgroundColor: cardStyle.backgroundColor
35-
})
36-
37-
const link = document.createElement("a")
38-
link.download = new Date().getTime()+"-note.png"
39-
link.href = dataUrl
40-
link.click()
41-
42-
setDownloading(false)
31+
const exportAsImage = async () => {
32+
if (!noteRef.current) return
33+
setDownloading(true)
34+
const dataUrl = await toPng(noteRef.current, {
35+
pixelRatio: 2, // crisp image
36+
//backgroundColor: "#fff"
37+
cacheBust: true,
38+
backgroundColor: cardStyle.backgroundColor
39+
})
40+
41+
const link = document.createElement("a")
42+
link.download = new Date().getTime() + "-note.png"
43+
link.href = dataUrl
44+
link.click()
45+
46+
setDownloading(false)
47+
48+
}
49+
4350

44-
}
4551
const onCopy = async (text: string) => {
4652
setCopying(true)
4753
await window.navigator.clipboard.writeText(text)
48-
49-
setTimeout(()=>{
50-
setCopying(false)
51-
}, 3000)
54+
55+
setTimeout(() => {
56+
setCopying(false)
57+
}, 3000)
58+
}
59+
60+
const formatDate = (date: Date) => {
61+
return date.toLocaleDateString("en-US", {
62+
month: "long",
63+
day: "numeric",
64+
year: "numeric",
65+
})
5266
}
5367

5468
return (
@@ -60,63 +74,57 @@ setDownloading(true)
6074
}>
6175

6276
<div
63-
ref={noteRef}
77+
ref={noteRef}
6478
style={cardStyle}
65-
className={
66-
cn(
67-
"border p-2 bg-card rounded-xl ",
68-
"flex flex-col justify-between items-start gap-2",
69-
"",
70-
)
71-
72-
}>
73-
<div className="
74-
tiptap
75-
prose-sm
76-
removed-prose
77-
removed-sm:prose-base
78-
removed-lg:prose-lg
79-
removed-xl:prose-2xl
80-
removed-prose-foreground
81-
line-clamp-3
82-
"> {/* IMPORTANT */}
79+
className={cn(
80+
"border p-2 bg-card rounded-xl ",
81+
"flex flex-col justify-between items-start gap-2",
82+
"",
83+
)}>
84+
<div className={cn(
85+
"tiptap",
86+
"prose-sm",
87+
"removed-prose",
88+
"removed-sm:prose-base ",
89+
"removed-lg:prose-lg",
90+
"removed-xl:prose-2xl",
91+
"removed-prose-foreground",
92+
"line-clamp-3",
93+
)}> {/* IMPORTANT */}
8394
<div dangerouslySetInnerHTML={{ __html: sanitizeHTML(quote.text) }}></div>
8495
</div>
8596
{/*
8697
<p className="text-base w-full text-card-foreground text-right">-- Pritam</p>
8798
*/}
8899

89100
<div className="flex w-full items-end justify-between gap-2">
90-
{quote.tags && quote.tags.length > 0 ? (
91-
<div className="flex flex-wrap gap-2">
92-
{quote.tags.map((tag, index) => (
93-
<Badge
94-
variant={'outline'}
95-
className=" text-[0.5rem] bg-primary/10 border-primary/20 text-primary/70"
96-
key={tag.id}
97-
>
98-
#{tag.name}
99-
</Badge>
100-
))}
101-
</div>
102-
) : (<span></span>)}
103-
101+
{infoType == "tags" && <ListTags tags={quote.tags!} />}
102+
{infoType == "created_at" && (
103+
<p className="p-0 text-xs text-muted-foreground"> {
104+
formatDate(quote.created_at!)
105+
}</p>
106+
)}
107+
{infoType == "updated_at" && (
108+
<p className="p-0 text-xs text-muted-foreground"> {
109+
formatDate(quote.updated_at!)
110+
}</p>
111+
)}
104112
<div className="flex items-center gap-2 ">
105113
<Button
106114
className="hover:text-green-600 "
107115
variant={"outline"}
108116
onClick={(e) => {
109117
e.preventDefault()
110-
const text = htmlToPlainText(quote.text)
118+
const text = htmlToPlainText(quote.text)
111119
onCopy(text)
112120
}}
113121
aria-label="Copy quote"
114122
size={"sm"}
115123
>
116124
{copying ? <Check className="text-green-500" /> : <Copy />}
117125
</Button>
118-
119-
126+
127+
120128
{/*
121129
<Button
122130
className="hover:text-yellow-600 "

‎frontend/src/feature/quote/dialog/setting.dialog.tsx‎

Lines changed: 97 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "@/components/ui/dialog"
1111
import { Button } from "@/components/ui/button";
1212
import { Separator } from "@/components/ui/separator";
13-
import type { QuoteFormData } from "@/model/quote.model";
13+
import type { QuoteFormData, SortOption } from "@/model/quote.model";
1414
import {
1515
Select,
1616
SelectItem,
@@ -19,21 +19,35 @@ import {
1919
SelectTrigger,
2020
} from "@/components/ui/select"
2121
import { useState } from "react";
22-
import { useTheme, type ThemeMode } from '@/hook/use-dark-or-light-theme.hook'
22+
import { themeModes, useTheme, type ThemeMode } from '@/hook/use-dark-or-light-theme.hook'
2323
import { ArrowLeftIcon, CircleArrowDown, CircleCheckBig, Copy, Images, LoaderCircle, Save, Share, Settings } from "lucide-react";
2424
import { colorThemes, useColorTheme, type ColorTheme } from "@/hook/use-color-theme.hook";
25+
import { showInfo, useShowCardInfo, type ShowInfo } from "@/hook/use-show-card-info.hook";
26+
import { capitalize } from "@/helper/capitalize";
2527

28+
interface SortOptions { key: SortOption, label: string }
2629

30+
const sortOptions: SortOptions[] = [
31+
{
32+
key: "created_at",
33+
label: "Created at",
34+
},
35+
{
36+
key: "updated_at",
37+
label: "Updated at",
38+
},
39+
]
2740
interface Props {
2841

2942
}
3043

3144
export function SettingComponent(props: Props) {
32-
3345
const { theme, setTheme } = useTheme()
34-
const { colorTheme, setColorTheme } = useColorTheme()
3546
const [open, setOpen] = useState(false)
47+
const { colorTheme, setColorTheme } = useColorTheme()
48+
const { info, setInfo } = useShowCardInfo()
3649

50+
const [sortBy, setSortBy] = useState<SortOptions["key"]>("created_at")
3751

3852
return (
3953
<Dialog open={open} onOpenChange={setOpen}>
@@ -55,42 +69,109 @@ export function SettingComponent(props: Props) {
5569
</DialogDescription>
5670
</DialogHeader>
5771
<Separator className="bg-border" />
58-
<div className="flex flex-col gap-4">
59-
<div className="flex justify-between gap-4">
72+
<div className="flex flex-col gap-2 text-sm">
73+
<p className="text-muted-foreground text-xs">App Style</p>
74+
<div className="flex justify-between items-center ">
6075
Appearance
6176
<Select value={theme} onValueChange={(value) => setTheme(value as ThemeMode)}>
6277
<SelectTrigger className="">
63-
<SelectValue placeholder="Theme" />
78+
<SelectValue placeholder="Appearance" />
6479
</SelectTrigger>
6580
<SelectContent>
66-
<SelectItem value="light">Light</SelectItem>
67-
<SelectItem value="dark">Dark</SelectItem>
68-
<SelectItem value="system" >System</SelectItem>
81+
{
82+
themeModes.map((pri) => {
83+
const yo = capitalize(pri)
84+
return (
85+
<SelectItem key={pri} value={pri} className="text-capitalize capitalize">
86+
{yo}
87+
</SelectItem>
88+
)
89+
})
90+
}
6991
</SelectContent>
7092
</Select>
7193
</div>
72-
<Separator className="bg-border" />
73-
<div className="flex justify-between gap-4">
94+
<div className="flex justify-between items-center ">
7495
Color Theme
75-
<Select value={colorTheme} onValueChange={(value) => setColorTheme(value as ColorTheme)}>
96+
<Select
97+
value={colorTheme}
98+
onValueChange={(value) => setColorTheme(value as ColorTheme)}>
7699
<SelectTrigger className="">
77-
<SelectValue placeholder="Color Theme" />
100+
<SelectValue placeholder="Color Theme" className="text-capitalize capitalize" />
78101
</SelectTrigger>
79-
<SelectContent>
102+
<SelectContent className="">
80103
{
81104
colorThemes.map((pri) => {
105+
const yoyo = pri.replace("theme-", "")
106+
const yo = capitalize(yoyo)
107+
console.log({ yo, yoyo })
108+
return (
109+
<SelectItem key={pri} value={pri} className="">
110+
{yo}
111+
</SelectItem>
112+
)
113+
})
114+
}
115+
</SelectContent>
116+
</Select>
117+
</div>
118+
<div className="flex justify-between items-center ">
119+
Sort by
120+
<Select value={sortBy} onValueChange={(value) => setSortBy(value as SortOption)}>
121+
<SelectTrigger className="">
122+
<SelectValue placeholder="Sort By" />
123+
</SelectTrigger>
124+
<SelectContent>
125+
{
126+
sortOptions.map((pri) => {
127+
let yo = capitalize(pri.key)
82128
return (
83-
<SelectItem key={pri} value={pri} className="text-capitalize capitalize">{pri}</SelectItem>
129+
<SelectItem key={pri.key} value={pri.key} className="">
130+
{yo.replaceAll('_', " ")}
131+
</SelectItem>
84132
)
85133
})
86134
}
87135
</SelectContent>
88136
</Select>
89137
</div>
138+
</div>
90139

140+
<Separator className="bg-border" />
91141

142+
<div className="flex flex-col gap-2">
143+
<p className="text-muted-foreground text-xs">Card Style</p>
144+
<div className="flex justify-between items-center ">
145+
Show Info
146+
<Select value={info} onValueChange={(value) => setInfo(value as ShowInfo)}>
147+
<SelectTrigger className="">
148+
<SelectValue placeholder="Show Info" />
149+
</SelectTrigger>
150+
<SelectContent>
151+
{
152+
showInfo.map((pri) => {
153+
let yo = pri.charAt(0).toUpperCase() + pri.slice(1)
154+
return (
155+
<SelectItem key={pri} value={pri} className=" ">
156+
{yo.replaceAll('_', " ")}
157+
</SelectItem>
158+
)
159+
})
160+
}
161+
</SelectContent>
162+
</Select>
163+
</div>
164+
</div>
92165

166+
<Separator className="bg-border" />
167+
168+
<div className="flex flex-col gap-2">
169+
<p className="text-muted-foreground text-xs">Other</p>
170+
<div className="flex justify-between text-center ">
171+
Made with 💙 by Pritam
172+
</div>
93173
</div>
174+
94175
</DialogContent>
95176
</Dialog>
96177
);

‎frontend/src/feature/quote/popover/filter.popover.tsx‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ export function TagFilter({ tags, value, onChange }: TagFilterProps) {
2626
)
2727
}
2828

29-
const label = useMemo(() => {
30-
if (value.length === 0) return "Filter"
31-
if (value.length === 1) return value[0]
32-
return `${value.length} tags`
33-
}, [value])
34-
3529
return (
3630
<Popover open={open} onOpenChange={setOpen}>
3731
<PopoverTrigger asChild >

‎frontend/src/helper/capitalize.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const capitalize = (pri: string) => pri?.charAt(0).toUpperCase() + pri?.slice(1);
2+

‎frontend/src/hook/use-color-theme.hook.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const colorThemes: ColorTheme[] = [
2424
]
2525

2626
export const useColorTheme = () => {
27-
const [stroredColorTheme, setStroredColorTheme] = useLocalStorage("app_theme", "theme-rose")
27+
const [stroredColorTheme, setStroredColorTheme] = useLocalStorage<ColorTheme>("app_theme", "theme-rose")
2828
const [colorTheme, setColorTheme] = useState<ColorTheme>(stroredColorTheme as ColorTheme)
2929

3030
useEffect(() => {

‎frontend/src/hook/use-dark-or-light-theme.hook.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { useLocalStorage } from "@/hook/use-localstroage.hook"
33

44
export type ThemeMode = "system" | "light" | "dark"
55

6+
export const themeModes = ["system" , "light" , "dark"]
7+
68
const getSystemTheme = () =>
79
window.matchMedia("(prefers-color-scheme: dark)").matches
810

911
export const useTheme = () => {
10-
const [ stroredTheme, setStroredTheme ]= useLocalStorage( 'app_appearance', "system")
12+
const [ stroredTheme, setStroredTheme ]= useLocalStorage<ThemeMode>( 'app_appearance', "system")
1113

1214
const [theme, setTheme] = useState<ThemeMode>(stroredTheme as ThemeMode)
1315
const [isDark, setIsDark] = useState(false)

‎frontend/src/hook/use-localstroage.hook.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState } from "react";
22
export const STORAGE_KEYS = {
33
THEME: "app_theme",
44
APPEARANCE: "app_appearance",
5+
CARD_INFO: 'card_info'
56
} as const;
67

78
// union type of all values

0 commit comments

Comments
 (0)