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.
This commit is contained in:
Fusion
2026-05-19 14:27:22 +02:00
parent 83f94b1f09
commit 955dadc604
+37 -24
View File
@@ -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<WorkspaceStatus>("loading");
const [repositories, setRepositories] = useState<GitRepository[]>([]);
@@ -151,7 +165,7 @@ const FileBrowser = ({
repoId: string;
}) => {
const [searchParams, setSearchParams] = useSearchParams();
const [entries, setEntries] = useState<any[]>([]);
const [entries, setEntries] = useState<FileTreeEntry[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(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" }
);
if (!response.ok) {
throw new Error("Failed to load files");
const response = await apiClient.get(
`/projects/${projectId}/repositories/${repoId}/files`,
{
params: {
branch,
path,
},
}
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<string | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(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" }
);
if (!response.ok) {
throw new Error("Failed to load file");
const response = await apiClient.get(
`/projects/${projectId}/repositories/${repoId}/files/content`,
{
params: {
branch,
path: filePath,
},
}
const data = await response.json();
);
const data = response.data;
if (data.is_binary) {
setIsBinary(true);
setContent("Binary file - cannot display");