A deployable markdown editor that connects with your self hosted files and lets you edit in a beautiful interface
at main 24 lines 846 B view raw
1import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; 2import { filesApi, type UpdateFileParams } from '../api/files'; 3 4export function useFileContent(owner: string, repo: string, path: string, branch?: string) { 5 return useQuery({ 6 queryKey: ['fileContent', owner, repo, path, branch], 7 queryFn: () => filesApi.getFileContent(owner, repo, path, branch), 8 enabled: !!owner && !!repo && !!path, 9 }); 10} 11 12export function useUpdateFile() { 13 const queryClient = useQueryClient(); 14 15 return useMutation({ 16 mutationFn: (params: UpdateFileParams) => filesApi.updateFile(params), 17 onSuccess: (_, variables) => { 18 // Invalidate the file content query to refetch 19 queryClient.invalidateQueries({ 20 queryKey: ['fileContent', variables.owner, variables.repo, variables.path], 21 }); 22 }, 23 }); 24}