1
1
import React , { useEffect , useCallback , memo , useState , useMemo , useRef } from 'react'
2
2
3
+ import OutboxIcon from '@mui/icons-material/Outbox'
3
4
import { Badge , List , Popover , Drawer } from '@mui/material'
4
5
import clsx from 'clsx'
5
6
import { useDispatch , useSelector } from 'react-redux'
6
7
8
+ import { AlertModal } from '@/main/components/modals'
7
9
import { alarmNoticeSelector } from '@/modules/alarmNotice'
8
- import { categorySelector } from '@/modules/category'
10
+ import { categorySelector , useCategories } from '@/modules/category'
9
11
import { useHistoryLinks } from '@/modules/historyLink'
10
- import { uiSelector } from '@/modules/ui '
12
+ import { createBookmark , createBookmarkFolder } from '@/utils/chromeApis/bookmarks '
11
13
import alarmImg from '@assets/images/alarm.png'
12
14
import historyImg from '@assets/images/history.png'
13
15
import personImg from '@assets/images/person.png'
14
16
import useDebounce from '@hooks/useDebounce'
15
17
import SearchBar from '@main/components/SearchBar'
16
- import { linkSearchFilterChangeState } from '@modules/link'
18
+ import { linkSearchFilterChangeState , linkSelector , linksReadThunk , useLinks } from '@modules/link'
19
+ import { uiSelector , useToast , useDialog , MODAL_NAME } from '@modules/ui'
17
20
import { GAEvent } from '@utils/ga'
18
21
19
22
import AlarmList from './AlarmList'
@@ -33,7 +36,15 @@ function AppBar() {
33
36
const category = useSelector ( categorySelector . selectedCategory )
34
37
const alarmList = useSelector ( alarmNoticeSelector . listData )
35
38
const isAppBarInversion = useSelector ( uiSelector . isAppBarInversion )
36
-
39
+ const { categories } = useCategories ( )
40
+ const links = useSelector ( ( state ) => linkSelector . linksData ( state ) )
41
+ const { openToast } = useToast ( )
42
+
43
+ const {
44
+ open : migrateBookmarksOpen ,
45
+ toggle : migrateBookmarksToggle ,
46
+ close : migrateBookmarksClose ,
47
+ } = useDialog ( MODAL_NAME . BOOKMARKS_MIGRATION_MODAL )
37
48
const { reload } = useHistoryLinks ( )
38
49
39
50
const notReadAlarmList = useMemo ( ( ) => {
@@ -46,6 +57,7 @@ function AppBar() {
46
57
const [ isHistoryOpen , setIsHistoryOpen ] = useState ( false )
47
58
const [ isAlarmOpen , setIsAlarmOpen ] = useState ( false )
48
59
const [ isProfileOpen , setIsProfileOpen ] = useState ( false )
60
+ const [ isReadyForMigration , setIsReadyForMigration ] = useState ( false )
49
61
50
62
const [ selectedName , setSelectedName ] = useState ( SEARCH_FILTER_LIST [ 0 ] . search )
51
63
const [ keyword , setKeyword ] = useState ( '' )
@@ -68,10 +80,48 @@ function AppBar() {
68
80
[ handleResetInput ]
69
81
)
70
82
83
+ const fetchAllLinkData = async ( ) => {
84
+ //λ‘λ© μ²λ¦¬ νμ
85
+ migrateBookmarksClose ( )
86
+ if ( categories . length ) {
87
+ for ( const category of categories ) {
88
+ await dispatch ( linksReadThunk ( { categoryId : category . id } , { key : category . id } ) )
89
+ }
90
+ }
91
+ setIsReadyForMigration ( true )
92
+ }
93
+
94
+ const handleMigrateBookmarks = useCallback ( ( ) => {
95
+ const callback = ( urlinkFolderId ) => {
96
+ for ( const category of categories ) {
97
+ //μΉ΄ν
κ³ λ¦¬ λ³λ‘ λΆλ§ν¬ ν΄λ μμ±
98
+ createBookmarkFolder ( { id : urlinkFolderId , title : category . name } , ( id ) => {
99
+ for ( const link of links [ category . id ] ) {
100
+ //μΉ΄ν
κ³ λ¦¬ λΆλ§ν¬ ν΄λ λ΄μ λ§ν¬ μ½μ
101
+ createBookmark ( {
102
+ id,
103
+ title : link . title ,
104
+ url : link . path ,
105
+ } )
106
+ }
107
+ } )
108
+ }
109
+
110
+ setIsReadyForMigration ( false )
111
+ openToast ( { type : 'success' , message : 'μ΄λμ΄ μλ£λμμ΅λλ€. λΆλ§ν¬λ₯Ό νμΈν΄μ£ΌμΈμ.' } )
112
+ }
113
+ //μ μ΄λ§ν¬ λΆλ§ν¬ ν΄λ μμ±
114
+ createBookmarkFolder ( { id : '1' , title : 'urLink Bookmarks' } , callback )
115
+ } , [ links , categories , openToast ] )
116
+
71
117
useEffect ( ( ) => {
72
118
dispatch ( linkSearchFilterChangeState ( { selectedName, keyword : debouncedKeyword } ) )
73
119
} , [ dispatch , selectedName , debouncedKeyword ] )
74
120
121
+ useEffect ( ( ) => {
122
+ if ( isReadyForMigration ) handleMigrateBookmarks ( )
123
+ } , [ isReadyForMigration , handleMigrateBookmarks ] )
124
+
75
125
return (
76
126
< >
77
127
< div
@@ -91,6 +141,17 @@ function AppBar() {
91
141
disabled = { ! category ?. id || isHistoryOpen }
92
142
/>
93
143
< List className = { classes . iconButtonGroup } >
144
+ < StyledListItem
145
+ button
146
+ aria-describedby = "bookmarks"
147
+ onClick = { ( ) => {
148
+ migrateBookmarksToggle ( )
149
+ GAEvent ( 'μ±λ°' , 'λΆλ§ν¬ μ΄λ λ²νΌ ν΄λ¦' )
150
+ } }
151
+ >
152
+ < OutboxIcon />
153
+ </ StyledListItem >
154
+
94
155
< StyledListItem
95
156
button
96
157
aria-describedby = "history-drawer"
@@ -155,6 +216,16 @@ function AppBar() {
155
216
</ List >
156
217
</ div >
157
218
219
+ { migrateBookmarksOpen && (
220
+ < AlertModal
221
+ openBool = { migrateBookmarksOpen }
222
+ btnYesText = "μ΄λ"
223
+ contentText = "λͺ¨λ λ§ν¬λ₯Ό λΆλ§ν¬λ‘ μ΄λνμκ² μ΅λκΉ?"
224
+ handleClose = { migrateBookmarksClose }
225
+ handleYesClick = { fetchAllLinkData }
226
+ />
227
+ ) }
228
+
158
229
< Drawer
159
230
className = { classes . drawer }
160
231
variant = "persistent"
0 commit comments