mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Remove redundant API_BASE constants and improve mobile UI layout
This commit is contained in:
1 parent
6c88f23b5f
commit
07d78450be
6 files changed
+50
-51
No files matched your search
@@ -2,10 +2,8 @@ import { useQuery } from '@tanstack/react-query'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { FileInfo, ChunkedFileInfo, PatchOperation } from '@/types/files'
|
||||
|
||||
const API_BASE = API_BASE_URL
|
||||
|
||||
async function fetchFile(path: string): Promise<FileInfo> {
|
||||
const response = await fetch(`${API_BASE}/api/files/${path}`)
|
||||
const response = await fetch(`${API_BASE_URL}/api/files/${path}`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load file: ${response.statusText}`)
|
||||
@@ -23,7 +21,7 @@ export function useFile(path: string | undefined) {
|
||||
}
|
||||
|
||||
export async function fetchFileRange(path: string, startLine: number, endLine: number): Promise<ChunkedFileInfo> {
|
||||
const response = await fetch(`${API_BASE}/api/files/${path}?startLine=${startLine}&endLine=${endLine}`)
|
||||
const response = await fetch(`${API_BASE_URL}/api/files/${path}?startLine=${startLine}&endLine=${endLine}`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load file range: ${response.statusText}`)
|
||||
@@ -33,7 +31,7 @@ export async function fetchFileRange(path: string, startLine: number, endLine: n
|
||||
}
|
||||
|
||||
export async function applyFilePatches(path: string, patches: PatchOperation[]): Promise<{ success: boolean; totalLines: number }> {
|
||||
const response = await fetch(`${API_BASE}/api/files/${path}`, {
|
||||
const response = await fetch(`${API_BASE_URL}/api/files/${path}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ patches }),
|
||||
|
||||
@@ -2,10 +2,8 @@ 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`)
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/status`)
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Failed to fetch git status' }))
|
||||
@@ -16,7 +14,7 @@ export async function fetchGitStatus(repoId: number): Promise<GitStatusResponse>
|
||||
}
|
||||
|
||||
export async function fetchFileDiff(repoId: number, path: string): Promise<FileDiffResponse> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${repoId}/git/diff?path=${encodeURIComponent(path)}`)
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/diff?path=${encodeURIComponent(path)}`)
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Failed to fetch file diff' }))
|
||||
|
||||
+11
-13
@@ -1,15 +1,13 @@
|
||||
import type { Repo } from './types'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
|
||||
const API_BASE = API_BASE_URL
|
||||
|
||||
export async function createRepo(
|
||||
repoUrl: string,
|
||||
branch?: string,
|
||||
openCodeConfigName?: string,
|
||||
useWorktree?: boolean
|
||||
): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE}/api/repos`, {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ repoUrl, branch, openCodeConfigName, useWorktree }),
|
||||
@@ -24,7 +22,7 @@ export async function createRepo(
|
||||
}
|
||||
|
||||
export async function listRepos(): Promise<Repo[]> {
|
||||
const response = await fetch(`${API_BASE}/api/repos`)
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to list repos')
|
||||
@@ -34,7 +32,7 @@ export async function listRepos(): Promise<Repo[]> {
|
||||
}
|
||||
|
||||
export async function getRepo(id: number): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}`)
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get repo')
|
||||
@@ -44,7 +42,7 @@ export async function getRepo(id: number): Promise<Repo> {
|
||||
}
|
||||
|
||||
export async function deleteRepo(id: number): Promise<void> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}`, {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
|
||||
@@ -54,7 +52,7 @@ export async function deleteRepo(id: number): Promise<void> {
|
||||
}
|
||||
|
||||
export async function startServer(id: number, openCodeConfigName?: string): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}/server/start`, {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/server/start`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ openCodeConfigName }),
|
||||
@@ -68,7 +66,7 @@ export async function startServer(id: number, openCodeConfigName?: string): Prom
|
||||
}
|
||||
|
||||
export async function stopServer(id: number): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}/server/stop`, {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/server/stop`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
@@ -80,7 +78,7 @@ export async function stopServer(id: number): Promise<Repo> {
|
||||
}
|
||||
|
||||
export async function pullRepo(id: number): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}/pull`, {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/pull`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
@@ -92,7 +90,7 @@ export async function pullRepo(id: number): Promise<Repo> {
|
||||
}
|
||||
|
||||
export async function getServerLogs(id: number): Promise<string> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}/server/logs`)
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/server/logs`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get server logs')
|
||||
@@ -102,7 +100,7 @@ export async function getServerLogs(id: number): Promise<string> {
|
||||
}
|
||||
|
||||
export async function switchRepoConfig(id: number, configName: string): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}/config/switch`, {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/config/switch`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ configName }),
|
||||
@@ -117,7 +115,7 @@ export async function switchRepoConfig(id: number, configName: string): Promise<
|
||||
}
|
||||
|
||||
export async function switchBranch(id: number, branch: string): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}/branch/switch`, {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/branch/switch`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ branch }),
|
||||
@@ -132,7 +130,7 @@ export async function switchBranch(id: number, branch: string): Promise<Repo> {
|
||||
}
|
||||
|
||||
export async function listBranches(id: number): Promise<{ local: string[], remote: string[], current: string | null }> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}/branches`)
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/branches`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to list branches')
|
||||
|
||||
@@ -201,7 +201,7 @@ export function FileDiffView({ repoId, filePath, onBack, onOpenFile, isMobile =
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-y-auto min-h-0">
|
||||
<div className="flex-1 overflow-y-auto min-h-0 mb-[85px]">
|
||||
{diffData.isBinary ? (
|
||||
<div className="flex items-center justify-center h-full text-muted-foreground">
|
||||
<p className="text-sm">Binary file - cannot display diff</p>
|
||||
|
||||
@@ -65,7 +65,7 @@ export function GitChangesSheet({ isOpen, onClose, repoId, currentBranch, repoLo
|
||||
className="w-screen h-screen max-w-none max-h-none p-0 bg-background border-0 flex flex-col"
|
||||
hideCloseButton
|
||||
>
|
||||
<div className="flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0">
|
||||
<div className="flex items-center justify-between px-4 sm:py-3 border-b border-border flex-shrink-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<GitBranch className="w-4 h-4 text-blue-400" />
|
||||
<h2 className="text-sm font-semibold text-foreground">
|
||||
|
||||
+32
-27
@@ -1,37 +1,42 @@
|
||||
import path from "path";
|
||||
import { defineConfig } from "vite";
|
||||
import { defineConfig, loadEnv } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
|
||||
export default defineConfig({
|
||||
envDir: path.resolve(__dirname, ".."),
|
||||
plugins: [react(), tailwindcss()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "./src"),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
host: "0.0.0.0",
|
||||
port: 5173,
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: "http://localhost:5003",
|
||||
changeOrigin: true,
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, path.resolve(__dirname, ".."), "");
|
||||
const backendPort = env.PORT || 5001;
|
||||
|
||||
return {
|
||||
envDir: path.resolve(__dirname, ".."),
|
||||
plugins: [react(), tailwindcss()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "./src"),
|
||||
},
|
||||
},
|
||||
},
|
||||
build: {
|
||||
assetsInlineLimit: 4096,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
assetFileNames: (assetInfo) => {
|
||||
if (assetInfo.name === "manifest.json") {
|
||||
return "manifest.json";
|
||||
}
|
||||
return "assets/[name]-[hash][extname]";
|
||||
server: {
|
||||
host: "0.0.0.0",
|
||||
port: 5173,
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: `http://localhost:${backendPort}`,
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
build: {
|
||||
assetsInlineLimit: 4096,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
assetFileNames: (assetInfo) => {
|
||||
if (assetInfo.name === "manifest.json") {
|
||||
return "manifest.json";
|
||||
}
|
||||
return "assets/[name]-[hash][extname]";
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user