-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuseSaveBookmarks.ts
More file actions
50 lines (43 loc) · 1.16 KB
/
useSaveBookmarks.ts
File metadata and controls
50 lines (43 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
interface SaveBookmarkParams {
url: string;
title: string;
description: string;
imgUrl: string;
memo: string;
isRemindOn: boolean;
selectedCategory: string | null;
date: string | null;
time: string | null;
}
export const useSaveBookmark = () => {
const save = async (params: SaveBookmarkParams) => {
try {
const saveData = {
...params,
createdAt: new Date().toISOString(),
};
const result = await new Promise<{ bookmarks?: any[] }>((resolve) => {
chrome.storage.local.get(['bookmarks'], (items) => resolve(items));
});
const bookmarks = result.bookmarks || [];
bookmarks.push(saveData);
await new Promise<void>((resolve) => {
chrome.storage.local.set({ bookmarks }, resolve);
});
chrome.bookmarks.create(
{
parentId: '1',
title: params.title || params.url,
url: params.url,
},
(newBookmark) => {
console.log('크롬 북마크바에 저장 완료:', newBookmark);
}
);
// window.close();
} catch (error) {
console.error('저장 중 오류:', error);
}
};
return { save };
};