f0358dbdfe
Implements a read-only repository viewer for remote Gitea repos and local clones. Adds UI/CSS for viewer panels, breadcrumb/branch controls, file table, code/Markdown preview, and readme rendering (frontend/css/components.css, frontend/js/app.js). Extends app state and wiring (state.js, app.js) with viewer actions, branch/content loading, local/remote navigation, and preview helpers (base64 decoding, markdown rendering, syntax highlighting, 256 KB preview limit). Adds Gitea API helpers to fetch repo branches and contents (frontend/js/gitea-api.js) and Tauri JS bindings for local repo operations (tauri-api.js). Implements Rust backend commands to list branches, tree entries, and file contents (with size/binary checks and helper utilities) and wires them into the Tauri command registry (src-tauri/src/lib.rs). Also updates README to mention the new read-only viewer.
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
import { loadSettings, saveSettings } from "./storage.js";
|
|
|
|
const state = {
|
|
settings: loadSettings(),
|
|
selectedRepoPath: "",
|
|
selectedRepoName: "",
|
|
repoSearch: "",
|
|
localRepoPathInput: "",
|
|
cloneUrlInput: "",
|
|
cloneDestinationInput: "",
|
|
commitMessage: "",
|
|
viewer: {
|
|
source: "",
|
|
repoName: "",
|
|
repoPath: "",
|
|
cloneUrl: "",
|
|
defaultBranch: "",
|
|
branch: "",
|
|
branches: [],
|
|
path: "",
|
|
entries: [],
|
|
selectedFile: null,
|
|
readmeFile: null,
|
|
loading: false,
|
|
error: "",
|
|
},
|
|
};
|
|
|
|
export function getState() {
|
|
return state;
|
|
}
|
|
|
|
export function setSettings(nextSettings) {
|
|
state.settings = nextSettings;
|
|
saveSettings(state.settings);
|
|
}
|
|
|
|
export function updateSettings(patch) {
|
|
setSettings({ ...state.settings, ...patch });
|
|
}
|
|
|
|
export function addRecentRepo(path) {
|
|
if (!path) return;
|
|
const current = state.settings.recentRepositories.filter((item) => item !== path);
|
|
const next = [path, ...current].slice(0, 15);
|
|
updateSettings({ recentRepositories: next });
|
|
}
|
|
|
|
export function getActiveServer() {
|
|
const { activeServerId, servers } = state.settings;
|
|
return servers.find((server) => server.id === activeServerId) ?? null;
|
|
}
|