From 955dadc604e5f7868ba74aea500bde47cbc2e7f5 Mon Sep 17 00:00:00 2001 From: Fusion Date: Tue, 19 May 2026 14:27:22 +0200 Subject: [PATCH] fix: correct API endpoint URLs in workspace file browser The workspace was using /api/projects/... but the API routes are mounted at /projects without the /api prefix. Switched from raw fetch() to the apiClient which already has the correct baseURL configured. Also fixed TypeScript types and removed unused variables. --- apps/web/src/pages/repo-workspace.tsx | 61 ++++++++++++++++----------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/apps/web/src/pages/repo-workspace.tsx b/apps/web/src/pages/repo-workspace.tsx index 71a9a91..57c4e02 100644 --- a/apps/web/src/pages/repo-workspace.tsx +++ b/apps/web/src/pages/repo-workspace.tsx @@ -1,15 +1,29 @@ import { useCallback, useEffect, useState } from "react"; -import { Link, useNavigate, useParams, useSearchParams } from "react-router-dom"; +import { Link, useParams, useSearchParams } from "react-router-dom"; +import { apiClient } from "../api/client"; import { listRepositories, type GitRepository } from "../api/git_repositories"; type WorkspaceStatus = "loading" | "ready" | "error" | "empty"; +interface FileTreeEntry { + name: string; + type: "file" | "directory"; + path: string; + size?: number; + mode?: string; + last_commit?: { + hash: string; + message: string; + author: string; + date: string; + } | null; +} + export const RepoWorkspace = () => { const { projectId } = useParams<{ projectId: string }>(); const [searchParams, setSearchParams] = useSearchParams(); - const navigate = useNavigate(); const [status, setStatus] = useState("loading"); const [repositories, setRepositories] = useState([]); @@ -151,7 +165,7 @@ const FileBrowser = ({ repoId: string; }) => { const [searchParams, setSearchParams] = useSearchParams(); - const [entries, setEntries] = useState([]); + const [entries, setEntries] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); @@ -162,17 +176,16 @@ const FileBrowser = ({ setLoading(true); setError(null); try { - const response = await fetch( - `/api/projects/${projectId}/repositories/${repoId}/files?branch=${encodeURIComponent( - branch - )}&path=${encodeURIComponent(path)}`, - { credentials: "include" } + const response = await apiClient.get( + `/projects/${projectId}/repositories/${repoId}/files`, + { + params: { + branch, + path, + }, + } ); - if (!response.ok) { - throw new Error("Failed to load files"); - } - const data = await response.json(); - setEntries(data.entries || []); + setEntries(response.data.entries || []); } catch { setError("Failed to load files"); } finally { @@ -184,7 +197,7 @@ const FileBrowser = ({ void loadFiles(); }, [loadFiles]); - const handleEntryClick = (entry: any) => { + const handleEntryClick = (entry: FileTreeEntry) => { if (entry.type === "directory") { const newParams = new URLSearchParams(searchParams); newParams.set("path", entry.path); @@ -240,7 +253,7 @@ const FileViewer = ({ projectId: string; repoId: string; }) => { - const [searchParams, setSearchParams] = useSearchParams(); + const [searchParams] = useSearchParams(); const [content, setContent] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); @@ -258,16 +271,16 @@ const FileViewer = ({ setLoading(true); setError(null); try { - const response = await fetch( - `/api/projects/${projectId}/repositories/${repoId}/files/content?branch=${encodeURIComponent( - branch - )}&path=${encodeURIComponent(filePath)}`, - { credentials: "include" } + const response = await apiClient.get( + `/projects/${projectId}/repositories/${repoId}/files/content`, + { + params: { + branch, + path: filePath, + }, + } ); - if (!response.ok) { - throw new Error("Failed to load file"); - } - const data = await response.json(); + const data = response.data; if (data.is_binary) { setIsBinary(true); setContent("Binary file - cannot display");