mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +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')
|
||||
|
||||
Reference in new issue
Block a user