-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
814e16b
commit f973185
Showing
6 changed files
with
106 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,20 @@ | ||
export const generateQueryString = (params: Record<string, any>) => { | ||
return Object.keys(params) | ||
.map((key) => { | ||
if (typeof params[key] === 'object') { | ||
return `${key}=${JSON.stringify(params[key])}`; | ||
} | ||
|
||
return `${key}=${params[key]}`; | ||
}) | ||
.join('&'); | ||
export const setSessionData = (key: string, data: Record<string, any>) => { | ||
sessionStorage.setItem(key, JSON.stringify(data)); | ||
}; | ||
|
||
export const parseQueryString = <T extends Record<string, any>>() => { | ||
const searchParams = new URLSearchParams(window.location.search); | ||
const searchParamsObject = Object.fromEntries(searchParams.entries()); | ||
export const getSessionData = <T extends Record<string, any>>(key: string): T | undefined => { | ||
const data = sessionStorage.getItem(key); | ||
if (!data) { | ||
return undefined; | ||
} | ||
|
||
const parsedObject = Object.entries(searchParamsObject).reduce( | ||
(acc, [key, value]) => { | ||
try { | ||
acc[key] = JSON.parse(value); | ||
} catch { | ||
acc[key] = value; | ||
} | ||
return acc; | ||
}, | ||
{} as Record<string, any>, | ||
); | ||
try { | ||
return JSON.parse(data); | ||
} catch { | ||
return undefined; | ||
} | ||
}; | ||
|
||
return parsedObject as T; | ||
export const clearSessionData = (key: string) => { | ||
sessionStorage.removeItem(key); | ||
}; |