Skip to content

Commit 8ed0aac

Browse files
authored
Merge pull request #7 from PriDebnath/feat/tag-system
Feat/tag system
2 parents 7fe3fdd + a770dc2 commit 8ed0aac

16 files changed

Lines changed: 1331 additions & 163 deletions

File tree

‎frontend/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"@floating-ui/react": "^0.27.16",
1717
"@radix-ui/react-dialog": "^1.1.15",
18+
"@radix-ui/react-dropdown-menu": "^2.1.16",
1819
"@radix-ui/react-label": "^2.1.8",
1920
"@radix-ui/react-slot": "^1.2.4",
2021
"@tailwindcss/vite": "^4.1.18",

‎frontend/src/App.tsx‎

Lines changed: 127 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
//import "index.scss"
22
import { useEffect, useState } from 'react'
33
import { Button } from '@/components/ui/button'
4-
import type { Quote } from '@/model/quote.model'
4+
import type { Quote, QuoteFormData, Tag } from '@/model/quote.model'
55
import { ListQuote } from '@/feature/quote/list.quote'
66
import DeleteQuoteDialog from '@/feature/quote/dialog/delete.quote.dialog'
77
import AddEditQuoteDialog from '@/feature/quote/dialog/add-edit.quote.dialog'
8-
import { getAllQuotes, addQuote, updateQuote, deleteQuote } from '@/db/quote.db'
8+
import { getAllQuotes, addQuote, updateQuote, deleteQuote, getAllQuote } from '@/db/quote.db'
99
import { PlusIcon, Home, BookOpen, Search, Settings, SearchIcon } from 'lucide-react'
1010
import { InputGroup, InputGroupInput, InputGroupAddon } from '@/components/ui/input-group'
11+
import { addOrGetTag } from '@/db/tag.db'
12+
import { addQuoteTag, deleteAllQuoteTags, getAllQuotesDetails } from '@/db/quote_tags.db'
1113

1214
function App() {
1315
const [loading, setLoading] = useState(false)
@@ -35,115 +37,150 @@ function App() {
3537
setOpenedDeleteDialog(true)
3638
}
3739

38-
const handleSubmit = async (quote: Quote) => {
39-
console.log(quote)
40-
if (quote.id) { // edit
41-
await updateQuote(quote)
42-
} else {
43-
await addQuote({
44-
...quote,
45-
id: new Date().getTime(),
46-
})
40+
const getTags = async (tags: string[]): Promise<Tag[]> => {
41+
const result: Tag[] = [];
42+
43+
for (const tag of tags) {
44+
const savedTag = await addOrGetTag({ name: tag });
45+
result.push(savedTag);
4746
}
48-
fetchQuotes()
49-
setOpenAddOrEditDialog(false)
50-
setSelectedQuote(null)
47+
48+
return result;
49+
};
50+
51+
52+
const handleSubmit = async (quote: QuoteFormData) => {
53+
console.log({quote})
54+
let quoteId: number | undefined = quote.id
55+
if (quoteId) { // edit
56+
await updateQuote({
57+
...quote,
58+
text: quote.text || "Empty"
59+
})
60+
} else {
61+
const newQuote = await addQuote({
62+
...quote,
63+
text: quote.text || "Empty",
64+
})
65+
quoteId = newQuote.id
5166
}
5267

53-
const handleDeleteSubmit = async (quote: Quote) => {
54-
console.log("deleted")
55-
await deleteQuote(quote.id!)
56-
console.log("deleted")
57-
setSelectedQuote(null)
58-
setOpenedDeleteDialog(false)
59-
fetchQuotes()
68+
console.log({quoteId});
69+
70+
const tags = await getTags(quote.tags!)
71+
console.log({ tags })
72+
73+
// Delete all existing tags for this quote
74+
await deleteAllQuoteTags(quoteId!)
75+
76+
// Add new tags for this quote
77+
for (const tag of tags) {
78+
await addQuoteTag({
79+
quoteId: quoteId!,
80+
tagId: tag.id!
81+
})
6082
}
6183

62-
const fetchQuotes = async () => {
63-
const storedQuotes = await getAllQuotes();
64-
console.log({ storedQuotes });
65-
setLoading(false)
66-
setSelectedQuote(null)
67-
setQuotes(storedQuotes);
68-
};
84+
fetchQuotes()
85+
setOpenAddOrEditDialog(false)
86+
setSelectedQuote(null)
87+
}
88+
89+
const handleDeleteSubmit = async (quote: QuoteFormData) => {
90+
console.log("deleted")
91+
await deleteQuote(quote.id!)
92+
console.log("deleted")
93+
setSelectedQuote(null)
94+
setOpenedDeleteDialog(false)
95+
fetchQuotes()
96+
}
6997

70-
useEffect(() => {
71-
setLoading(true)
72-
fetchQuotes();
73-
}, []);
74-
75-
return (
76-
<div className="bg-primary/10">
77-
{/* Purple Header */}
78-
<header className="w-full text-white bg-primary p-4 flex flex-col items-center">
79-
<h1 className="p-4">Quotes Keeper 3.0</h1>
80-
81-
</header>
82-
83-
{/* Sticky Search Bar */}
84-
<div
85-
className="rounded-b-2xl sticky top-0 bg-primary p-4">
86-
<InputGroup
87-
className=" mb-4 text-white border-white border">
88-
<InputGroupInput placeholder="Search..." className='text-white' />
89-
<InputGroupAddon>
90-
<SearchIcon className='text-white' />
91-
</InputGroupAddon>
92-
</InputGroup>
93-
</div>
94-
95-
{/* Main Content */}
96-
<main className="p-4 ">
97-
<ListQuote
98-
loading={loading}
99-
quotes={quotes}
100-
onEdit={openEditDialog}
101-
onDelete={openDeleteDialog}
102-
/>
103-
</main>
104-
105-
{/* Bottom Navigation */}
106-
<nav className="flex items-center justify-center ">
107-
{/* <button className="nav-item active">
98+
const fetchQuotes = async () => {
99+
const storedQuotes = await getAllQuotesDetails();
100+
console.log({storedQuotes});
101+
102+
setLoading(false)
103+
setSelectedQuote(null)
104+
setQuotes(storedQuotes);
105+
};
106+
107+
useEffect(() => {
108+
setLoading(true)
109+
fetchQuotes();
110+
}, []);
111+
112+
return (
113+
<div className="bg-primary/10">
114+
{/* Purple Header */}
115+
<header className="w-full text-white bg-primary p-4 flex flex-col items-center">
116+
<h1 className="p-4">Quotes Keeper 3.0</h1>
117+
118+
</header>
119+
120+
{/* Sticky Search Bar */}
121+
<div
122+
className="rounded-b-2xl sticky top-0 bg-primary p-4">
123+
<InputGroup
124+
className=" mb-4 text-white border-white border">
125+
<InputGroupInput placeholder="Search..." className='text-white' />
126+
<InputGroupAddon>
127+
<SearchIcon className='text-white' />
128+
</InputGroupAddon>
129+
</InputGroup>
130+
</div>
131+
132+
{/* Main Content */}
133+
<main className="p-4 ">
134+
<ListQuote
135+
loading={loading}
136+
quotes={quotes}
137+
onEdit={openEditDialog}
138+
onDelete={openDeleteDialog}
139+
/>
140+
</main>
141+
142+
{/* Bottom Navigation */}
143+
<nav className="flex items-center justify-center ">
144+
{/* <button className="nav-item active">
108145
<Home size={24} />
109146
<span>Home</span>
110147
</button>
111148
<button className="nav-item">
112149
<BookOpen size={24} />
113150
<span>Books</span>
114151
</button> */}
115-
<Button
152+
<Button
116153
size="lg"
117-
className=" fixed bottom-4 "
118-
onClick={openAddDialog}>
119-
<PlusIcon />
120-
</Button>
121-
{/* <button className="nav-item">
154+
className=" fixed bottom-4 "
155+
onClick={openAddDialog}>
156+
<PlusIcon />
157+
</Button>
158+
{/* <button className="nav-item">
122159
<Search size={24} />
123160
<span>Discover</span>
124161
</button>
125162
<button className="nav-item">
126163
<Settings size={24} />
127164
<span>Settings</span>
128165
</button> */}
129-
</nav>
130-
131-
<AddEditQuoteDialog
132-
mode={addOrEdit}
133-
quote={selectedQuote}
134-
open={openAddOrEditDialog}
135-
setOpen={setOpenAddOrEditDialog}
136-
handleSubmit={handleSubmit}
137-
/>
138-
139-
<DeleteQuoteDialog
140-
open={openedDeleteDialog}
141-
setOpen={setOpenedDeleteDialog}
142-
quote={selectedQuote}
143-
handleDelete={handleDeleteSubmit}
144-
/>
145-
</div>
146-
)
166+
</nav>
167+
168+
<AddEditQuoteDialog
169+
mode={addOrEdit}
170+
quote={selectedQuote}
171+
open={openAddOrEditDialog}
172+
setOpen={setOpenAddOrEditDialog}
173+
handleSubmit={handleSubmit}
174+
/>
175+
176+
<DeleteQuoteDialog
177+
open={openedDeleteDialog}
178+
setOpen={setOpenedDeleteDialog}
179+
quote={selectedQuote}
180+
handleDelete={handleDeleteSubmit}
181+
/>
182+
</div>
183+
)
147184
}
148185

149186
export default App

‎frontend/src/components/common/tiptap-customized.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import StarterKit from '@tiptap/starter-kit'
2+
import { BatteryFull, List } from 'lucide-react'
23
import { useEditor, EditorContent } from '@tiptap/react'
34
import { FloatingMenu, BubbleMenu } from '@tiptap/react/menus'
4-
import { BatteryFull, List } from 'lucide-react'
55
import TiptapToolbar from '@/components/common/tiptap-toolbar'
66

77

@@ -15,6 +15,11 @@ const Tiptap = (props: Props) => {
1515
const editor = useEditor({
1616
extensions: [StarterKit], // define your extension array
1717
content: value,
18+
editorProps: {
19+
attributes: {
20+
class: 'border rounded border-primary/20 focus-visible:border-primary outline-none'
21+
}
22+
},
1823
onUpdate: (updates) => {
1924
const { editor: newEditor } = updates
2025
const html = newEditor.getHTML()
@@ -32,7 +37,7 @@ const Tiptap = (props: Props) => {
3237
xl:prose-2xl
3338
focus:outline-none
3439
"> {/* IMPORTANT */}
35-
<EditorContent editor={editor} className='border rounded border-primary/20 active:border-primary' />
40+
<EditorContent editor={editor} />
3641
<TiptapToolbar editor={editor} />
3742
{/* <FloatingMenu editor={editor}>This is the floating menu</FloatingMenu>
3843
<BubbleMenu editor={editor}>This is the bubble menu</BubbleMenu> */}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as React from "react"
2+
import { Slot } from "@radix-ui/react-slot"
3+
import { cva, type VariantProps } from "class-variance-authority"
4+
5+
import { cn } from "@/lib/utils"
6+
7+
const badgeVariants = cva(
8+
"inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
9+
{
10+
variants: {
11+
variant: {
12+
default:
13+
"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
14+
secondary:
15+
"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
16+
destructive:
17+
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
18+
outline:
19+
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
20+
},
21+
},
22+
defaultVariants: {
23+
variant: "default",
24+
},
25+
}
26+
)
27+
28+
function Badge({
29+
className,
30+
variant,
31+
asChild = false,
32+
...props
33+
}: React.ComponentProps<"span"> &
34+
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
35+
const Comp = asChild ? Slot : "span"
36+
37+
return (
38+
<Comp
39+
data-slot="badge"
40+
className={cn(badgeVariants({ variant }), className)}
41+
{...props}
42+
/>
43+
)
44+
}
45+
46+
export { Badge, badgeVariants }

0 commit comments

Comments
 (0)