readme file is now rendering in repo. can now view files and edit them. can switch between branches with dropdown menu

This commit is contained in:
2026-05-07 11:28:06 +02:00
parent 779a1fdb82
commit dad82a79de
41 changed files with 2463 additions and 141 deletions
+51
View File
@@ -33,10 +33,23 @@ const treeEntrySchema = z.object({
type: z.enum(['blob', 'tree']),
hash: z.string(),
name: z.string(),
size: z.number().default(0),
commitHash: z.string().default(''),
commitMsg: z.string().default(''),
commitDate: z.string().default(''),
})
const treeSchema = z.array(treeEntrySchema)
const blobSchema = z.object({
content: z.string(),
path: z.string(),
ref: z.string(),
})
const branchSchema = z.object({ name: z.string() })
const branchesSchema = z.array(branchSchema)
export function useRepos() {
return useQuery({
queryKey: ['repos'],
@@ -98,6 +111,44 @@ export function useDeleteRepo(owner: string, name: string) {
})
}
export function useRepoBranches(owner: string, name: string) {
return useQuery({
queryKey: ['repos', owner, name, 'branches'],
queryFn: () =>
api.get<{ name: string }[]>(`/api/v1/repos/${owner}/${name}/branches`, branchesSchema),
enabled: Boolean(owner && name),
})
}
export function useRepoBlob(owner: string, name: string, ref: string, path: string) {
return useQuery({
queryKey: ['repos', owner, name, 'blob', ref, path],
queryFn: () =>
api.get<{ content: string; path: string; ref: string }>(
`/api/v1/repos/${owner}/${name}/blob?ref=${encodeURIComponent(ref)}&path=${encodeURIComponent(path)}`,
blobSchema,
),
enabled: Boolean(owner && name && ref && path),
})
}
export function useUpdateBlob(owner: string, name: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (data: { path: string; content: string; message: string; branch: string }) =>
api.put<{ status: string }>(
`/api/v1/repos/${owner}/${name}/blob`,
z.object({ status: z.string() }),
data,
),
onSuccess: (_data, vars) => {
queryClient.invalidateQueries({ queryKey: ['repos', owner, name, 'blob', vars.branch, vars.path] })
queryClient.invalidateQueries({ queryKey: ['repos', owner, name, 'tree'] })
queryClient.invalidateQueries({ queryKey: ['repos', owner, name, 'commits'] })
},
})
}
export function useCreateRepo() {
const queryClient = useQueryClient()
return useMutation({