Skip to content

Commit eb7a428

Browse files
committed
Added created at and updated at field to quote
1 parent a64f030 commit eb7a428

6 files changed

Lines changed: 39 additions & 35 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ removed-sm:prose-base
5050
removed-xl:prose-2xl
5151
transition-transform duration-300 ease-out
5252
"> {/* IMPORTANT */}
53-
<EditorContent editor={editor} />
53+
<EditorContent editor={editor} />
5454
{/*
5555
<div className="
5656
fixed

‎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 = 6
9+
const DB_VERSION = 7
1010

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

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

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { openDB, STORES } from "@/db/db";
22
import type { Quote } from "@/model/quote.model";
33

44
const STORE_NAME = STORES.QUOTES;
5-
5+
66
export const getAllQuotes = async (): Promise<Quote[]> => {
77
const db = await openDB();
88
const transaction = db.transaction(STORE_NAME, 'readonly');
@@ -26,30 +26,30 @@ export const getAllQuote = async (quoteId: number): Promise<Quote> => {
2626
};
2727

2828

29-
export const addQuote = async (
30-
quote: Quote
31-
): Promise<Quote> => {
32-
const db = await openDB()
33-
const tx = db.transaction(STORE_NAME, 'readwrite')
34-
const store = tx.objectStore(STORE_NAME)
35-
36-
return new Promise(async (resolve, reject) => {
37-
const { id, ...data } = quote
38-
const req = store.add(data)
29+
export const addQuote = async (quote: Quote): Promise<Quote> => {
30+
const db = await openDB();
31+
const tx = db.transaction(STORE_NAME, 'readwrite');
32+
const store = tx.objectStore(STORE_NAME);
3933

40-
req.onsuccess = async () => {
41-
console.log("resol", quote, req.result)
42-
await tx.done
34+
const promise = new Promise<Quote>((resolve, reject) => {
35+
// IMPORTANT: remove id before add
36+
const { id, ...data } = quote;
37+
const req = store.add({
38+
...data,
39+
created_at: new Date(),
40+
updated_at: new Date(),
41+
});
42+
req.onsuccess = () => {
4343
resolve({
4444
...quote,
45-
id: req.result as number,
46-
})
47-
}
48-
49-
req.onerror = () => reject(req.error)
50-
})
51-
}
45+
id: req.result as number, // ✅ GENERATED ID
46+
});
47+
};
48+
req.onerror = () => reject(req.error);
49+
});
5250

51+
return promise
52+
};
5353

5454

5555

@@ -62,18 +62,20 @@ export const updateQuote = async (quote: Quote): Promise<Quote> => {
6262
const tx = db.transaction(STORE_NAME, 'readwrite');
6363
const store = tx.objectStore(STORE_NAME);
6464

65-
return new Promise(async (resolve, reject) => {
66-
const { id, ...data } = quote
67-
const req = store.put(quote)
68-
65+
const promise = new Promise<Quote>(async (resolve, reject) => {
66+
const req = store.put({
67+
...quote,
68+
updated_at: new Date(),
69+
})
6970
req.onsuccess = async () => {
70-
console.log("resol", quote, req.result)
71-
await tx.done
72-
resolve(quote)
71+
resolve({
72+
...quote,
73+
})
7374
}
74-
7575
req.onerror = () => reject(req.error)
7676
})
77+
78+
return promise
7779
};
7880

7981

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const buildStyle = (texture: TextureKey, pri_set: Pri_set) => {
9797
backgroundSize: "cover",
9898
backgroundPosition: "center",
9999
};
100-
console.log({ style, preset,texture });
100+
// console.log({ style, preset,texture });
101101

102102
return style
103103
};
@@ -124,7 +124,7 @@ const buildStyleString = (texture: TextureKey, pri_set: Pri_set): string => {
124124
background-position: center;
125125
`.trim();
126126

127-
console.log({ style, preset, texture });
127+
// console.log({ style, preset, texture });
128128

129129
return style;
130130
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export interface Quote {
55
text: string;
66
texture?: TextureKey;
77
pri_set?: Pri_set;
8+
created_at?: Date;
9+
updated_at?: Date;
810
}
911

1012
export interface QuoteDetails {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const noteRef = useRef<HTMLDivElement>(null)
5050
texture: quote?.texture ,
5151
pri_set: quote?.pri_set,
5252
}))
53-
console.log({quoteData})
53+
// console.log({quoteData})
5454

5555
const onTagChoose = (tag: string) => {
5656
setQuoteData(prev => {
@@ -120,7 +120,7 @@ console.log({quoteData})
120120
console.log({ quoteId });
121121

122122
const tags = await getTags(quote.tags!)
123-
console.log({ tags })
123+
// console.log({ tags })
124124

125125
// Delete all existing tags for this quote
126126
await deleteAllQuoteTags(quoteId!)

0 commit comments

Comments
 (0)