Initial Commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '../api';
|
||||
|
||||
export function useCalendar(months?: number) {
|
||||
return useQuery({
|
||||
queryKey: ['calendar', months],
|
||||
queryFn: () => api.calendar.get(months),
|
||||
staleTime: 60 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCalendarDate(date: string) {
|
||||
return useQuery({
|
||||
queryKey: ['calendar-date', date],
|
||||
queryFn: () => api.calendar.getDate(date),
|
||||
enabled: !!date,
|
||||
staleTime: 60 * 60_000,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '../api';
|
||||
|
||||
export function useHorizon() {
|
||||
return useQuery({
|
||||
queryKey: ['horizon'],
|
||||
queryFn: () => api.horizon.get(),
|
||||
staleTime: 5 * 60_000,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { api } from '../api';
|
||||
import type { LogEntry } from '../api/types';
|
||||
|
||||
export function useLog(page?: number) {
|
||||
return useQuery({
|
||||
queryKey: ['log', page],
|
||||
queryFn: () => api.log.list(page),
|
||||
});
|
||||
}
|
||||
|
||||
export function useTargetLog(catalogId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['target-log', catalogId],
|
||||
queryFn: () => api.log.forTarget(catalogId),
|
||||
enabled: !!catalogId,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateLog() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (entry: Omit<LogEntry, 'id' | 'created_at' | 'target_name' | 'target_common_name' | 'target_obj_type'>) =>
|
||||
api.log.create(entry),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['log'] });
|
||||
qc.invalidateQueries({ queryKey: ['target-log'] });
|
||||
qc.invalidateQueries({ queryKey: ['stats'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateLog() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: number; data: Partial<LogEntry> }) =>
|
||||
api.log.update(id, data),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['log'] });
|
||||
qc.invalidateQueries({ queryKey: ['target-log'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteLog() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => api.log.delete(id),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['log'] });
|
||||
qc.invalidateQueries({ queryKey: ['target-log'] });
|
||||
qc.invalidateQueries({ queryKey: ['stats'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '../api';
|
||||
|
||||
export function useStats() {
|
||||
return useQuery({
|
||||
queryKey: ['stats'],
|
||||
queryFn: () => api.stats.get(),
|
||||
staleTime: 5 * 60_000,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { api, type TargetsParams } from '../api';
|
||||
|
||||
export function useTargets(params: TargetsParams = {}) {
|
||||
return useQuery({
|
||||
queryKey: ['targets', params],
|
||||
queryFn: () => api.targets.list(params),
|
||||
staleTime: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTarget(id: string) {
|
||||
return useQuery({
|
||||
queryKey: ['target', id],
|
||||
queryFn: () => api.targets.get(id),
|
||||
enabled: !!id,
|
||||
staleTime: 5 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTargetVisibility(id: string) {
|
||||
return useQuery({
|
||||
queryKey: ['target-visibility', id],
|
||||
queryFn: () => api.targets.visibility(id),
|
||||
enabled: !!id,
|
||||
staleTime: 5 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTargetCurve(id: string) {
|
||||
return useQuery({
|
||||
queryKey: ['target-curve', id],
|
||||
queryFn: () => api.targets.curve(id),
|
||||
enabled: !!id,
|
||||
staleTime: 5 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTargetFilters(id: string) {
|
||||
return useQuery({
|
||||
queryKey: ['target-filters', id],
|
||||
queryFn: () => api.targets.filters(id),
|
||||
enabled: !!id,
|
||||
staleTime: 5 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTargetWorkflow(id: string, filterId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['target-workflow', id, filterId],
|
||||
queryFn: () => api.targets.workflow(id, filterId),
|
||||
enabled: !!id && !!filterId,
|
||||
staleTime: 60 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTargetYearly(id: string, enabled = false) {
|
||||
return useQuery({
|
||||
queryKey: ['target-yearly', id],
|
||||
queryFn: () => api.targets.yearly(id),
|
||||
enabled: !!id && enabled,
|
||||
staleTime: 60 * 60_000,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '../api';
|
||||
|
||||
export function useTonight() {
|
||||
return useQuery({
|
||||
queryKey: ['tonight'],
|
||||
queryFn: () => api.tonight.get(),
|
||||
staleTime: 60_000,
|
||||
refetchInterval: 60_000,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '../api';
|
||||
|
||||
export function useWeather() {
|
||||
return useQuery({
|
||||
queryKey: ['weather'],
|
||||
queryFn: () => api.weather.get(),
|
||||
staleTime: 15 * 60_000,
|
||||
refetchInterval: 15 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useForecast() {
|
||||
return useQuery({
|
||||
queryKey: ['forecast'],
|
||||
queryFn: () => api.weather.forecast(),
|
||||
staleTime: 3 * 60 * 60_000,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user