mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add git changes viewer with diff display
- Add backend git-operations service for git status and file diffs - Add git/status and git/diff API routes to repos - Add GitChangesPanel component to list changed files with status - Add FileDiffView component with unified diff rendering - Add GitChangesSheet as full-screen dialog wrapper - Integrate View Changes option into BranchSwitcher dropdown - Support both mobile (stacked) and desktop (split) layouts
This commit is contained in:
1 parent
12b7ab54b2
commit
ed82b99236
8 files changed
+815
-3
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { GitStatusResponse, FileDiffResponse } from '@/types/git'
|
||||
|
||||
const API_BASE = API_BASE_URL
|
||||
|
||||
export async function fetchGitStatus(repoId: number): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${repoId}/git/status`)
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Failed to fetch git status' }))
|
||||
throw new Error(error.error || 'Failed to fetch git status')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function fetchFileDiff(repoId: number, path: string): Promise<FileDiffResponse> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${repoId}/git/diff?path=${encodeURIComponent(path)}`)
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Failed to fetch file diff' }))
|
||||
throw new Error(error.error || 'Failed to fetch file diff')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export function useGitStatus(repoId: number | undefined) {
|
||||
return useQuery({
|
||||
queryKey: ['gitStatus', repoId],
|
||||
queryFn: () => repoId ? fetchGitStatus(repoId) : Promise.reject(new Error('No repo ID')),
|
||||
enabled: !!repoId,
|
||||
refetchInterval: 10000,
|
||||
})
|
||||
}
|
||||
|
||||
export function useFileDiff(repoId: number | undefined, path: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: ['fileDiff', repoId, path],
|
||||
queryFn: () => (repoId && path) ? fetchFileDiff(repoId, path) : Promise.reject(new Error('Missing params')),
|
||||
enabled: !!repoId && !!path,
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user