clean
This commit is contained in:
35
frontend/src/api/api.ts
Normal file
35
frontend/src/api/api.ts
Normal 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,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user