A deployable markdown editor that connects with your self hosted files and lets you edit in a beautiful interface
1import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
2import { branchApi, type PublishParams } from '../api/branch';
3
4export function useBranchStatus(owner: string, repo: string) {
5 return useQuery({
6 queryKey: ['branchStatus', owner, repo],
7 queryFn: () => branchApi.getBranchStatus(owner, repo),
8 enabled: !!owner && !!repo,
9 refetchInterval: 30000, // Refetch every 30 seconds
10 });
11}
12
13export function usePublish() {
14 const queryClient = useQueryClient();
15
16 return useMutation({
17 mutationFn: (params: PublishParams) => branchApi.publish(params),
18 onSuccess: (_, variables) => {
19 // Invalidate branch status, file content, and pending changes queries
20 queryClient.invalidateQueries({
21 queryKey: ['branchStatus', variables.owner, variables.repo],
22 });
23 queryClient.invalidateQueries({
24 queryKey: ['fileContent'],
25 });
26 queryClient.invalidateQueries({
27 queryKey: ['pending-changes', variables.owner, variables.repo],
28 });
29 queryClient.invalidateQueries({
30 queryKey: ['files', variables.owner, variables.repo],
31 });
32 },
33 });
34}