From 6167dfa440aef15a5479043a169778178d3c3a99 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Sat, 14 Feb 2026 10:51:17 -0600 Subject: [PATCH] feat: Add project file tree viewer to Git page Add Files tab with browsable project structure and file content viewer. New components: ProjectTree for navigation, FileViewer for content display. Backend endpoints: /api/git/tree and /api/git/file. --- frontend/src/components/git/FileViewer.vue | 308 ++++++++++++++++++++ frontend/src/components/git/ProjectTree.vue | 290 ++++++++++++++++++ frontend/src/components/git/index.ts | 2 + frontend/src/composables/git/useGitApi.ts | 47 ++- frontend/src/pages/GitPage.vue | 171 ++++++++++- frontend/src/types/git.ts | 15 + server/routes/git.ts | 132 ++++++++- server/routes/index.ts | 10 +- 8 files changed, 968 insertions(+), 7 deletions(-) create mode 100644 frontend/src/components/git/FileViewer.vue create mode 100644 frontend/src/components/git/ProjectTree.vue diff --git a/frontend/src/components/git/FileViewer.vue b/frontend/src/components/git/FileViewer.vue new file mode 100644 index 0000000..c97f80a --- /dev/null +++ b/frontend/src/components/git/FileViewer.vue @@ -0,0 +1,308 @@ + + + + + diff --git a/frontend/src/components/git/ProjectTree.vue b/frontend/src/components/git/ProjectTree.vue new file mode 100644 index 0000000..93fb578 --- /dev/null +++ b/frontend/src/components/git/ProjectTree.vue @@ -0,0 +1,290 @@ + + + + + diff --git a/frontend/src/components/git/index.ts b/frontend/src/components/git/index.ts index 5475a23..6cbc7f8 100644 --- a/frontend/src/components/git/index.ts +++ b/frontend/src/components/git/index.ts @@ -2,3 +2,5 @@ export { default as DiffViewer } from './DiffViewer.vue' export { default as FileTree } from './FileTree.vue' export { default as CommitList } from './CommitList.vue' export { default as BranchSelector } from './BranchSelector.vue' +export { default as ProjectTree } from './ProjectTree.vue' +export { default as FileViewer } from './FileViewer.vue' diff --git a/frontend/src/composables/git/useGitApi.ts b/frontend/src/composables/git/useGitApi.ts index 18fd818..0dcb601 100644 --- a/frontend/src/composables/git/useGitApi.ts +++ b/frontend/src/composables/git/useGitApi.ts @@ -1,5 +1,5 @@ import { ref } from 'vue' -import type { GitStatus, CommitInfo, FileDiff, BranchInfo, CompareResult, DiffResult } from '@/types/git' +import type { GitStatus, CommitInfo, FileDiff, BranchInfo, CompareResult, DiffResult, TreeNode, FileContent } from '@/types/git' const API_BASE = '/api/git' @@ -11,6 +11,8 @@ export function useGitApi() { const diff = ref(null) const compareResult = ref(null) const selectedCommit = ref(null) + const fileTree = ref([]) + const fileContent = ref(null) const loading = ref(false) const error = ref(null) @@ -116,6 +118,42 @@ export function useGitApi() { compareResult.value = null } + async function fetchFileTree(path?: string) { + loading.value = true + error.value = null + try { + const params = new URLSearchParams() + if (path) params.set('path', path) + + const res = await fetch(`${API_BASE}/tree?${params}`) + if (!res.ok) throw new Error('Failed to fetch file tree') + fileTree.value = await res.json() + } catch (e: any) { + error.value = e.message + } finally { + loading.value = false + } + } + + async function fetchFileContent(path: string) { + loading.value = true + error.value = null + try { + const params = new URLSearchParams({ path }) + const res = await fetch(`${API_BASE}/file?${params}`) + if (!res.ok) throw new Error('Failed to fetch file content') + fileContent.value = await res.json() + } catch (e: any) { + error.value = e.message + } finally { + loading.value = false + } + } + + function clearFileContent() { + fileContent.value = null + } + return { status, commits, @@ -124,6 +162,8 @@ export function useGitApi() { diff, compareResult, selectedCommit, + fileTree, + fileContent, loading, error, fetchStatus, @@ -133,6 +173,9 @@ export function useGitApi() { fetchBranches, compare, clearDiff, - clearCompare + clearCompare, + fetchFileTree, + fetchFileContent, + clearFileContent } } diff --git a/frontend/src/pages/GitPage.vue b/frontend/src/pages/GitPage.vue index dbead08..bea6bea 100644 --- a/frontend/src/pages/GitPage.vue +++ b/frontend/src/pages/GitPage.vue @@ -1,9 +1,9 @@