1- import { useRef , useState } from 'react'
1+ import { useRef } from 'react'
22import { BiBookmarkMinus } from 'react-icons/bi'
3+ import { GrDocumentDownload , GrDocumentUpload } from 'react-icons/gr'
34import toast from 'react-simple-toasts'
45import { CardLink } from 'src/components/Elements'
56import { SettingsContentLayout } from 'src/components/Layout/SettingsContentLayout'
@@ -62,7 +63,7 @@ const BookmarkItem = ({ item, appendRef = false }: BookmarkItemProps) => {
6263
6364export const BookmarkSettings = ( ) => {
6465 const inputFile = useRef < HTMLInputElement | null > ( null )
65- const { initState, userBookmarks } = useBookmarks ( )
66+ const { initState, userBookmarks } = useBookmarks ( )
6667
6768 const importBookmarks = ( ) => {
6869 inputFile . current ?. click ( )
@@ -72,63 +73,66 @@ export const BookmarkSettings = () => {
7273 const blob = new Blob ( [ JSON . stringify ( userBookmarks , null , 2 ) ] , {
7374 type : 'application/json' ,
7475 } )
75- const downloadURL = URL . createObjectURL ( blob ) ;
76- const link = document . createElement ( "a" ) ;
77- link . href = downloadURL ;
78- link . download = "hackertabBookmarks" ;
79- link . click ( ) ;
80- toast ( 'Your bookmarks have been successfully exported' , { theme : 'defaultToast' } )
76+ const downloadURL = URL . createObjectURL ( blob )
77+ const link = document . createElement ( 'a' )
78+ link . href = downloadURL
79+ link . download = 'hackertabBookmarks'
80+ link . click ( )
8181 }
82+
8283 const handleFileChange = ( event : any ) => {
83- const file = event . target . files ?. [ 0 ] ;
84+ const file = event . target . files ?. [ 0 ]
8485 if ( file ) {
8586 const reader = new FileReader ( )
8687 reader . onload = ( ) => {
87- const importData : BookmarkedPost [ ] = JSON . parse ( reader . result as string ) ;
88- const validatedData = importData . filter (
89- ( data : BookmarkedPost ) =>
90- data . title &&
91- data . url &&
92- ! userBookmarks . some ( ( bm ) => bm . title === data . title && bm . url === data . url ) )
93- . map ( ( data ) => ( {
88+ const importData : BookmarkedPost [ ] = JSON . parse ( reader . result as string )
89+ const validatedData = importData
90+ . filter (
91+ ( data : BookmarkedPost ) =>
92+ data . title &&
93+ data . url &&
94+ ! userBookmarks . some ( ( bm ) => bm . title === data . title && bm . url === data . url )
95+ )
96+ . map ( ( data ) => ( {
9497 title : data . title ,
9598 url : data . url ,
9699 source : data . source || '' ,
97100 sourceType : data . sourceType || '' ,
98- } ) ) ;
101+ } ) )
99102 initState ( {
100103 userBookmarks : [ ...userBookmarks , ...validatedData ] ,
101- } ) ;
104+ } )
102105 toast ( 'Your bookmarks have been successfully imported' , { theme : 'defaultToast' } )
103106 }
104107 reader . readAsText ( file )
105108 }
106109 }
107110
108-
109111 return (
110112 < >
111- < div className = "btn-group" >
112- < div >
113- < input
114- type = "file"
115- id = "file"
116- ref = { inputFile }
117- accept = "application/json"
118- style = { { display : 'none' } }
119- onChange = { handleFileChange }
120- />
121- < button className = "notbtn btn" onClick = { ( ) => importBookmarks ( ) } >
122- Import
123- </ button >
124- </ div >
125- < button className = "notbtn btn" onClick = { ( ) => exportBookmarks ( ) } >
126- Export
127- </ button >
128- </ div >
129113 < SettingsContentLayout
130114 title = "Bookmarks"
131- description = "Find all your bookmarks here. You can remove a bookmark by clicking on the remove icon." >
115+ description = "Find all your bookmarks here. You can remove a bookmark by clicking on the remove icon."
116+ actions = {
117+ < >
118+ < input
119+ type = "file"
120+ id = "file"
121+ ref = { inputFile }
122+ accept = "application/json"
123+ className = "hidden"
124+ onChange = { handleFileChange }
125+ />
126+ < button className = "extraBtn extraTextBtn" onClick = { ( ) => importBookmarks ( ) } >
127+ < GrDocumentUpload />
128+ Import
129+ </ button >
130+ < button className = "extraBtn extraTextBtn" onClick = { ( ) => exportBookmarks ( ) } >
131+ < GrDocumentDownload />
132+ Export
133+ </ button >
134+ </ >
135+ } >
132136 < div className = "bookmarks" >
133137 { userBookmarks . map ( ( bm ) => (
134138 < BookmarkItem item = { bm } key = { bm . url } />
0 commit comments