|
1 | | -import { useRef } from 'react' |
2 | | -import { RiFileDownloadFill, RiFileUploadFill } from 'react-icons/ri' |
3 | | -import toast from 'react-simple-toasts' |
4 | | -import { SettingsContentLayout } from 'src/components/Layout/SettingsContentLayout' |
5 | 1 | import { useAuth, User } from 'src/features/auth' |
6 | | -import { BookmarkedPost } from 'src/features/bookmarks' |
7 | | -import { useBookmarks } from 'src/stores/bookmarks' |
8 | | -import { BookmarkItem } from '../BookmarkSettings' |
9 | 2 | import './profileSettings.css' |
10 | 3 |
|
11 | 4 | interface UserInfoProps { |
@@ -36,84 +29,5 @@ const UserInfo = ({ user }: UserInfoProps) => { |
36 | 29 |
|
37 | 30 | export const ProfileSettings = () => { |
38 | 31 | const { user } = useAuth() |
39 | | - |
40 | | - const inputFile = useRef<HTMLInputElement | null>(null) |
41 | | - const { initState, userBookmarks } = useBookmarks() |
42 | | - |
43 | | - const importBookmarks = () => { |
44 | | - inputFile.current?.click() |
45 | | - } |
46 | | - |
47 | | - const exportBookmarks = () => { |
48 | | - const blob = new Blob([JSON.stringify(userBookmarks, null, 2)], { |
49 | | - type: 'application/json', |
50 | | - }) |
51 | | - const downloadURL = URL.createObjectURL(blob) |
52 | | - const link = document.createElement('a') |
53 | | - link.href = downloadURL |
54 | | - link.download = 'hackertabBookmarks' |
55 | | - link.click() |
56 | | - } |
57 | | - |
58 | | - const handleFileChange = (event: any) => { |
59 | | - const file = event.target.files?.[0] |
60 | | - if (file) { |
61 | | - const reader = new FileReader() |
62 | | - reader.onload = () => { |
63 | | - const importData: BookmarkedPost[] = JSON.parse(reader.result as string) |
64 | | - const validatedData = importData |
65 | | - .filter( |
66 | | - (data: BookmarkedPost) => |
67 | | - data.title && |
68 | | - data.url && |
69 | | - !userBookmarks.some((bm) => bm.title === data.title && bm.url === data.url) |
70 | | - ) |
71 | | - .map((data) => ({ |
72 | | - title: data.title, |
73 | | - url: data.url, |
74 | | - source: data.source || '', |
75 | | - sourceType: data.sourceType || '', |
76 | | - })) |
77 | | - initState({ |
78 | | - userBookmarks: [...userBookmarks, ...validatedData], |
79 | | - }) |
80 | | - toast('Your bookmarks have been successfully imported', { theme: 'defaultToast' }) |
81 | | - } |
82 | | - reader.readAsText(file) |
83 | | - } |
84 | | - } |
85 | | - |
86 | | - return ( |
87 | | - <div className="profile"> |
88 | | - {user != null && <UserInfo user={user} />} |
89 | | - <SettingsContentLayout |
90 | | - title="Bookmarks" |
91 | | - description="Find all your bookmarks here. You can remove a bookmark by clicking on the remove icon." |
92 | | - actions={ |
93 | | - <> |
94 | | - <input |
95 | | - type="file" |
96 | | - id="file" |
97 | | - ref={inputFile} |
98 | | - accept="application/json" |
99 | | - className="hidden" |
100 | | - onChange={handleFileChange} |
101 | | - /> |
102 | | - <button className="extraBtn extraTextBtn" onClick={() => importBookmarks()}> |
103 | | - <RiFileUploadFill /> |
104 | | - Import |
105 | | - </button> |
106 | | - <button className="extraBtn" onClick={() => exportBookmarks()}> |
107 | | - <RiFileDownloadFill /> |
108 | | - </button> |
109 | | - </> |
110 | | - }> |
111 | | - <div className="bookmarks"> |
112 | | - {userBookmarks.map((bm) => ( |
113 | | - <BookmarkItem item={bm} key={bm.url} /> |
114 | | - ))} |
115 | | - </div> |
116 | | - </SettingsContentLayout> |
117 | | - </div> |
118 | | - ) |
| 32 | + return <div className="profile">{user != null && <UserInfo user={user} />}</div> |
119 | 33 | } |
0 commit comments