Skip to content

Commit 27700e8

Browse files
resolving issues on switching tabs
1 parent cf7ddb5 commit 27700e8

File tree

3 files changed

+49
-28
lines changed

3 files changed

+49
-28
lines changed

interface/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ export interface iconSetStateType {
134134
showPanel: boolean
135135
searchValue: string
136136
tab: string
137-
staticHistory: string
138-
animatedHistory: string
137+
staticHistory: SelectedIconType
138+
animatedHistory: SelectedIconType
139139
selectMultiple: boolean
140140
emptySearchResult: boolean
141141
suggestedString: string

tsconfig.tsbuildinfo

+1-1
Large diffs are not rendered by default.

utils/IconSet.store.ts

+46-25
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const iconSetState: iconSetStateType = {
1414
showPanel: false,
1515
searchValue: '',
1616
tab: 'Static Icons',
17-
staticHistory: '',
18-
animatedHistory: '',
17+
staticHistory: { name: '', tags: [] },
18+
animatedHistory: { name: '', tags: [] },
1919
selectMultiple: true,
2020
emptySearchResult: false,
2121
suggestedString: '',
@@ -41,8 +41,8 @@ export const iconSetHelper = {
4141
showPanel: false,
4242
searchValue: '',
4343
tab: 'Static Icons',
44-
staticHistory: '',
45-
animatedHistory: '',
44+
staticHistory: { name: '', tags: [] },
45+
animatedHistory: { name: '', tags: [] },
4646
selectMultiple: true,
4747
emptySearchResult: false,
4848
suggestedString: '',
@@ -173,7 +173,7 @@ export const iconSetHelper = {
173173
return {
174174
emptySearchResult: false,
175175
...iconSetHelper.closeHowTo(router),
176-
searchValue: suggestedString
176+
searchValue: suggestedString || ''
177177
}
178178
},
179179

@@ -217,7 +217,7 @@ export const iconSetHelper = {
217217
return {
218218
showPanel: true,
219219
iconSelected: iconObj,
220-
searchValue: iconObj.name,
220+
searchValue: iconObj.name || '',
221221
tab: tabType === 'static' ? 'Static Icons' : 'Animated Icons'
222222
}
223223
}
@@ -247,6 +247,7 @@ export const iconSetHelper = {
247247
return {
248248
showPanel: !setIconSelected,
249249
iconSelected: setIconSelected ? '' : iconObj,
250+
staticHistory: setIconSelected ? { name: '', tags: [] } : iconObj,
250251
searchValue: setIconSelected ? '' : iconObj.name
251252
}
252253
}
@@ -270,6 +271,11 @@ export const iconSetHelper = {
270271
JSON.stringify(iconSelected)
271272
? { name: '', tags: [] }
272273
: { name: icon, tags: [] },
274+
animatedHistory:
275+
JSON.stringify({ name: icon, tags: [] }) ===
276+
JSON.stringify(iconSelected)
277+
? { name: '', tags: [] }
278+
: { name: icon, tags: [] },
273279
showPanel:
274280
JSON.stringify({ name: icon, tags: [] }) !==
275281
JSON.stringify(iconSelected),
@@ -291,49 +297,64 @@ export const iconSetHelper = {
291297
e: string,
292298
tab: string,
293299
iconSelected: SelectedIconType,
294-
staticHistory: string,
295-
animatedHistory: string,
300+
staticHistory: SelectedIconType,
301+
animatedHistory: SelectedIconType,
296302
searchValue: string,
297303
router: Router
298304
) => {
299305
if (e !== tab) {
300306
if (e === 'Static Icons') {
301-
if (staticHistory === '') {
302-
const storeSearchValue = searchValue
307+
if (
308+
JSON.stringify(staticHistory) !==
309+
JSON.stringify({ name: '', tags: [] })
310+
) {
311+
router.push(
312+
{
313+
query: { iconName: staticHistory.name, type: 'static' }
314+
},
315+
undefined,
316+
{ scroll: false }
317+
)
303318
return {
304319
tab: e,
305-
animatedHistory: iconSelected,
306-
...iconSetHelper.closeHowTo(router),
307-
searchValue: storeSearchValue
320+
iconSelected: staticHistory,
321+
showPanel: true,
322+
searchValue: staticHistory.name || ''
308323
}
309324
} else {
325+
router.push('/', undefined, { scroll: false })
310326
return {
311327
tab: e,
312-
animatedHistory: iconSelected,
313-
iconsSelected: staticHistory,
314-
showPanel: true
328+
...iconSetHelper.closeHowTo(router)
315329
}
316330
}
317331
} else {
318-
if (animatedHistory === '') {
319-
const storeSearchValue = searchValue
332+
if (
333+
JSON.stringify(animatedHistory) !==
334+
JSON.stringify({ name: '', tags: [] })
335+
) {
336+
router.push(
337+
{
338+
query: { iconName: animatedHistory.name, type: 'animated' }
339+
},
340+
undefined,
341+
{ scroll: false }
342+
)
320343
return {
321344
tab: e,
322-
staticHistory: iconSelected,
323-
...iconSetHelper.closeHowTo(router),
324-
searchValue: storeSearchValue
345+
iconSelected: animatedHistory,
346+
showPanel: true,
347+
searchValue: animatedHistory.name || ''
325348
}
326349
} else {
350+
router.push('/', undefined, { scroll: false })
327351
return {
328352
tab: e,
329-
staticHistory: iconSelected,
330-
iconsSelected: animatedHistory,
331-
showPanel: true
353+
...iconSetHelper.closeHowTo(router)
332354
}
333355
}
334356
}
335357
}
336-
return { iconsSelected: iconSelected }
337358
},
338359

339360
getWords: (values: string) => {

0 commit comments

Comments
 (0)