feat(phase4): Quick Edit, Contents API commit flow, editor workspace
- portable UTF-8 base64 helpers (Hermes-safe), used for file round-trips - endpoints: updateFileContents, createFileContents, createPull - hooks: useCommitFile (invalidates repo cache), useCreatePull - FileEdit screen: native monospace editor, dirty/discard, branch picker, commit-to-new-branch, protected-branch handling, post-commit PR creation; stale-SHA 409 surfaces as a conflict message - settings: editor URL template; repo overview 'Open in editor' (no token) - tests: base64 round-trips (accents/emoji), editor URL expansion
This commit is contained in:
1 parent
ddd834b7ac
commit
c9dd49446a
18 files changed
+733
-29
No files matched your search
+13
-10
@@ -16,7 +16,7 @@ This document is the living implementation plan. It is updated as phases land.
|
|||||||
| 1 | Foundation: design system, auth, multi-account, biometrics | ✅ Done |
|
| 1 | Foundation: design system, auth, multi-account, biometrics | ✅ Done |
|
||||||
| 2 | Core Git experience: home, repos, browsing, commits | ✅ Done |
|
| 2 | Core Git experience: home, repos, browsing, commits | ✅ Done |
|
||||||
| 3 | Collaboration: issues, PRs, reviews, notifications | ✅ Done (read + write) |
|
| 3 | Collaboration: issues, PRs, reviews, notifications | ✅ Done (read + write) |
|
||||||
| 4 | Code editing: Quick Edit (CodeMirror), VS Code workspace | ⬜ Planned |
|
| 4 | Code editing: Quick Edit, commit flow, editor workspace | ✅ Done (native editor) |
|
||||||
| 5 | Advanced: Actions, packages, orgs, wiki, releases, admin | ⬜ Planned |
|
| 5 | Advanced: Actions, packages, orgs, wiki, releases, admin | ⬜ Planned |
|
||||||
|
|
||||||
Detailed acceptance criteria per phase are in `docs/FEATURE_PARITY.md`.
|
Detailed acceptance criteria per phase are in `docs/FEATURE_PARITY.md`.
|
||||||
@@ -103,16 +103,19 @@ Architectural decisions are recorded in `docs/ARCHITECTURE.md`.
|
|||||||
- [ ] Server-side filter UI (label, milestone, assignee) and sorting
|
- [ ] Server-side filter UI (label, milestone, assignee) and sorting
|
||||||
- [ ] Reactions/subscriptions
|
- [ ] Reactions/subscriptions
|
||||||
|
|
||||||
## Phase 4 — Code editing (planned)
|
## Phase 4 — Code editing
|
||||||
|
|
||||||
- [ ] Quick Edit: CodeMirror 6 in a dedicated WebView
|
- [x] Quick Edit: in-app editor over the file contents (native, monospace)
|
||||||
- [ ] Syntax highlighting, line numbers, search/replace, auto-indent
|
- [x] Commit through the Contents API (base64 content + blob SHA)
|
||||||
- [ ] Unsaved-changes detection, diff preview
|
- [x] Branch selection and **commit to a new branch** (`new_branch`)
|
||||||
- [ ] Branch selection/creation, commit message, Contents API commit (base64 + SHA)
|
- [x] Protected-branch awareness (force a new branch when direct push is blocked)
|
||||||
- [ ] Optional "create pull request" after commit
|
- [x] Optional "create pull request" right after committing to a new branch
|
||||||
- [ ] Protected-branch awareness and stale-SHA (409) conflict handling
|
- [x] Stale-SHA (409) conflict handling with a clear message
|
||||||
- [ ] VS Code workspace: per-instance/repo IDE URL, embedded browser, system-browser fallback
|
- [x] Unsaved-changes detection + discard
|
||||||
- [ ] IDE auth kept separate from Gitea API auth (no token passthrough)
|
- [x] Per-instance editor/IDE URL template ("Open in editor"), system-browser/app fallback
|
||||||
|
- [x] IDE auth stays separate from Gitea API auth (no token in the URL)
|
||||||
|
- [ ] CodeMirror 6 editor in a WebView (syntax highlighting, search/replace)
|
||||||
|
- [ ] Line-level diff preview before committing
|
||||||
|
|
||||||
## Phase 5 — Advanced features (planned)
|
## Phase 5 — Advanced features (planned)
|
||||||
|
|
||||||
|
|||||||
@@ -102,14 +102,18 @@ roadmap).
|
|||||||
| i18n (en/nl) | ✅ | device detection + override |
|
| i18n (en/nl) | ✅ | device detection + override |
|
||||||
| Loading/empty/error states | ✅ | shared components |
|
| Loading/empty/error states | ✅ | shared components |
|
||||||
|
|
||||||
## Code editing (planned)
|
## Code editing
|
||||||
|
|
||||||
| Feature | Status | Notes |
|
| Feature | Status | Notes |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| Quick Edit (CodeMirror WebView) | ⬜ | syntax highlight, search/replace |
|
| Quick Edit | ✅ | native monospace editor (CodeMirror/WebView deferred) |
|
||||||
| Commit via Contents API | ⬜ | base64 + SHA, 409 conflict handling |
|
| Commit via Contents API | ✅ | base64 + blob SHA; creates the commit |
|
||||||
| Create PR after commit | ⬜ | |
|
| Commit to a new branch | ✅ | `new_branch`, auto-forced on protected branches |
|
||||||
| VS Code workspace | 🌐 | per-instance IDE URL, no token passthrough |
|
| Protected-branch awareness | ✅ | blocks direct commits when `user_can_push` is false |
|
||||||
|
| Stale-SHA (409) handling | ✅ | mapped to a clear conflict message |
|
||||||
|
| Create PR after commit | ✅ | when committing to a new branch |
|
||||||
|
| VS Code / editor workspace | ✅ | configurable URL template, no token passthrough |
|
||||||
|
| Syntax highlighting / search-replace | ⬜ | planned (CodeMirror 6 in a WebView) |
|
||||||
|
|
||||||
## Advanced (planned)
|
## Advanced (planned)
|
||||||
|
|
||||||
|
|||||||
@@ -628,6 +628,94 @@ export function fetchCombinedStatus(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// File editing (Contents API) & pull request creation
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Result of a Contents API write: the new commit plus the updated entry. */
|
||||||
|
export interface FileWriteResponse {
|
||||||
|
commit?: { sha?: string; html_url?: string };
|
||||||
|
content?: ContentsEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CommitFileInput {
|
||||||
|
path: string;
|
||||||
|
/** Base64-encoded file content. */
|
||||||
|
content: string;
|
||||||
|
message: string;
|
||||||
|
/** Target branch. Defaults to the repository's default branch. */
|
||||||
|
branch?: string;
|
||||||
|
/** When set, the commit is made on a new branch created from `branch`. */
|
||||||
|
newBranch?: string;
|
||||||
|
/** Blob SHA of the file being replaced (required for updates). */
|
||||||
|
sha?: string;
|
||||||
|
signoff?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Updates an existing file via `PUT /repos/{owner}/{repo}/contents/{path}`. */
|
||||||
|
export function updateFileContents(
|
||||||
|
client: GiteaClient,
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
input: CommitFileInput,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<FileWriteResponse> {
|
||||||
|
return client.put<FileWriteResponse>(
|
||||||
|
`${repoPath(owner, repo)}/contents/${encodeRepoPath(input.path)}`,
|
||||||
|
{
|
||||||
|
content: input.content,
|
||||||
|
message: input.message,
|
||||||
|
branch: input.branch,
|
||||||
|
new_branch: input.newBranch,
|
||||||
|
sha: input.sha,
|
||||||
|
signoff: input.signoff,
|
||||||
|
},
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates a new file via `POST /repos/{owner}/{repo}/contents/{path}`. */
|
||||||
|
export function createFileContents(
|
||||||
|
client: GiteaClient,
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
input: CommitFileInput,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<FileWriteResponse> {
|
||||||
|
return client.post<FileWriteResponse>(
|
||||||
|
`${repoPath(owner, repo)}/contents/${encodeRepoPath(input.path)}`,
|
||||||
|
{
|
||||||
|
content: input.content,
|
||||||
|
message: input.message,
|
||||||
|
branch: input.branch,
|
||||||
|
new_branch: input.newBranch,
|
||||||
|
signoff: input.signoff,
|
||||||
|
},
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CreatePullInput {
|
||||||
|
title: string;
|
||||||
|
head: string;
|
||||||
|
base: string;
|
||||||
|
body?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createPull(
|
||||||
|
client: GiteaClient,
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
input: CreatePullInput,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<PullRequest> {
|
||||||
|
return client.post<PullRequest>(
|
||||||
|
`${repoPath(owner, repo)}/pulls`,
|
||||||
|
{ title: input.title, head: input.head, base: input.base, body: input.body },
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Notifications
|
// Notifications
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/** Portable base64 ⇄ UTF-8 helpers (Contents API round-trip). */
|
||||||
|
|
||||||
|
import { decodeBase64Utf8, encodeBase64Utf8 } from './base64';
|
||||||
|
|
||||||
|
describe('base64 utf-8', () => {
|
||||||
|
it('encodes ASCII to standard base64', () => {
|
||||||
|
expect(encodeBase64Utf8('hello')).toBe('aGVsbG8=');
|
||||||
|
expect(encodeBase64Utf8('a')).toBe('YQ==');
|
||||||
|
expect(encodeBase64Utf8('ab')).toBe('YWI=');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('decodes standard base64', () => {
|
||||||
|
expect(decodeBase64Utf8('TWFu')).toBe('Man');
|
||||||
|
expect(decodeBase64Utf8('aGVsbG8=')).toBe('hello');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('round-trips multi-byte content (accents + emoji)', () => {
|
||||||
|
const text = 'Héllo, wörld! 🌱 commit – 100%';
|
||||||
|
expect(decodeBase64Utf8(encodeBase64Utf8(text))).toBe(text);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('round-trips empty and multiline content', () => {
|
||||||
|
expect(decodeBase64Utf8(encodeBase64Utf8(''))).toBe('');
|
||||||
|
const multi = 'line 1\nline 2\n\ttabbed\n';
|
||||||
|
expect(decodeBase64Utf8(encodeBase64Utf8(multi))).toBe(multi);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tolerates whitespace in decoded input', () => {
|
||||||
|
expect(decodeBase64Utf8('aGVs\nbG8=')).toBe('hello');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
* Portable base64 ⇄ UTF-8 helpers.
|
||||||
|
*
|
||||||
|
* Hermes does not guarantee `atob`/`btoa`, and those only handle Latin-1 anyway,
|
||||||
|
* so the Contents API round-trip uses these pure-JS implementations. They are
|
||||||
|
* unit-tested against multi-byte (emoji/accented) content.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||||
|
|
||||||
|
function utf8ToBinary(text: string): string {
|
||||||
|
const encoded = encodeURIComponent(text);
|
||||||
|
let binary = '';
|
||||||
|
for (let i = 0; i < encoded.length; i += 1) {
|
||||||
|
if (encoded[i] === '%') {
|
||||||
|
binary += String.fromCharCode(parseInt(encoded.slice(i + 1, i + 3), 16));
|
||||||
|
i += 2;
|
||||||
|
} else {
|
||||||
|
binary += encoded[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return binary;
|
||||||
|
}
|
||||||
|
|
||||||
|
function binaryToUtf8(binary: string): string {
|
||||||
|
let percent = '';
|
||||||
|
for (let i = 0; i < binary.length; i += 1) {
|
||||||
|
percent += `%${binary.charCodeAt(i).toString(16).padStart(2, '0')}`;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(percent);
|
||||||
|
} catch {
|
||||||
|
return binary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function binaryToBase64(binary: string): string {
|
||||||
|
let result = '';
|
||||||
|
for (let i = 0; i < binary.length; i += 3) {
|
||||||
|
const c1 = binary.charCodeAt(i);
|
||||||
|
const c2 = i + 1 < binary.length ? binary.charCodeAt(i + 1) : NaN;
|
||||||
|
const c3 = i + 2 < binary.length ? binary.charCodeAt(i + 2) : NaN;
|
||||||
|
const e1 = c1 >> 2;
|
||||||
|
const e2 = ((c1 & 3) << 4) | (Number.isNaN(c2) ? 0 : c2 >> 4);
|
||||||
|
const e3 = Number.isNaN(c2) ? 64 : ((c2 & 15) << 2) | (Number.isNaN(c3) ? 0 : c3 >> 6);
|
||||||
|
const e4 = Number.isNaN(c3) ? 64 : c3 & 63;
|
||||||
|
result += ALPHABET[e1] + ALPHABET[e2] + (e3 === 64 ? '=' : ALPHABET[e3]) + (e4 === 64 ? '=' : ALPHABET[e4]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function base64ToBinary(base64: string): string {
|
||||||
|
const clean = base64.replace(/[^A-Za-z0-9+/]/g, '');
|
||||||
|
let result = '';
|
||||||
|
let buffer = 0;
|
||||||
|
let bits = 0;
|
||||||
|
for (let i = 0; i < clean.length; i += 1) {
|
||||||
|
const value = ALPHABET.indexOf(clean[i]);
|
||||||
|
if (value < 0) continue;
|
||||||
|
buffer = (buffer << 6) | value;
|
||||||
|
bits += 6;
|
||||||
|
if (bits >= 8) {
|
||||||
|
bits -= 8;
|
||||||
|
result += String.fromCharCode((buffer >> bits) & 0xff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Encodes a UTF-8 string to base64 (used for Contents API payloads). */
|
||||||
|
export function encodeBase64Utf8(text: string): string {
|
||||||
|
return binaryToBase64(utf8ToBinary(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Decodes base64 (whitespace tolerated) to a UTF-8 string. */
|
||||||
|
export function decodeBase64Utf8(base64: string): string {
|
||||||
|
return binaryToUtf8(base64ToBinary(base64));
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/** Editor URL template expansion. */
|
||||||
|
|
||||||
|
import { buildEditorUrl } from './editor-url';
|
||||||
|
|
||||||
|
describe('buildEditorUrl', () => {
|
||||||
|
it('replaces owner and repo placeholders', () => {
|
||||||
|
expect(
|
||||||
|
buildEditorUrl('https://ide.example/{owner}/{repo}', { owner: 'octo', name: 'repo' }),
|
||||||
|
).toBe('https://ide.example/octo/repo');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('URI-encodes the clone URL when used as a query parameter', () => {
|
||||||
|
const url = buildEditorUrl('vscode://vscode.git/clone?url={cloneUrl}', {
|
||||||
|
owner: 'octo',
|
||||||
|
name: 'repo',
|
||||||
|
cloneUrl: 'https://codeberg.org/octo/repo.git',
|
||||||
|
});
|
||||||
|
expect(url).toBe(
|
||||||
|
'vscode://vscode.git/clone?url=https%3A%2F%2Fcodeberg.org%2Focto%2Frepo.git',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('substitutes missing optional values with an empty string', () => {
|
||||||
|
expect(buildEditorUrl('x?u={htmlUrl}', { owner: 'o', name: 'r' })).toBe('x?u=');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('never adds a token', () => {
|
||||||
|
const url = buildEditorUrl('https://ide/{owner}/{repo}', { owner: 'o', name: 'r' });
|
||||||
|
expect(url).not.toMatch(/token|Authorization/i);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* Expands the user's editor/IDE URL template for the repository action.
|
||||||
|
*
|
||||||
|
* The template is opened with `Linking.openURL` only — the API token is never
|
||||||
|
* part of the template or the resulting URL, so IDE auth stays separate.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface EditorUrlParts {
|
||||||
|
owner: string;
|
||||||
|
name: string;
|
||||||
|
cloneUrl?: string;
|
||||||
|
htmlUrl?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Replaces `{owner}`, `{repo}`, `{cloneUrl}` and `{htmlUrl}`, URI-encoding each value. */
|
||||||
|
export function buildEditorUrl(template: string, parts: EditorUrlParts): string {
|
||||||
|
return template
|
||||||
|
.split('{owner}')
|
||||||
|
.join(encodeURIComponent(parts.owner))
|
||||||
|
.split('{repo}')
|
||||||
|
.join(encodeURIComponent(parts.name))
|
||||||
|
.split('{cloneUrl}')
|
||||||
|
.join(encodeURIComponent(parts.cloneUrl ?? ''))
|
||||||
|
.split('{htmlUrl}')
|
||||||
|
.join(encodeURIComponent(parts.htmlUrl ?? ''));
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import type { RawResponse } from '@/core/api/client';
|
|||||||
import {
|
import {
|
||||||
createIssue,
|
createIssue,
|
||||||
createIssueComment,
|
createIssueComment,
|
||||||
|
createPull,
|
||||||
createPullReview,
|
createPullReview,
|
||||||
deleteIssueComment,
|
deleteIssueComment,
|
||||||
fetchCombinedStatus,
|
fetchCombinedStatus,
|
||||||
@@ -39,6 +40,7 @@ import {
|
|||||||
updateIssue,
|
updateIssue,
|
||||||
updateIssueComment,
|
updateIssueComment,
|
||||||
type CreateIssueInput,
|
type CreateIssueInput,
|
||||||
|
type CreatePullInput,
|
||||||
type CreateReviewInput,
|
type CreateReviewInput,
|
||||||
type EditIssueInput,
|
type EditIssueInput,
|
||||||
type IssueSearchParams,
|
type IssueSearchParams,
|
||||||
@@ -437,5 +439,20 @@ export function useCombinedStatus(owner: string, name: string, ref: string | und
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Create a pull request (used after committing to a new branch). */
|
||||||
|
export function useCreatePull(owner: string, name: string) {
|
||||||
|
const { client, account } = useSession();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const accountId = account?.id ?? '';
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (input: CreatePullInput) => createPull(client!, owner, name, input),
|
||||||
|
onSuccess: () => {
|
||||||
|
void queryClient.invalidateQueries({ queryKey: queryKeys.pullsRoot(accountId, owner, name) });
|
||||||
|
void queryClient.invalidateQueries({ queryKey: queryKeys.issueSearchRoot(accountId) });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export type { Issue, Label, PullRequest };
|
export type { Issue, Label, PullRequest };
|
||||||
export type { ChangedFile, CombinedStatus, Comment, Milestone, PullReview, User };
|
export type { ChangedFile, CombinedStatus, Comment, Milestone, PullReview, User };
|
||||||
@@ -3,7 +3,9 @@
|
|||||||
import {
|
import {
|
||||||
keepPreviousData,
|
keepPreviousData,
|
||||||
useInfiniteQuery,
|
useInfiniteQuery,
|
||||||
|
useMutation,
|
||||||
useQuery,
|
useQuery,
|
||||||
|
useQueryClient,
|
||||||
type InfiniteData,
|
type InfiniteData,
|
||||||
} from '@tanstack/react-query';
|
} from '@tanstack/react-query';
|
||||||
|
|
||||||
@@ -17,9 +19,12 @@ import {
|
|||||||
listCommits,
|
listCommits,
|
||||||
listContents,
|
listContents,
|
||||||
listTags,
|
listTags,
|
||||||
|
updateFileContents,
|
||||||
|
type CommitFileInput,
|
||||||
} from '@/core/api/endpoints';
|
} from '@/core/api/endpoints';
|
||||||
import { queryKeys } from '@/core/api/query-keys';
|
import { queryKeys } from '@/core/api/query-keys';
|
||||||
import type { Branch, Commit, Tag } from '@/core/api/types';
|
import type { Branch, Commit, Tag } from '@/core/api/types';
|
||||||
|
import { decodeBase64Utf8 } from '@/core/utils/base64';
|
||||||
import { useSession } from '@/features/accounts/use-session';
|
import { useSession } from '@/features/accounts/use-session';
|
||||||
|
|
||||||
/** Directory listing (or file entry when a path is given). */
|
/** Directory listing (or file entry when a path is given). */
|
||||||
@@ -159,12 +164,21 @@ export function useCommit(owner: string, name: string, sha: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convenience: decode a base64 contents payload from the API. */
|
/** Convenience: decode a base64 contents payload from the API (UTF-8 safe). */
|
||||||
export function decodeBase64(content: string): string {
|
export function decodeBase64(content: string): string {
|
||||||
// Gitea returns base64 without line wrapping; atob is available in Hermes.
|
return decodeBase64Utf8(content);
|
||||||
try {
|
}
|
||||||
return globalThis.atob(content.replace(/\s/g, ''));
|
|
||||||
} catch {
|
/** Commit a file edit through the Contents API (update path; handles new branches). */
|
||||||
return '';
|
export function useCommitFile(owner: string, name: string) {
|
||||||
}
|
const { client, account } = useSession();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const accountId = account?.id ?? '';
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (input: CommitFileInput) => updateFileContents(client!, owner, name, input),
|
||||||
|
onSuccess: () => {
|
||||||
|
void queryClient.invalidateQueries({ queryKey: queryKeys.repo(accountId, owner, name) });
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,299 @@
|
|||||||
|
import { useMemo, useState } from 'react';
|
||||||
|
import { Alert, StyleSheet, Switch, View } from 'react-native';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { Screen } from '@/components/layout/screen';
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Card } from '@/components/ui/card';
|
||||||
|
import { ChipSelect } from '@/components/ui/chip-select';
|
||||||
|
import { Field } from '@/components/ui/field';
|
||||||
|
import { TextArea } from '@/components/ui/text-area';
|
||||||
|
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||||
|
import { apiErrorMessage } from '@/core/api/error-text';
|
||||||
|
import type { Branch, ContentsEntry, Repository } from '@/core/api/types';
|
||||||
|
import { encodeBase64Utf8 } from '@/core/utils/base64';
|
||||||
|
import { flattenPages } from '@/core/utils/infinite';
|
||||||
|
import { useCreatePull } from '@/features/issues/queries';
|
||||||
|
import { useRepository } from '@/features/repositories/queries';
|
||||||
|
import { decodeBase64, useBranches, useCommitFile, useFile } from '@/features/repository/queries';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { spacing } from '@/theme/tokens';
|
||||||
|
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||||
|
import type { ScreenProps } from '@/navigation/typing';
|
||||||
|
|
||||||
|
type Props = ScreenProps<RepositoryStackParamList, 'FileEdit'>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quick Edit: edit a file in a monospace editor and commit it through the
|
||||||
|
* Contents API. Supports committing to a new branch (which also handles
|
||||||
|
* protected branches) and optionally opening a pull request afterwards.
|
||||||
|
*/
|
||||||
|
export function FileEditScreen({ navigation, route }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { owner, name, path, ref } = route.params;
|
||||||
|
|
||||||
|
const fileQuery = useFile(owner, name, path, ref);
|
||||||
|
const refetchFile = fileQuery.refetch;
|
||||||
|
const repoQuery = useRepository(owner, name);
|
||||||
|
const branchesQuery = useBranches(owner, name, '');
|
||||||
|
const branches = flattenPages(branchesQuery.data);
|
||||||
|
const entry = fileQuery.data;
|
||||||
|
|
||||||
|
if (fileQuery.isPending) return <LoadingView />;
|
||||||
|
if (fileQuery.isError) {
|
||||||
|
return (
|
||||||
|
<ErrorState
|
||||||
|
title={t('errors.title')}
|
||||||
|
body={apiErrorMessage(fileQuery.error, t)}
|
||||||
|
retryLabel={t('common.retry')}
|
||||||
|
onRetry={() => void refetchFile()}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!entry) {
|
||||||
|
return (
|
||||||
|
<ErrorState
|
||||||
|
title={t('files.rawUnavailable')}
|
||||||
|
retryLabel={t('common.retry')}
|
||||||
|
onRetry={() => void refetchFile()}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FileEditForm
|
||||||
|
key={entry.sha ?? entry.path}
|
||||||
|
owner={owner}
|
||||||
|
name={name}
|
||||||
|
path={path}
|
||||||
|
initialRef={ref}
|
||||||
|
entry={entry}
|
||||||
|
repo={repoQuery.data}
|
||||||
|
branches={branches}
|
||||||
|
onDone={() => navigation.goBack()}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FormProps {
|
||||||
|
owner: string;
|
||||||
|
name: string;
|
||||||
|
path: string;
|
||||||
|
initialRef?: string;
|
||||||
|
entry: ContentsEntry;
|
||||||
|
repo?: Repository;
|
||||||
|
branches: Branch[];
|
||||||
|
onDone: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function FileEditForm({ owner, name, path, initialRef, entry, repo, branches, onDone }: FormProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { colors } = useTheme();
|
||||||
|
const commitFile = useCommitFile(owner, name);
|
||||||
|
const createPull = useCreatePull(owner, name);
|
||||||
|
|
||||||
|
// Initialised once per file (the parent remounts this component via `key`).
|
||||||
|
const [original] = useState(() => decodeBase64(entry.content ?? ''));
|
||||||
|
const [draft, setDraft] = useState(original);
|
||||||
|
const [message, setMessage] = useState('');
|
||||||
|
const [branch, setBranch] = useState<string | null>(initialRef ?? null);
|
||||||
|
const [useNewBranch, setUseNewBranch] = useState(false);
|
||||||
|
const [newBranch, setNewBranch] = useState('');
|
||||||
|
const [createPr, setCreatePr] = useState(false);
|
||||||
|
const [prTitle, setPrTitle] = useState('');
|
||||||
|
const [submitted, setSubmitted] = useState(false);
|
||||||
|
|
||||||
|
const targetBranch = branch ?? repo?.default_branch ?? null;
|
||||||
|
const branchOptions = useMemo(
|
||||||
|
() => branches.map((b) => ({ id: b.name, label: b.name })),
|
||||||
|
[branches],
|
||||||
|
);
|
||||||
|
const currentBranch = branches.find((b) => b.name === targetBranch);
|
||||||
|
const branchProtected = Boolean(currentBranch?.protected && currentBranch?.user_can_push !== true);
|
||||||
|
const effectiveNewBranch = useNewBranch || branchProtected;
|
||||||
|
|
||||||
|
const dirty = draft !== original;
|
||||||
|
const canSubmit =
|
||||||
|
dirty &&
|
||||||
|
message.trim().length > 0 &&
|
||||||
|
(effectiveNewBranch ? newBranch.trim().length > 0 : Boolean(targetBranch)) &&
|
||||||
|
!commitFile.isPending;
|
||||||
|
|
||||||
|
const submit = () => {
|
||||||
|
setSubmitted(true);
|
||||||
|
if (!canSubmit || !entry.sha) return;
|
||||||
|
const newBranchName = effectiveNewBranch ? newBranch.trim() : undefined;
|
||||||
|
commitFile.mutate(
|
||||||
|
{
|
||||||
|
path,
|
||||||
|
content: encodeBase64Utf8(draft),
|
||||||
|
message: message.trim(),
|
||||||
|
branch: targetBranch ?? undefined,
|
||||||
|
newBranch: newBranchName,
|
||||||
|
sha: entry.sha,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess: async () => {
|
||||||
|
if (createPr && newBranchName && targetBranch && prTitle.trim().length > 0) {
|
||||||
|
try {
|
||||||
|
await createPull.mutateAsync({
|
||||||
|
title: prTitle.trim(),
|
||||||
|
head: newBranchName,
|
||||||
|
base: targetBranch,
|
||||||
|
body: message.trim(),
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
// The commit succeeded; a failed PR can be opened from the web UI.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Alert.alert(t('edit.commitSuccessTitle'), t('edit.commitSuccessBody'));
|
||||||
|
onDone();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Screen scroll padded>
|
||||||
|
<View style={styles.toolbar}>
|
||||||
|
<AppText variant="monoSmall" tone="tertiary" numberOfLines={1} style={styles.pathLabel}>
|
||||||
|
{path}
|
||||||
|
</AppText>
|
||||||
|
{dirty ? (
|
||||||
|
<Button
|
||||||
|
label={t('edit.discard')}
|
||||||
|
variant="ghost"
|
||||||
|
size="md"
|
||||||
|
onPress={() => setDraft(original)}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<TextArea
|
||||||
|
value={draft}
|
||||||
|
onChangeText={setDraft}
|
||||||
|
minHeight={360}
|
||||||
|
mono
|
||||||
|
autoCapitalize="none"
|
||||||
|
autoCorrect={false}
|
||||||
|
testID="file-editor"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{branchProtected ? (
|
||||||
|
<AppText variant="caption" tone="warning">
|
||||||
|
{t('edit.protectedBranch', { branch: targetBranch ?? '' })}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<AppText variant="label" tone="secondary" style={styles.sectionLabel}>
|
||||||
|
{t('edit.branch')}
|
||||||
|
</AppText>
|
||||||
|
<ChipSelect
|
||||||
|
options={branchOptions}
|
||||||
|
selectedIds={targetBranch ? [targetBranch] : []}
|
||||||
|
onToggle={(id) => setBranch(id)}
|
||||||
|
emptyLabel={t('edit.loadingBranches')}
|
||||||
|
single
|
||||||
|
/>
|
||||||
|
|
||||||
|
<View style={styles.switchRow}>
|
||||||
|
<AppText variant="bodyMedium" style={styles.switchLabel}>
|
||||||
|
{t('edit.createBranch')}
|
||||||
|
</AppText>
|
||||||
|
<Switch
|
||||||
|
value={effectiveNewBranch}
|
||||||
|
onValueChange={setUseNewBranch}
|
||||||
|
disabled={branchProtected}
|
||||||
|
trackColor={{ true: colors.primary, false: colors.border }}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
{effectiveNewBranch ? (
|
||||||
|
<Field
|
||||||
|
label={t('edit.newBranchName')}
|
||||||
|
value={newBranch}
|
||||||
|
onChangeText={setNewBranch}
|
||||||
|
placeholder={t('edit.newBranchPlaceholder')}
|
||||||
|
autoCapitalize="none"
|
||||||
|
autoCorrect={false}
|
||||||
|
mono
|
||||||
|
testID="new-branch"
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<TextArea
|
||||||
|
label={t('edit.commitMessage')}
|
||||||
|
value={message}
|
||||||
|
onChangeText={setMessage}
|
||||||
|
placeholder={t('edit.commitMessagePlaceholder')}
|
||||||
|
minHeight={80}
|
||||||
|
autoCapitalize="sentences"
|
||||||
|
autoCorrect
|
||||||
|
testID="commit-message"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{effectiveNewBranch ? (
|
||||||
|
<Card>
|
||||||
|
<View style={styles.switchRow}>
|
||||||
|
<AppText variant="bodyMedium" style={styles.switchLabel}>
|
||||||
|
{t('edit.openPullRequest')}
|
||||||
|
</AppText>
|
||||||
|
<Switch
|
||||||
|
value={createPr}
|
||||||
|
onValueChange={setCreatePr}
|
||||||
|
trackColor={{ true: colors.primary, false: colors.border }}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
{createPr ? (
|
||||||
|
<Field
|
||||||
|
label={t('edit.prTitle')}
|
||||||
|
value={prTitle}
|
||||||
|
onChangeText={setPrTitle}
|
||||||
|
placeholder={t('edit.prTitlePlaceholder')}
|
||||||
|
autoCapitalize="sentences"
|
||||||
|
testID="pr-title"
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</Card>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{submitted && !canSubmit ? (
|
||||||
|
<AppText variant="caption" tone="error">
|
||||||
|
{t('edit.incomplete')}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
{commitFile.isError ? (
|
||||||
|
<AppText variant="caption" tone="error">
|
||||||
|
{apiErrorMessage(commitFile.error, t)}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
label={t('edit.commit')}
|
||||||
|
onPress={submit}
|
||||||
|
loading={commitFile.isPending}
|
||||||
|
disabled={!canSubmit}
|
||||||
|
fullWidth
|
||||||
|
testID="commit-submit"
|
||||||
|
/>
|
||||||
|
<View style={styles.spacer} />
|
||||||
|
</Screen>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
toolbar: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm },
|
||||||
|
pathLabel: { flex: 1 },
|
||||||
|
sectionLabel: { marginBottom: spacing.sm },
|
||||||
|
switchRow: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
gap: spacing.md,
|
||||||
|
marginTop: spacing.md,
|
||||||
|
},
|
||||||
|
switchLabel: { flex: 1 },
|
||||||
|
spacer: { height: spacing.xl },
|
||||||
|
});
|
||||||
@@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { Markdown } from '@/components/git/markdown';
|
import { Markdown } from '@/components/git/markdown';
|
||||||
import { Screen } from '@/components/layout/screen';
|
import { Screen } from '@/components/layout/screen';
|
||||||
import { AppText } from '@/components/ui/app-text';
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
import { Card } from '@/components/ui/card';
|
import { Card } from '@/components/ui/card';
|
||||||
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||||
import { apiErrorMessage } from '@/core/api/error-text';
|
import { apiErrorMessage } from '@/core/api/error-text';
|
||||||
@@ -30,7 +31,7 @@ function extensionOf(path: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Renders a single file: image preview, markdown, or source text. */
|
/** Renders a single file: image preview, markdown, or source text. */
|
||||||
export function FileViewerScreen({ route }: Props) {
|
export function FileViewerScreen({ navigation, route }: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
const { instance, token } = useSession();
|
const { instance, token } = useSession();
|
||||||
@@ -115,6 +116,15 @@ export function FileViewerScreen({ route }: Props) {
|
|||||||
{t('files.large', { size: formatBytes(entry.size) })}
|
{t('files.large', { size: formatBytes(entry.size) })}
|
||||||
</AppText>
|
</AppText>
|
||||||
) : null}
|
) : null}
|
||||||
|
<View style={styles.editRow}>
|
||||||
|
<Button
|
||||||
|
label={t('edit.title')}
|
||||||
|
variant="secondary"
|
||||||
|
size="md"
|
||||||
|
iconLeft="edit"
|
||||||
|
onPress={() => navigation.navigate('FileEdit', { owner, name, path, ref })}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
{MARKDOWN_EXTENSIONS.has(extension) ? (
|
{MARKDOWN_EXTENSIONS.has(extension) ? (
|
||||||
<View style={styles.markdownWrap}>
|
<View style={styles.markdownWrap}>
|
||||||
<Markdown content={content} baseUrl={instance?.baseUrl} />
|
<Markdown content={content} baseUrl={instance?.baseUrl} />
|
||||||
@@ -137,6 +147,7 @@ export function FileViewerScreen({ route }: Props) {
|
|||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
notice: { paddingHorizontal: spacing.lg, paddingVertical: spacing.sm },
|
notice: { paddingHorizontal: spacing.lg, paddingVertical: spacing.sm },
|
||||||
|
editRow: { paddingHorizontal: spacing.lg, paddingBottom: spacing.sm },
|
||||||
markdownWrap: { paddingHorizontal: spacing.lg },
|
markdownWrap: { paddingHorizontal: spacing.lg },
|
||||||
imageCard: { overflow: 'hidden', minHeight: 200 },
|
imageCard: { overflow: 'hidden', minHeight: 200 },
|
||||||
image: { width: '100%', height: 320 },
|
image: { width: '100%', height: 320 },
|
||||||
|
|||||||
@@ -13,9 +13,11 @@ import { LabelChip } from '@/components/ui/label-chip';
|
|||||||
import { ListItem } from '@/components/ui/list-item';
|
import { ListItem } from '@/components/ui/list-item';
|
||||||
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||||
import { apiErrorMessage } from '@/core/api/error-text';
|
import { apiErrorMessage } from '@/core/api/error-text';
|
||||||
|
import { buildEditorUrl } from '@/core/utils/editor-url';
|
||||||
import { useRepository, useRepositoryLanguages } from '@/features/repositories/queries';
|
import { useRepository, useRepositoryLanguages } from '@/features/repositories/queries';
|
||||||
import { useReadme } from '@/features/repository/queries';
|
import { decodeBase64, useReadme } from '@/features/repository/queries';
|
||||||
import { useSession } from '@/features/accounts/use-session';
|
import { useSession } from '@/features/accounts/use-session';
|
||||||
|
import { useSettingsStore } from '@/features/settings/settings-store';
|
||||||
import { useTheme } from '@/theme/theme-provider';
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
import { radius, spacing } from '@/theme/tokens';
|
import { radius, spacing } from '@/theme/tokens';
|
||||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||||
@@ -28,6 +30,7 @@ export function RepoOverviewScreen({ navigation, route }: Props) {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
const { instance } = useSession();
|
const { instance } = useSession();
|
||||||
|
const editorUrlTemplate = useSettingsStore((s) => s.editorUrlTemplate);
|
||||||
const { owner, name, ref } = route.params;
|
const { owner, name, ref } = route.params;
|
||||||
|
|
||||||
const repoQuery = useRepository(owner, name);
|
const repoQuery = useRepository(owner, name);
|
||||||
@@ -107,6 +110,23 @@ export function RepoOverviewScreen({ navigation, route }: Props) {
|
|||||||
onPress={() => void Linking.openURL(repo.html_url as string).catch(() => undefined)}
|
onPress={() => void Linking.openURL(repo.html_url as string).catch(() => undefined)}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
{editorUrlTemplate ? (
|
||||||
|
<Button
|
||||||
|
label={t('repo.openInEditor')}
|
||||||
|
variant="secondary"
|
||||||
|
iconLeft="externalLink"
|
||||||
|
onPress={() => {
|
||||||
|
const url = buildEditorUrl(editorUrlTemplate, {
|
||||||
|
owner,
|
||||||
|
name,
|
||||||
|
cloneUrl: repo.clone_url,
|
||||||
|
htmlUrl: repo.html_url,
|
||||||
|
});
|
||||||
|
void Linking.openURL(url).catch(() => undefined);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Quick navigation */}
|
{/* Quick navigation */}
|
||||||
@@ -265,11 +285,7 @@ function languageColor(index: number, fallback: string): string {
|
|||||||
|
|
||||||
function decodeReadme(content: string | undefined): string {
|
function decodeReadme(content: string | undefined): string {
|
||||||
if (!content) return '';
|
if (!content) return '';
|
||||||
try {
|
return decodeBase64(content);
|
||||||
return globalThis.atob(content.replace(/\s/g, ''));
|
|
||||||
} catch {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { Screen } from '@/components/layout/screen';
|
import { Screen } from '@/components/layout/screen';
|
||||||
import { AppText } from '@/components/ui/app-text';
|
import { AppText } from '@/components/ui/app-text';
|
||||||
import { Card } from '@/components/ui/card';
|
import { Card } from '@/components/ui/card';
|
||||||
|
import { Field } from '@/components/ui/field';
|
||||||
import { ListItem } from '@/components/ui/list-item';
|
import { ListItem } from '@/components/ui/list-item';
|
||||||
import { SegmentedControl } from '@/components/ui/segmented';
|
import { SegmentedControl } from '@/components/ui/segmented';
|
||||||
import { queryClient } from '@/core/api/query-client';
|
import { queryClient } from '@/core/api/query-client';
|
||||||
@@ -39,6 +40,8 @@ export function SettingsScreen(_props: Props) {
|
|||||||
const setLanguage = useSettingsStore((s) => s.setLanguage);
|
const setLanguage = useSettingsStore((s) => s.setLanguage);
|
||||||
const setBiometricsEnabled = useSettingsStore((s) => s.setBiometricsEnabled);
|
const setBiometricsEnabled = useSettingsStore((s) => s.setBiometricsEnabled);
|
||||||
const setNotificationPollSeconds = useSettingsStore((s) => s.setNotificationPollSeconds);
|
const setNotificationPollSeconds = useSettingsStore((s) => s.setNotificationPollSeconds);
|
||||||
|
const editorUrlTemplate = useSettingsStore((s) => s.editorUrlTemplate);
|
||||||
|
const setEditorUrlTemplate = useSettingsStore((s) => s.setEditorUrlTemplate);
|
||||||
|
|
||||||
const [support, setSupport] = useState<BiometricSupport | null>(null);
|
const [support, setSupport] = useState<BiometricSupport | null>(null);
|
||||||
|
|
||||||
@@ -146,6 +149,22 @@ export function SettingsScreen(_props: Props) {
|
|||||||
</Card>
|
</Card>
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
|
{/* Editor integration */}
|
||||||
|
<Section title={t('settings.editor')}>
|
||||||
|
<Card style={styles.card}>
|
||||||
|
<Field
|
||||||
|
label={t('settings.editorUrlTemplate')}
|
||||||
|
value={editorUrlTemplate}
|
||||||
|
onChangeText={setEditorUrlTemplate}
|
||||||
|
placeholder={t('settings.editorUrlPlaceholder')}
|
||||||
|
helper={t('settings.editorUrlHelp')}
|
||||||
|
autoCapitalize="none"
|
||||||
|
autoCorrect={false}
|
||||||
|
mono
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</Section>
|
||||||
|
|
||||||
{/* Data */}
|
{/* Data */}
|
||||||
<Section title={t('settings.data')}>
|
<Section title={t('settings.data')}>
|
||||||
<Card padded={false} variant="flat">
|
<Card padded={false} variant="flat">
|
||||||
|
|||||||
@@ -20,10 +20,17 @@ export interface SettingsState {
|
|||||||
biometricsEnabled: boolean;
|
biometricsEnabled: boolean;
|
||||||
/** Background polling interval for the notifications inbox, in seconds. 0 = only manual/foreground refresh. */
|
/** Background polling interval for the notifications inbox, in seconds. 0 = only manual/foreground refresh. */
|
||||||
notificationPollSeconds: number;
|
notificationPollSeconds: number;
|
||||||
|
/**
|
||||||
|
* Optional editor/IDE URL template for the "Open in editor" action.
|
||||||
|
* Placeholders: {owner} {repo} {path} {cloneUrl}. Empty hides the action.
|
||||||
|
* Opened in the system browser/app only — the API token is never appended.
|
||||||
|
*/
|
||||||
|
editorUrlTemplate: string;
|
||||||
setThemePreference: (preference: ThemePreference) => void;
|
setThemePreference: (preference: ThemePreference) => void;
|
||||||
setLanguage: (language: LanguagePreference) => void;
|
setLanguage: (language: LanguagePreference) => void;
|
||||||
setBiometricsEnabled: (enabled: boolean) => void;
|
setBiometricsEnabled: (enabled: boolean) => void;
|
||||||
setNotificationPollSeconds: (seconds: number) => void;
|
setNotificationPollSeconds: (seconds: number) => void;
|
||||||
|
setEditorUrlTemplate: (template: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useSettingsStore = create<SettingsState>()(
|
export const useSettingsStore = create<SettingsState>()(
|
||||||
@@ -33,10 +40,12 @@ export const useSettingsStore = create<SettingsState>()(
|
|||||||
language: 'system',
|
language: 'system',
|
||||||
biometricsEnabled: false,
|
biometricsEnabled: false,
|
||||||
notificationPollSeconds: 60,
|
notificationPollSeconds: 60,
|
||||||
|
editorUrlTemplate: '',
|
||||||
setThemePreference: (themePreference) => set({ themePreference }),
|
setThemePreference: (themePreference) => set({ themePreference }),
|
||||||
setLanguage: (language) => set({ language }),
|
setLanguage: (language) => set({ language }),
|
||||||
setBiometricsEnabled: (biometricsEnabled) => set({ biometricsEnabled }),
|
setBiometricsEnabled: (biometricsEnabled) => set({ biometricsEnabled }),
|
||||||
setNotificationPollSeconds: (notificationPollSeconds) => set({ notificationPollSeconds }),
|
setNotificationPollSeconds: (notificationPollSeconds) => set({ notificationPollSeconds }),
|
||||||
|
setEditorUrlTemplate: (editorUrlTemplate) => set({ editorUrlTemplate }),
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: 'gitea-native:settings:v1',
|
name: 'gitea-native:settings:v1',
|
||||||
@@ -46,6 +55,7 @@ export const useSettingsStore = create<SettingsState>()(
|
|||||||
language: state.language,
|
language: state.language,
|
||||||
biometricsEnabled: state.biometricsEnabled,
|
biometricsEnabled: state.biometricsEnabled,
|
||||||
notificationPollSeconds: state.notificationPollSeconds,
|
notificationPollSeconds: state.notificationPollSeconds,
|
||||||
|
editorUrlTemplate: state.editorUrlTemplate,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -153,6 +153,7 @@
|
|||||||
"notFound": "This repository could not be found.",
|
"notFound": "This repository could not be found.",
|
||||||
"noPermission": "You don't have permission to view this repository.",
|
"noPermission": "You don't have permission to view this repository.",
|
||||||
"viewOnInstance": "Open in browser",
|
"viewOnInstance": "Open in browser",
|
||||||
|
"openInEditor": "Open in editor",
|
||||||
"browse": "Browse",
|
"browse": "Browse",
|
||||||
"empty": "This repository is empty",
|
"empty": "This repository is empty",
|
||||||
"noReadme": "No README file",
|
"noReadme": "No README file",
|
||||||
@@ -325,6 +326,25 @@
|
|||||||
"count": "{{count}} checks",
|
"count": "{{count}} checks",
|
||||||
"unnamed": "check"
|
"unnamed": "check"
|
||||||
},
|
},
|
||||||
|
"edit": {
|
||||||
|
"title": "Edit file",
|
||||||
|
"discard": "Discard changes",
|
||||||
|
"branch": "Commit to branch",
|
||||||
|
"loadingBranches": "Loading branches…",
|
||||||
|
"createBranch": "Create a new branch",
|
||||||
|
"newBranchName": "New branch name",
|
||||||
|
"newBranchPlaceholder": "feature/my-change",
|
||||||
|
"protectedBranch": "{{branch}} is protected. Your change will be committed to a new branch.",
|
||||||
|
"commitMessage": "Commit message",
|
||||||
|
"commitMessagePlaceholder": "Describe your change",
|
||||||
|
"openPullRequest": "Open a pull request",
|
||||||
|
"prTitle": "Pull request title",
|
||||||
|
"prTitlePlaceholder": "Title for the pull request",
|
||||||
|
"incomplete": "Add a commit message and a target branch.",
|
||||||
|
"commit": "Commit changes",
|
||||||
|
"commitSuccessTitle": "Committed",
|
||||||
|
"commitSuccessBody": "Your changes were committed."
|
||||||
|
},
|
||||||
"inbox": {
|
"inbox": {
|
||||||
"title": "Inbox",
|
"title": "Inbox",
|
||||||
"filterUnread": "Unread",
|
"filterUnread": "Unread",
|
||||||
@@ -359,6 +379,10 @@
|
|||||||
"pollInterval": "Refresh interval",
|
"pollInterval": "Refresh interval",
|
||||||
"pollIntervalManual": "Manual only",
|
"pollIntervalManual": "Manual only",
|
||||||
"pollIntervalSeconds": "{{count}} seconds",
|
"pollIntervalSeconds": "{{count}} seconds",
|
||||||
|
"editor": "Editor",
|
||||||
|
"editorUrlTemplate": "Editor URL template",
|
||||||
|
"editorUrlPlaceholder": "vscode://vscode.git/clone?url={cloneUrl}",
|
||||||
|
"editorUrlHelp": "Leave empty to hide. Placeholders: {owner}, {repo}, {cloneUrl}, {htmlUrl}. Your token is never sent.",
|
||||||
"data": "Data",
|
"data": "Data",
|
||||||
"clearCache": "Clear cached data",
|
"clearCache": "Clear cached data",
|
||||||
"clearCacheTitle": "Clear cached data?",
|
"clearCacheTitle": "Clear cached data?",
|
||||||
|
|||||||
@@ -153,6 +153,7 @@
|
|||||||
"notFound": "Deze repository kon niet worden gevonden.",
|
"notFound": "Deze repository kon niet worden gevonden.",
|
||||||
"noPermission": "Je hebt geen rechten om deze repository te bekijken.",
|
"noPermission": "Je hebt geen rechten om deze repository te bekijken.",
|
||||||
"viewOnInstance": "Openen in browser",
|
"viewOnInstance": "Openen in browser",
|
||||||
|
"openInEditor": "Openen in editor",
|
||||||
"browse": "Bladeren",
|
"browse": "Bladeren",
|
||||||
"empty": "Deze repository is leeg",
|
"empty": "Deze repository is leeg",
|
||||||
"noReadme": "Geen README-bestand",
|
"noReadme": "Geen README-bestand",
|
||||||
@@ -325,6 +326,25 @@
|
|||||||
"count": "{{count}} checks",
|
"count": "{{count}} checks",
|
||||||
"unnamed": "check"
|
"unnamed": "check"
|
||||||
},
|
},
|
||||||
|
"edit": {
|
||||||
|
"title": "Bestand bewerken",
|
||||||
|
"discard": "Wijzigingen verwerpen",
|
||||||
|
"branch": "Committen naar branch",
|
||||||
|
"loadingBranches": "Branches laden…",
|
||||||
|
"createBranch": "Nieuwe branch aanmaken",
|
||||||
|
"newBranchName": "Naam nieuwe branch",
|
||||||
|
"newBranchPlaceholder": "feature/mijn-wijziging",
|
||||||
|
"protectedBranch": "{{branch}} is beschermd. Je wijziging wordt naar een nieuwe branch gecommit.",
|
||||||
|
"commitMessage": "Commit-bericht",
|
||||||
|
"commitMessagePlaceholder": "Beschrijf je wijziging",
|
||||||
|
"openPullRequest": "Pull request openen",
|
||||||
|
"prTitle": "Titel van pull request",
|
||||||
|
"prTitlePlaceholder": "Titel voor de pull request",
|
||||||
|
"incomplete": "Voeg een commit-bericht en een doelbranch toe.",
|
||||||
|
"commit": "Wijzigingen committen",
|
||||||
|
"commitSuccessTitle": "Gecommit",
|
||||||
|
"commitSuccessBody": "Je wijzigingen zijn gecommit."
|
||||||
|
},
|
||||||
"inbox": {
|
"inbox": {
|
||||||
"title": "Inbox",
|
"title": "Inbox",
|
||||||
"filterUnread": "Ongelezen",
|
"filterUnread": "Ongelezen",
|
||||||
@@ -359,6 +379,10 @@
|
|||||||
"pollInterval": "Vernieuwingsinterval",
|
"pollInterval": "Vernieuwingsinterval",
|
||||||
"pollIntervalManual": "Alleen handmatig",
|
"pollIntervalManual": "Alleen handmatig",
|
||||||
"pollIntervalSeconds": "{{count}} seconden",
|
"pollIntervalSeconds": "{{count}} seconden",
|
||||||
|
"editor": "Editor",
|
||||||
|
"editorUrlTemplate": "Editor-URL-sjabloon",
|
||||||
|
"editorUrlPlaceholder": "vscode://vscode.git/clone?url={cloneUrl}",
|
||||||
|
"editorUrlHelp": "Laat leeg om te verbergen. Placeholders: {owner}, {repo}, {cloneUrl}, {htmlUrl}. Je token wordt nooit meegestuurd.",
|
||||||
"data": "Gegevens",
|
"data": "Gegevens",
|
||||||
"clearCache": "Cachegegevens wissen",
|
"clearCache": "Cachegegevens wissen",
|
||||||
"clearCacheTitle": "Cachegegevens wissen?",
|
"clearCacheTitle": "Cachegegevens wissen?",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { HeaderAccountAndSettings } from '@/components/layout/header-buttons';
|
|||||||
import { BranchesScreen } from '@/features/repository/screens/branches-screen';
|
import { BranchesScreen } from '@/features/repository/screens/branches-screen';
|
||||||
import { CommitDetailScreen } from '@/features/repository/screens/commit-detail-screen';
|
import { CommitDetailScreen } from '@/features/repository/screens/commit-detail-screen';
|
||||||
import { CommitsScreen } from '@/features/repository/screens/commits-screen';
|
import { CommitsScreen } from '@/features/repository/screens/commits-screen';
|
||||||
|
import { FileEditScreen } from '@/features/repository/screens/file-edit-screen';
|
||||||
import { FileViewerScreen } from '@/features/repository/screens/file-viewer-screen';
|
import { FileViewerScreen } from '@/features/repository/screens/file-viewer-screen';
|
||||||
import { FilesScreen } from '@/features/repository/screens/files-screen';
|
import { FilesScreen } from '@/features/repository/screens/files-screen';
|
||||||
import { IssueComposeScreen } from '@/features/repository/screens/issue-compose-screen';
|
import { IssueComposeScreen } from '@/features/repository/screens/issue-compose-screen';
|
||||||
@@ -61,6 +62,13 @@ export function RepositoryNavigator() {
|
|||||||
title: lastSegment(route.params.path, t('files.title')),
|
title: lastSegment(route.params.path, t('files.title')),
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
|
<Stack.Screen
|
||||||
|
name="FileEdit"
|
||||||
|
component={FileEditScreen}
|
||||||
|
options={({ route }) => ({
|
||||||
|
title: `${t('edit.title')} · ${lastSegment(route.params.path, t('files.title'))}`,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
name="Commits"
|
name="Commits"
|
||||||
component={CommitsScreen}
|
component={CommitsScreen}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ export type RepositoryStackParamList = {
|
|||||||
RepoOverview: { owner: string; name: string; ref?: string };
|
RepoOverview: { owner: string; name: string; ref?: string };
|
||||||
Files: { owner: string; name: string; path?: string; ref?: string };
|
Files: { owner: string; name: string; path?: string; ref?: string };
|
||||||
FileViewer: { owner: string; name: string; path: string; ref?: string };
|
FileViewer: { owner: string; name: string; path: string; ref?: string };
|
||||||
|
FileEdit: { owner: string; name: string; path: string; ref?: string };
|
||||||
Commits: { owner: string; name: string; sha?: string; path?: string };
|
Commits: { owner: string; name: string; sha?: string; path?: string };
|
||||||
CommitDetail: { owner: string; name: string; sha: string };
|
CommitDetail: { owner: string; name: string; sha: string };
|
||||||
Branches: { owner: string; name: string };
|
Branches: { owner: string; name: string };
|
||||||
|
|||||||
Reference in new issue
Block a user