ce7f83734a
Enhance UI and dev workflow: add main/right tabbed panels (Repositories/Local and Clone/Settings/Servers), repository owner filter pills (All/Personal/Organizations), org-grouped listing, repo cards, git output and empty-state styling. Introduce new state vars (activeMainTab, activeRightTab, repoOwnerFilter, currentUserLogin) and update event bindings to toggle tabs/filters and focus appropriate panels on actions. Add fetchCurrentUser to gitea-api and use it when loading repositories to distinguish personal vs organization repos (falls back to mock user on error). Update README with development/prerequisites and build instructions and rename npm script "tauri:dev" -> "dev" for running the Tauri dev process.
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
function normalizeServerUrl(serverUrl) {
|
|
return serverUrl.trim().replace(/\/+$/, "");
|
|
}
|
|
|
|
export function buildApiBaseUrl(serverUrl) {
|
|
const normalized = normalizeServerUrl(serverUrl);
|
|
return normalized.endsWith("/api/v1") ? normalized : `${normalized}/api/v1`;
|
|
}
|
|
|
|
export function buildHeaders(serverConfig) {
|
|
const headers = {
|
|
Accept: "application/json",
|
|
};
|
|
|
|
if (serverConfig.authMethod === "token" && serverConfig.token) {
|
|
headers.Authorization = `token ${serverConfig.token}`;
|
|
} else if (
|
|
serverConfig.authMethod === "password" &&
|
|
serverConfig.username &&
|
|
serverConfig.password
|
|
) {
|
|
headers.Authorization = `Basic ${btoa(
|
|
`${serverConfig.username}:${serverConfig.password}`
|
|
)}`;
|
|
}
|
|
|
|
return headers;
|
|
}
|
|
|
|
export async function fetchCurrentUser(serverConfig) {
|
|
const apiBase = buildApiBaseUrl(serverConfig.serverUrl);
|
|
const response = await fetch(`${apiBase}/user`, {
|
|
headers: buildHeaders(serverConfig),
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error(`Gitea API error: ${response.status}`);
|
|
}
|
|
return response.json();
|
|
}
|
|
|
|
export async function fetchRepositories(serverConfig, page = 1, limit = 50) {
|
|
const apiBase = buildApiBaseUrl(serverConfig.serverUrl);
|
|
const url = `${apiBase}/user/repos?page=${page}&limit=${limit}&sort=updated`;
|
|
const response = await fetch(url, {
|
|
headers: buildHeaders(serverConfig),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Gitea API error: ${response.status}`);
|
|
}
|
|
return response.json();
|
|
}
|