Skip to content

Commit fe41293

Browse files
committed
refactor: Remove bookmark import/export functionality from ProfileSettings component
1 parent eb3b6db commit fe41293

1 file changed

Lines changed: 1 addition & 87 deletions

File tree

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
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'
51
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'
92
import './profileSettings.css'
103

114
interface UserInfoProps {
@@ -36,84 +29,5 @@ const UserInfo = ({ user }: UserInfoProps) => {
3629

3730
export const ProfileSettings = () => {
3831
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-
&nbsp;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>
11933
}

0 commit comments

Comments
 (0)