mirror of
https://github.com/silvanocerza/github-gitless-sync.git
synced 2026-07-22 12:10:28 +00:00
Handle conflict resolution
This commit is contained in:
parent
d8ebee26e8
commit
68c3b4e6df
2 changed files with 23 additions and 10 deletions
|
|
@ -14,7 +14,7 @@ const MobileApp = ({
|
|||
ConflictResolution[]
|
||||
>([]);
|
||||
|
||||
const onConflictResolved = (fileIndex: number) => {
|
||||
const onConflictResolved = (fileIndex: number, content: string) => {
|
||||
// Remove the file from the conflicts to resolve
|
||||
const remainingFiles = files.filter((_, index) => index !== fileIndex);
|
||||
setFiles(remainingFiles);
|
||||
|
|
@ -23,7 +23,7 @@ const MobileApp = ({
|
|||
...resolvedConflicts,
|
||||
{
|
||||
filePath: files[fileIndex].filePath,
|
||||
content: files[fileIndex].localContent,
|
||||
content,
|
||||
},
|
||||
];
|
||||
setResolvedConflicts(newResolvedConflicts);
|
||||
|
|
@ -57,7 +57,9 @@ const MobileApp = ({
|
|||
<UnifiedDiffView
|
||||
initialOldText={file.remoteContent || ""}
|
||||
initialNewText={file.localContent || ""}
|
||||
onConflictResolved={() => onConflictResolved(index)}
|
||||
onConflictResolved={(content: string) => {
|
||||
onConflictResolved(index, content);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import diff, { DiffChunk } from "./diff";
|
|||
interface UnifiedDiffViewProps {
|
||||
initialOldText: string;
|
||||
initialNewText: string;
|
||||
onConflictResolved: () => void;
|
||||
onConflictResolved: (content: string) => void;
|
||||
}
|
||||
|
||||
const createUnifiedDocument = (
|
||||
|
|
@ -219,6 +219,8 @@ const UnifiedDiffView: React.FC<UnifiedDiffViewProps> = ({
|
|||
initialNewText,
|
||||
onConflictResolved,
|
||||
}) => {
|
||||
const editorViewRef = React.useRef<EditorView | null>(null);
|
||||
|
||||
const diffChunks = diff(initialOldText, initialNewText);
|
||||
const { doc, lineRanges } = createUnifiedDocument(
|
||||
initialOldText,
|
||||
|
|
@ -250,7 +252,8 @@ const UnifiedDiffView: React.FC<UnifiedDiffViewProps> = ({
|
|||
"&": {
|
||||
backgroundColor: "var(--background-primary)",
|
||||
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": {
|
||||
padding: 0,
|
||||
|
|
@ -288,6 +291,9 @@ const UnifiedDiffView: React.FC<UnifiedDiffViewProps> = ({
|
|||
theme="none"
|
||||
basicSetup={false}
|
||||
extensions={extensions}
|
||||
onCreateEditor={(view: EditorView) => {
|
||||
editorViewRef.current = view;
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
|
|
@ -297,13 +303,18 @@ const UnifiedDiffView: React.FC<UnifiedDiffViewProps> = ({
|
|||
}}
|
||||
>
|
||||
<button
|
||||
style={{
|
||||
backgroundColor: "var(--interactive-accent)",
|
||||
color: "var(--text-on-accent)",
|
||||
}}
|
||||
style={
|
||||
hasConflicts
|
||||
? {}
|
||||
: {
|
||||
backgroundColor: "var(--interactive-accent)",
|
||||
color: "var(--text-on-accent)",
|
||||
}
|
||||
}
|
||||
disabled={hasConflicts}
|
||||
onClick={() => {
|
||||
console.log("Conflict resolved");
|
||||
const content = editorViewRef.current!.state.doc.toString();
|
||||
onConflictResolved(content);
|
||||
}}
|
||||
>
|
||||
Resolve conflict
|
||||
|
|
|
|||
Loading…
Reference in a new issue