-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
3 changed files
with
40 additions
and
17 deletions.
There are no files selected for viewing
17 changes: 10 additions & 7 deletions
17
ui/components/ItemDetail/CandidatureLba/services/getSchema.ts
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,25 +1,41 @@ | ||
export function localStorageSet<T>(key: string, value: T) { | ||
export function storageSet<T>(storage: Storage, key: string, value: T) { | ||
try { | ||
if (window?.localStorage) { | ||
if (storage) { | ||
const serializedValue = typeof value === "string" ? value : JSON.stringify(value) | ||
window.localStorage.setItem(key, serializedValue) | ||
storage.setItem(key, serializedValue) | ||
return true | ||
} | ||
return false | ||
} catch (error) { | ||
console.error(`Error setting localStorage key "${key}":`, error) | ||
console.error(`Error setting storage key "${key}":`, error) | ||
return false | ||
} | ||
} | ||
|
||
export function localStorageGet(key: string): string | null { | ||
export function storageGet(storage: Storage, key: string): string | null { | ||
try { | ||
if (window?.localStorage) { | ||
return window.localStorage.getItem(key) | ||
if (storage) { | ||
return storage.getItem(key) | ||
} | ||
return null | ||
} catch (error) { | ||
console.error(`Error getting localStorage key "${key}":`, error) | ||
console.error(`Error getting storage key "${key}":`, error) | ||
return null | ||
} | ||
} | ||
|
||
export function localStorageSet<T>(key: string, value: T) { | ||
return storageSet(window?.localStorage, key, value) | ||
} | ||
|
||
export function localStorageGet(key: string): string | null { | ||
return storageGet(window?.localStorage, key) | ||
} | ||
|
||
export function sessionStorageSet<T>(key: string, value: T) { | ||
return storageSet(window?.sessionStorage, key, value) | ||
} | ||
|
||
export function sessionStorageGet(key: string): any | null { | ||
return storageGet(window?.sessionStorage, key) | ||
} |