refactor: rewrite useVersion and healthcheck with RQ

This commit is contained in:
Rıdvan Akca
2024-03-13 11:39:52 +03:00
parent f07b6d105a
commit 58fcfd9a34
8 changed files with 31 additions and 56 deletions

View File

@@ -1,11 +1,23 @@
import { useQuery } from '@apollo/client';
import { compare } from 'compare-versions';
import { HEALTHCHECK } from 'graphql/queries/healthcheck';
import { useQuery } from '@tanstack/react-query';
import useNotifications from 'hooks/useNotifications';
import api from 'helpers/api';
export default function useVersion() {
const { notifications } = useNotifications();
const { data } = useQuery(HEALTHCHECK, { fetchPolicy: 'cache-and-network' });
const version = data?.healthcheck.version;
const { data } = useQuery({
queryKey: ['automatischVersion'],
queryFn: async ({ signal }) => {
const { data } = await api.get('/v1/automatisch/version', {
signal,
});
return data;
},
});
const version = data?.data?.version;
const newVersionCount = notifications.reduce((count, notification) => {
if (!version) return 0;
// an unexpectedly invalid version would throw and thus, try-catch.
@@ -16,6 +28,7 @@ export default function useVersion() {
return count;
}
}, 0);
return {
version,
newVersionCount,