Handle conflict resolution

This commit is contained in:
Silvano Cerza 2025-03-06 17:37:00 +01:00
parent d8ebee26e8
commit 68c3b4e6df
2 changed files with 23 additions and 10 deletions

View file

@ -14,7 +14,7 @@ const MobileApp = ({
ConflictResolution[] ConflictResolution[]
>([]); >([]);
const onConflictResolved = (fileIndex: number) => { const onConflictResolved = (fileIndex: number, content: string) => {
// Remove the file from the conflicts to resolve // Remove the file from the conflicts to resolve
const remainingFiles = files.filter((_, index) => index !== fileIndex); const remainingFiles = files.filter((_, index) => index !== fileIndex);
setFiles(remainingFiles); setFiles(remainingFiles);
@ -23,7 +23,7 @@ const MobileApp = ({
...resolvedConflicts, ...resolvedConflicts,
{ {
filePath: files[fileIndex].filePath, filePath: files[fileIndex].filePath,
content: files[fileIndex].localContent, content,
}, },
]; ];
setResolvedConflicts(newResolvedConflicts); setResolvedConflicts(newResolvedConflicts);
@ -57,7 +57,9 @@ const MobileApp = ({
<UnifiedDiffView <UnifiedDiffView
initialOldText={file.remoteContent || ""} initialOldText={file.remoteContent || ""}
initialNewText={file.localContent || ""} initialNewText={file.localContent || ""}
onConflictResolved={() => onConflictResolved(index)} onConflictResolved={(content: string) => {
onConflictResolved(index, content);
}}
/> />
</div> </div>
); );

View file

@ -7,7 +7,7 @@ import diff, { DiffChunk } from "./diff";
interface UnifiedDiffViewProps { interface UnifiedDiffViewProps {
initialOldText: string; initialOldText: string;
initialNewText: string; initialNewText: string;
onConflictResolved: () => void; onConflictResolved: (content: string) => void;
} }
const createUnifiedDocument = ( const createUnifiedDocument = (
@ -219,6 +219,8 @@ const UnifiedDiffView: React.FC<UnifiedDiffViewProps> = ({
initialNewText, initialNewText,
onConflictResolved, onConflictResolved,
}) => { }) => {
const editorViewRef = React.useRef<EditorView | null>(null);
const diffChunks = diff(initialOldText, initialNewText); const diffChunks = diff(initialOldText, initialNewText);
const { doc, lineRanges } = createUnifiedDocument( const { doc, lineRanges } = createUnifiedDocument(
initialOldText, initialOldText,
@ -250,7 +252,8 @@ const UnifiedDiffView: React.FC<UnifiedDiffViewProps> = ({
"&": { "&": {
backgroundColor: "var(--background-primary)", backgroundColor: "var(--background-primary)",
color: "var(--text-normal)", color: "var(--text-normal)",
border: "1px solid var(--background-modifier-border)", borderTop: "1px solid var(--background-modifier-border)",
borderBottom: "1px solid var(--background-modifier-border)",
}, },
".cm-content": { ".cm-content": {
padding: 0, padding: 0,
@ -288,6 +291,9 @@ const UnifiedDiffView: React.FC<UnifiedDiffViewProps> = ({
theme="none" theme="none"
basicSetup={false} basicSetup={false}
extensions={extensions} extensions={extensions}
onCreateEditor={(view: EditorView) => {
editorViewRef.current = view;
}}
/> />
<div <div
style={{ style={{
@ -297,13 +303,18 @@ const UnifiedDiffView: React.FC<UnifiedDiffViewProps> = ({
}} }}
> >
<button <button
style={{ style={
backgroundColor: "var(--interactive-accent)", hasConflicts
color: "var(--text-on-accent)", ? {}
}} : {
backgroundColor: "var(--interactive-accent)",
color: "var(--text-on-accent)",
}
}
disabled={hasConflicts} disabled={hasConflicts}
onClick={() => { onClick={() => {
console.log("Conflict resolved"); const content = editorViewRef.current!.state.doc.toString();
onConflictResolved(content);
}} }}
> >
Resolve conflict Resolve conflict