mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-04-24 20:07:51 +00:00
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import React, { useCallback, useEffect } from 'react'
|
|
import { useSetRecoilState } from 'recoil';
|
|
import { settingsLocalLastUpdatedAtom, sortablePinnedAppsAtom } from './atoms/global';
|
|
|
|
function fetchFromLocalStorage(key) {
|
|
try {
|
|
const serializedValue = localStorage.getItem(key);
|
|
if (serializedValue === null) {
|
|
return null;
|
|
}
|
|
return JSON.parse(serializedValue);
|
|
} catch (error) {
|
|
console.error('Error fetching from localStorage:', error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export const useRetrieveDataLocalStorage = () => {
|
|
const setSortablePinnedApps = useSetRecoilState(sortablePinnedAppsAtom);
|
|
const setSettingsLocalLastUpdated = useSetRecoilState(settingsLocalLastUpdatedAtom);
|
|
|
|
const getSortablePinnedApps = useCallback(()=> {
|
|
const pinnedAppsLocal = fetchFromLocalStorage('ext_saved_settings')
|
|
if(pinnedAppsLocal?.sortablePinnedApps){
|
|
setSortablePinnedApps(pinnedAppsLocal?.sortablePinnedApps)
|
|
}
|
|
setSettingsLocalLastUpdated(pinnedAppsLocal?.timestamp || -1)
|
|
}, [])
|
|
useEffect(()=> {
|
|
|
|
getSortablePinnedApps()
|
|
}, [getSortablePinnedApps])
|
|
|
|
}
|