This commit is contained in:
KS Jannette
2026-02-13 15:27:10 -05:00
parent 1a85c6e1e0
commit a720673896
2 changed files with 0 additions and 0 deletions

35
frontend/src/api/api.ts Normal file
View File

@@ -0,0 +1,35 @@
import { useQuery, useMutation } from '@tanstack/react-query';
import type { Sticky, Cluster } from '../types/types';
const API_BASE = 'http://localhost:3001/v1/notes';
const fetchStickies = async (): Promise<Sticky[]> => {
const response = await fetch(API_BASE);
if (!response.ok) {
throw new Error('Failed to fetch stickies');
}
return response.json();
};
const fetchClusters = async (): Promise<Cluster[]> => {
const response = await fetch(`${API_BASE}/cluster`, {
method: 'POST',
});
if (!response.ok) {
throw new Error('Failed to cluster stickies');
}
return response.json();
};
export const useGetStickies = () => {
return useQuery<Sticky[]>({
queryKey: ['stickies'],
queryFn: fetchStickies,
});
};
export const useClusterStickies = () => {
return useMutation<Cluster[]>({
mutationFn: fetchClusters,
});
};