refactor: rewrite useVersion and healthcheck with RQ
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user