Skip to content

Commit 91ae7de

Browse files
committed
Integrated choose bg and display bg system
1 parent c9c52c7 commit 91ae7de

8 files changed

Lines changed: 74 additions & 60 deletions

File tree

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { motion } from "framer-motion";
22
import StarterKit from '@tiptap/starter-kit'
33
import { BatteryFull, List } from 'lucide-react'
44
import { useEditor, EditorContent } from '@tiptap/react'
5+
import type { QuoteFormData } from "@/model/quote.model";
56
import { FloatingMenu, BubbleMenu } from '@tiptap/react/menus'
67
import TiptapToolbar from '@/components/common/tiptap-toolbar'
7-
import {useGetKeyBoardHeight} from '@/hook/use-get-keyboard-height.hook'
8+
import { useGetKeyBoardHeight } from '@/hook/use-get-keyboard-height.hook'
89

910
interface Props {
1011
value?: string
11-
onValueUpdate: (text: string) => void
12+
onValueUpdate: (key: keyof QuoteFormData, value: string) => void
1213
}
1314

1415
const Tiptap = (props: Props) => {
@@ -24,13 +25,13 @@ const Tiptap = (props: Props) => {
2425
onUpdate: (updates) => {
2526
const { editor: newEditor } = updates
2627
const html = newEditor.getHTML()
27-
onValueUpdate(html)
28+
onValueUpdate("text", html)
2829
}
2930
})
30-
31-
let keyBoardHeight = useGetKeyBoardHeight()
3231

33-
console. log({k: keyBoardHeight})
32+
let keyBoardHeight = useGetKeyBoardHeight()
33+
34+
console.log({ k: keyBoardHeight })
3435
return (
3536
<div className="
3637
tiptap
@@ -62,7 +63,7 @@ transition-transform duration-300 ease-out
6263
>
6364
*/}
6465
<motion.div
65-
className="
66+
className="
6667
fixed
6768
z-50
6869
bottom-0
@@ -71,17 +72,17 @@ transition-transform duration-300 ease-out
7172
border
7273
rounded-t-xl
7374
"
74-
initial={{ scale: 0.8, }}
75-
animate={{
76-
y: -keyBoardHeight ,
77-
scale: 1
78-
}}
79-
transition={{
80-
type: "spring",
81-
stiffness: 300, // how stiff the spring is
82-
damping: 30, // how quickly it settles
83-
}}
84-
>
75+
initial={{ scale: 0.8, }}
76+
animate={{
77+
y: -keyBoardHeight,
78+
scale: 1
79+
}}
80+
transition={{
81+
type: "spring",
82+
stiffness: 300, // how stiff the spring is
83+
damping: 30, // how quickly it settles
84+
}}
85+
>
8586
<TiptapToolbar editor={editor} />
8687
</motion.div>
8788
{/* <FloatingMenu editor={editor}>This is the floating menu</FloatingMenu>

‎frontend/src/db/db.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* - keyPath change
77
*/
88
const DB_NAME = 'quotes_keeper_db_by_pri';
9-
const DB_VERSION = 5
9+
const DB_VERSION = 6
1010

1111
export const STORES = {
1212
QUOTES: 'quotes',

‎frontend/src/db/quote.db.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const getAllQuote = async (quoteId: number): Promise<Quote> => {
2727

2828

2929
export const addQuote = async (
30-
quote: Omit<Quote, 'id'>
30+
quote: Quote
3131
): Promise<Quote> => {
3232
const db = await openDB()
3333
const tx = db.transaction(STORE_NAME, 'readwrite')

‎frontend/src/db/quote_tags.db.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ export const getAllQuotesDetails = async (): Promise<QuoteDetails[]> => {
174174
}
175175

176176
result.push({
177-
id: quote.id,
178-
text: quote.text,
177+
...quote,
179178
tags,
180179
})
181180
}

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Badge } from "@/components/ui/badge";
22
import { Button } from "@/components/ui/button";
33
import { sanitizeHTML } from "@/helper/sanitize-html";
4+
import useBackground from "@/hook/use-background.hook";
45
import { cn } from "@/lib/utils";
56
import type { Quote, QuoteDetails } from "@/model/quote.model";
67
import { Link } from "@tanstack/react-router";
@@ -16,6 +17,7 @@ interface Props {
1617
const QuoteCard = (props: Props) => {
1718
const { quote, onEdit, onDelete, } = props
1819
const [copying, setCopying] = useState(false)
20+
const { buildStyle } = useBackground()
1921

2022
const onCopy = async (text: string) => {
2123
setCopying(true)
@@ -26,20 +28,23 @@ const QuoteCard = (props: Props) => {
2628
}
2729

2830
return (
29-
<Link
30-
className=""
31-
to={"/$quoteId"}
31+
<Link
32+
className=""
33+
to={"/$quoteId"}
3234
params={
3335
{ quoteId: quote.id?.toString()! }
3436
}>
3537

36-
<div className={
37-
cn(
38-
"border p-2 bg-card rounded-xl ",
39-
"flex flex-col justify-between items-start gap-2",
40-
"",
41-
)
42-
}>
38+
<div
39+
style={buildStyle(quote.texture!, quote.pri_set!)}
40+
className={
41+
cn(
42+
"border p-2 bg-card rounded-xl ",
43+
"flex flex-col justify-between items-start gap-2",
44+
"",
45+
)
46+
47+
}>
4348
<div className="
4449
tiptap
4550
prose-sm
@@ -51,7 +56,7 @@ const QuoteCard = (props: Props) => {
5156
"> {/* IMPORTANT */}
5257
<div dangerouslySetInnerHTML={{ __html: sanitizeHTML(quote.text) }}></div>
5358
</div>
54-
{/*
59+
{/*
5560
<p className="text-base w-full text-card-foreground text-right">-- Pritam</p>
5661
*/}
5762

@@ -75,8 +80,8 @@ const QuoteCard = (props: Props) => {
7580
className="hover:text-green-600 "
7681
variant={"outline"}
7782
onClick={(e) => {
78-
e.preventDefault()
79-
onCopy(quote.text)
83+
e.preventDefault()
84+
onCopy(quote.text)
8085
}}
8186
aria-label="Copy quote"
8287
size={"sm"}
@@ -100,8 +105,8 @@ const QuoteCard = (props: Props) => {
100105
className=" hover:text-destructive "
101106
variant={"outline"}
102107
onClick={(e) => {
103-
e.preventDefault()
104-
onDelete(quote)
108+
e.preventDefault()
109+
onDelete(quote)
105110
}}
106111
aria-label="Delete quote"
107112
size={"sm"}

‎frontend/src/feature/quote/drawer/choose-background.drawer.tsx‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
1-
import { useState } from "react";
21
import {
32
Drawer,
3+
DrawerTitle,
44
DrawerClose,
5-
DrawerContent,
6-
DrawerDescription,
75
DrawerHeader,
8-
DrawerTitle,
6+
DrawerContent,
97
DrawerTrigger,
8+
DrawerDescription,
109
} from "@/components/ui/drawer";
10+
import { useState } from "react";
1111
import { Button } from "@/components/ui/button";
12-
import useBackground, { type Pri_set, type TextureKey } from "@/hook/use-background.hook";
12+
import type { QuoteFormData } from "@/model/quote.model";
1313
import { ArrowLeftIcon, Save, Shirt } from "lucide-react";
14+
import useBackground, { type Pri_set, type TextureKey } from "@/hook/use-background.hook";
1415

15-
export default function ChooseBackground() {
16+
interface Props {
17+
onValueUpdate: (key: keyof QuoteFormData, value: string) => void
18+
}
1619

20+
export default function ChooseBackground(props: Props) {
21+
const { onValueUpdate} = props
1722
const { textures, colorPresets, buildStyle } = useBackground()
18-
1923
const [selectedTexture, setSelectedTexture] = useState<TextureKey> ( "cardboard");
2024
const [selectedPreset, setSelectedPreset] = useState<Pri_set>('pri_set_1');
2125

22-
const apply = () => {
23-
// const result = {
24-
// image: selectedTexture,
25-
// color: selectedPreset.color ?? undefined,
26-
// overlay: selectedPreset.overlay ?? undefined,
27-
// };
28-
};
26+
const handleTextureClick = (key: TextureKey)=>{
27+
setSelectedTexture(key)
28+
onValueUpdate("texture", key)
29+
}
30+
31+
const handlePriSetClick = (pri: Pri_set)=>{
32+
setSelectedPreset(pri)
33+
onValueUpdate("pri_set", pri)
34+
}
2935

3036
return (
3137
<Drawer
@@ -79,7 +85,7 @@ export default function ChooseBackground() {
7985
return (
8086
<button
8187
key={ key}
82-
onClick={() => setSelectedTexture(key as TextureKey)}
88+
onClick={() => handleTextureClick(key as TextureKey)}
8389
className={`w-28 h-20 rounded-lg shrink-0 focus:outline-none ${selectedTexture === key ? "ring-2 ring-primary" : "border"
8490
}`}
8591
aria-pressed={selectedTexture === key}
@@ -110,7 +116,7 @@ export default function ChooseBackground() {
110116
return (
111117
<button
112118
key={key}
113-
onClick={() => setSelectedPreset(key as Pri_set)}
119+
onClick={() => handlePriSetClick(key as Pri_set)}
114120
className={`w-20 h-20 rounded-lg shrink-0 p-0 relative focus:outline-none ${isSelected ? "ring-2 ring-primary" : "border"
115121
}`}
116122
aria-pressed={isSelected}

‎frontend/src/model/quote.model.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export interface Quote {
1010
export interface QuoteDetails {
1111
id?: number | undefined;
1212
text: string;
13+
texture?: TextureKey;
14+
pri_set?: Pri_set;
1315
tags?: Tag[]
1416
}
1517

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ interface Props {
2525

2626
export function QuotePage(props: Props) {
2727
const { mode } = props
28+
const navigate = useNavigate()
29+
2830
// Only read params in edit mode
2931
const params = mode === 'edit' ? Route.useParams() : null
3032
const quoteId = params?.quoteId
@@ -42,9 +44,10 @@ export function QuotePage(props: Props) {
4244
id: quote?.id,
4345
text: quote?.text || "",
4446
tags: quote?.tags?.map((tag) => tag.name) || [],
47+
texture: quote?.texture,
48+
pri_set: quote?.pri_set,
4549
}))
4650

47-
const navigate = useNavigate()
4851

4952
const onTagChoose = (tag: string) => {
5053
setQuoteData(prev => {
@@ -70,21 +73,19 @@ export function QuotePage(props: Props) {
7073
})
7174
}
7275

73-
const onValueUpdate = (text: string) => {
76+
const onValueUpdate = (key: keyof QuoteFormData, value: string) => {
7477
setQuoteData(prev => ({
7578
...prev,
76-
text: text
79+
[key]: value
7780
}))
7881
}
7982

8083
const getTags = async (tags: string[]): Promise<Tag[]> => {
8184
const result: Tag[] = [];
82-
8385
for (const tag of tags) {
8486
const savedTag = await addOrGetTag({ name: tag });
8587
result.push(savedTag);
8688
}
87-
8889
return result;
8990
};
9091

@@ -98,7 +99,7 @@ export function QuotePage(props: Props) {
9899

99100

100101
const handleSubmit = useCallback(async (quote: QuoteFormData) => {
101-
console.log({ quote })
102+
console.log({at:"at" ,quote })
102103
let quoteId: number | undefined = quote.id
103104
if (quoteId) { // edit
104105
await updateQuote({
@@ -188,7 +189,7 @@ export function QuotePage(props: Props) {
188189
</Button>
189190
</Link>
190191
<div>
191-
<ChooseBackground />
192+
<ChooseBackground onValueUpdate={onValueUpdate}/>
192193
</div>
193194
</div>
194195

0 commit comments

Comments
 (0)