mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 02:43:50 +00:00
27 lines
922 B
TypeScript
27 lines
922 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { unobfuscate } from 'ontime-utils';
|
|
|
|
import { APP_SETTINGS } from '../api/constants';
|
|
import { getSettings } from '../api/settings';
|
|
import { ontimePlaceholderSettings } from '../models/OntimeSettings';
|
|
|
|
export default function useSettings() {
|
|
const { data, status, isFetching, isError, refetch } = useQuery({
|
|
queryKey: APP_SETTINGS,
|
|
queryFn: ({ signal }) => getSettings({ signal }),
|
|
placeholderData: (previousData, _previousQuery) => previousData,
|
|
select: (data) => {
|
|
const unobfuscated = { ...data };
|
|
if (data.editorKey) {
|
|
unobfuscated.editorKey = unobfuscate(data.editorKey);
|
|
}
|
|
if (data.operatorKey) {
|
|
unobfuscated.operatorKey = unobfuscate(data.operatorKey);
|
|
}
|
|
return unobfuscated;
|
|
},
|
|
});
|
|
|
|
return { data: data ?? ontimePlaceholderSettings, status, isFetching, isError, refetch };
|
|
}
|