mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 17:03:53 +00:00
1849b4d39f
* chore: migrate eslint to oxlint * chore: migrate prettier to oxfmt * chore: migrate typescript * chore: toThrow should have a expected value * chore: cast test value as Day * chore: small title fix * chore: mocks should be hoisted * chore: incorrect async useage * chore: test should be inside description * chore: test sohuld include an expeced * chore: oxfmt --------- Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { dayInMs } from 'ontime-utils';
|
|
|
|
import { version } from '../../../../../package.json';
|
|
import { isLocalhost } from '../../externals';
|
|
import { APP_VERSION } from '../api/constants';
|
|
import { HasUpdate, getLatestVersion } from '../api/external';
|
|
|
|
const placeholder: HasUpdate & { hasUpdates: boolean } = { url: '', version: '', hasUpdates: false };
|
|
|
|
export default function useAppVersion() {
|
|
const {
|
|
data: fetchData,
|
|
status,
|
|
isFetching,
|
|
isError,
|
|
refetch,
|
|
} = useQuery({
|
|
queryKey: APP_VERSION,
|
|
queryFn: ({ signal }) => getLatestVersion({ signal }),
|
|
placeholderData: (previousData, _previousQuery) => previousData,
|
|
refetchOnWindowFocus: false,
|
|
refetchOnReconnect: false,
|
|
retry: false,
|
|
staleTime: dayInMs,
|
|
enabled: isLocalhost,
|
|
});
|
|
|
|
const hasUpdates = fetchData?.version && !fetchData.version.includes(version);
|
|
|
|
const data = fetchData ? { ...fetchData, hasUpdates } : placeholder;
|
|
|
|
return { data, placeholder, status, isFetching, isError, refetch };
|
|
}
|