mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
619 restructure local storage (#628)
* To MMKV migration working * POC migrated font size settings * Moved settings to mmkv * Fix typos * Migrated contexts slice * Migrated app slice * POC instance emoji update * Migrated drafts * Migrated simple instance properties * All migrated! * Re-structure files * Tolerant of undefined settings * Can properly logging in and out including empty state
This commit is contained in:
27
src/utils/queryHooks/preferences.ts
Normal file
27
src/utils/queryHooks/preferences.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
import apiInstance from '@utils/api/instance'
|
||||
import { getAccountStorage, setAccountStorage } from '@utils/storage/actions'
|
||||
import { AxiosError } from 'axios'
|
||||
|
||||
export type QueryKeyPreferences = ['Preferences']
|
||||
|
||||
const queryFunction = () =>
|
||||
apiInstance<Mastodon.Preferences>({
|
||||
method: 'get',
|
||||
url: 'preferences'
|
||||
}).then(res => res.body)
|
||||
|
||||
const usePreferencesQuery = (params?: {
|
||||
options: UseQueryOptions<Mastodon.Preferences, AxiosError>
|
||||
}) => {
|
||||
const queryKey: QueryKeyPreferences = ['Preferences']
|
||||
return useQuery(queryKey, queryFunction, {
|
||||
...params?.options,
|
||||
staleTime: Infinity,
|
||||
cacheTime: Infinity,
|
||||
initialData: getAccountStorage.object('preferences'),
|
||||
onSuccess: data => setAccountStorage([{ key: 'preferences', value: data }])
|
||||
})
|
||||
}
|
||||
|
||||
export { usePreferencesQuery }
|
Reference in New Issue
Block a user