feat: inline review-comment composer + WebView code editor
- diff lines are tappable; PullDiff opens a composer that posts a positioned inline review comment (path + new_position) - CodeEditor: self-contained WebView editor with line numbers, tab handling and lightweight syntax highlighting (no remote code / bundled editor assets); used by Quick Edit - i18n (en/nl) for inline comments
This commit is contained in:
1 parent
587bf732b5
commit
eed9c91274
6 files changed
+294
-19
No files matched your search
@@ -3,6 +3,7 @@ import { Alert, StyleSheet, Switch, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { CodeEditor, languageForPath } from '@/components/git/code-editor';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card } from '@/components/ui/card';
|
||||
@@ -170,15 +171,13 @@ function FileEditForm({ owner, name, path, initialRef, entry, repo, branches, on
|
||||
) : null}
|
||||
</View>
|
||||
|
||||
<TextArea
|
||||
value={draft}
|
||||
onChangeText={setDraft}
|
||||
minHeight={360}
|
||||
mono
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
testID="file-editor"
|
||||
/>
|
||||
<View style={styles.editorWrap}>
|
||||
<CodeEditor
|
||||
value={draft}
|
||||
onChangeText={setDraft}
|
||||
language={languageForPath(path)}
|
||||
/>
|
||||
</View>
|
||||
|
||||
{branchProtected ? (
|
||||
<AppText variant="caption" tone="warning">
|
||||
@@ -285,6 +284,7 @@ function FileEditForm({ owner, name, path, initialRef, entry, repo, branches, on
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
toolbar: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm },
|
||||
editorWrap: { height: 380, borderRadius: 10, overflow: 'hidden' },
|
||||
pathLabel: { flex: 1 },
|
||||
sectionLabel: { marginBottom: spacing.sm },
|
||||
switchRow: {
|
||||
|
||||
@@ -1,20 +1,33 @@
|
||||
import { useState } from 'react';
|
||||
import { Alert, StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { DiffView } from '@/components/git/diff';
|
||||
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 { TextArea } from '@/components/ui/text-area';
|
||||
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import { usePullDiff } from '@/features/issues/queries';
|
||||
import { useCreatePullReview, usePull, usePullDiff } from '@/features/issues/queries';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<RepositoryStackParamList, 'PullDiff'>;
|
||||
|
||||
/** Native unified diff for a pull request (all files, or a single `path`). */
|
||||
/** Native unified diff for a pull request (all files, or a single `path`).
|
||||
* Tapping a line opens an inline review-comment composer. */
|
||||
export function PullDiffScreen({ route }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { owner, name, index, path } = route.params;
|
||||
const query = usePullDiff(owner, name, index);
|
||||
const pull = usePull(owner, name, index);
|
||||
const createReview = useCreatePullReview(owner, name, index);
|
||||
|
||||
const [target, setTarget] = useState<{ path: string; position: number } | null>(null);
|
||||
const [body, setBody] = useState('');
|
||||
|
||||
if (query.isPending) return <LoadingView label={t('pulls.loadingDiff')} />;
|
||||
if (query.isError) {
|
||||
@@ -28,9 +41,74 @@ export function PullDiffScreen({ route }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
const submit = () => {
|
||||
if (!target || body.trim().length === 0) return;
|
||||
createReview.mutate(
|
||||
{
|
||||
event: 'COMMENT',
|
||||
commitId: pull.data?.head?.sha,
|
||||
comments: [{ path: target.path, new_position: target.position, body: body.trim() }],
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
setTarget(null);
|
||||
setBody('');
|
||||
Alert.alert(t('pulls.inlineCommentAddedTitle'), t('pulls.inlineCommentAddedBody'));
|
||||
},
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Screen padded={false} scroll={false}>
|
||||
<DiffView raw={query.data ?? ''} pathFilter={path} emptyLabel={t('pulls.noChanges')} />
|
||||
<DiffView
|
||||
raw={query.data ?? ''}
|
||||
pathFilter={path}
|
||||
emptyLabel={t('pulls.noChanges')}
|
||||
onLinePress={(filePath, position) => {
|
||||
setTarget({ path: filePath, position });
|
||||
setBody('');
|
||||
}}
|
||||
/>
|
||||
|
||||
{target ? (
|
||||
<Card style={styles.composer}>
|
||||
<AppText variant="caption" tone="tertiary" numberOfLines={1}>
|
||||
<AppText variant="monoSmall" tone="tertiary">
|
||||
{target.path}
|
||||
</AppText>
|
||||
{` : ${target.position}`}
|
||||
</AppText>
|
||||
<TextArea
|
||||
value={body}
|
||||
onChangeText={setBody}
|
||||
placeholder={t('pulls.inlineCommentPlaceholder')}
|
||||
minHeight={72}
|
||||
autoFocus
|
||||
/>
|
||||
<View style={styles.composerActions}>
|
||||
<Button
|
||||
label={t('common.cancel')}
|
||||
variant="ghost"
|
||||
size="md"
|
||||
onPress={() => setTarget(null)}
|
||||
/>
|
||||
<Button
|
||||
label={t('pulls.inlineCommentSubmit')}
|
||||
size="md"
|
||||
loading={createReview.isPending}
|
||||
disabled={body.trim().length === 0}
|
||||
onPress={submit}
|
||||
/>
|
||||
</View>
|
||||
</Card>
|
||||
) : null}
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
composer: { gap: spacing.sm, borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: 'rgba(128,128,128,0.3)' },
|
||||
composerActions: { flexDirection: 'row', justifyContent: 'flex-end', gap: spacing.sm },
|
||||
});
|
||||
Reference in new issue
Block a user