diff --git a/renderer/src/components/TextTranslationMerge/TranslationMergeUI.jsx b/renderer/src/components/TextTranslationMerge/TranslationMergeUI.jsx index f47180c3..ff96e9bb 100644 --- a/renderer/src/components/TextTranslationMerge/TranslationMergeUI.jsx +++ b/renderer/src/components/TextTranslationMerge/TranslationMergeUI.jsx @@ -237,7 +237,7 @@ function TranslationMergeUI() { (usfmJsons.current && usfmJsons.imported) ? (
- +
) : ( diff --git a/renderer/src/components/TextTranslationMerge/UsfmConflictEditor.jsx b/renderer/src/components/TextTranslationMerge/UsfmConflictEditor.jsx index 69c9b8ea..0b42c6c4 100644 --- a/renderer/src/components/TextTranslationMerge/UsfmConflictEditor.jsx +++ b/renderer/src/components/TextTranslationMerge/UsfmConflictEditor.jsx @@ -1,10 +1,14 @@ /* eslint-disable no-nested-ternary */ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; - -function UsfmConflictEditor({ usfmJsons, currentProjectMeta }) { - console.log({ usfmJsons, currentProjectMeta }); - +import DiffMatchPatch from 'diff-match-patch'; + +const dmp = new DiffMatchPatch(); +function UsfmConflictEditor({ usfmJsons, currentProjectMeta, selectedChapter }) { + console.log({ usfmJsons, currentProjectMeta, selectedChapter }); + const [currentChapterVerses, setCurrentChapterVerses] = useState(); + const [importedChapterVerses, setImportedChapterVerses] = useState(); + const [haveConflict, setHaveConflict] = useState([]); const [resolveAllActive, setResolveALlActive] = useState(); const [resetAlll, setResetAll] = useState(); const { t } = useTranslation(); @@ -20,7 +24,52 @@ function UsfmConflictEditor({ usfmJsons, currentProjectMeta }) { const resetAllResolved = () => { console.log('reset all conflict '); }; + const displayContent = (selectedChapter) => { + const currentContent = usfmJsons.current.chapters; + const importContent = usfmJsons.imported.chapters; + // console.log(currentContent); + const currentVerses = currentContent.map((value) => { + if (value.chapterNumber === selectedChapter) { + const verses = value.contents.filter((item) => item?.verseNumber); + console.log(verses); + return verses; + } + }); + const currentValue = currentVerses.filter((item) => item)[0]; + const importedVerses = importContent.map((value) => { + if (value.chapterNumber === selectedChapter) { + const verses = value.contents.filter((item) => item?.verseNumber); + console.log(verses); + return verses; + } + }); + const importedValue = importedVerses.filter((item) => item)[0]; + const conflicts = []; + currentValue?.map((current, index) => { + if (current.verseNumber === (importedValue && importedValue[index].verseNumber)) { + // const diffOut = dmp.diff_main(current.verseText, importedValue[index].verseText); + // console.log(diffOut); + if (current.verseText !== importedValue[index].verseText) { + conflicts.push(current.verseNumber); + } + } + }); + console.log(currentValue, importedValue); + console.log({ conflicts }); + setHaveConflict(conflicts); + setCurrentChapterVerses(currentValue); + setImportedChapterVerses(importedValue); + }; + + // const findDifference =(selectedChapter)=>{ + // } + useEffect(() => { + if (selectedChapter) { + displayContent(selectedChapter); + // findDifference(selectedChapter) + } + }, [selectedChapter]); return (
{/* Header and Buttons */} @@ -82,6 +131,44 @@ function UsfmConflictEditor({ usfmJsons, currentProjectMeta }) { {/* Content */}
+
+ {currentChapterVerses?.map((verse, index) => ( +
+

{verse.verseNumber}

+
+
+ {verse.contents?.map((data, index) => ( +

+ {/* {console.log(typeof data === 'string' ? data : JSON.stringify(data.s5) || JSON.stringify(data.p))} */} + {typeof data === 'string' ? data : JSON.stringify(data.s5) || JSON.stringify(data.p)} +

+ ))} +
+
+ {importedChapterVerses && importedChapterVerses[index].contents?.map((data, index) => ( +

+ {/* {console.log(typeof data === 'string' ? data : JSON.stringify(data.s5) || JSON.stringify(data.p))} */} + {typeof data === 'string' ? data : JSON.stringify(data.s5) || JSON.stringify(data.p)} +

+ ))} +
+
+
+ ))} +
+ {/*
+ {importedChapterVerses?.map((verse) => ( + <> +

{verse.verseNumber}

+ {verse.contents?.map((data, index) => ( +

+ {console.log(typeof data === 'string' ? data : JSON.stringify(data.s5) || JSON.stringify(data.p))} + {typeof data === 'string' ? data : JSON.stringify(data.s5) || JSON.stringify(data.p)} +

+ ))} + + ))} +
*/} {/* {selectedFileContent.map((content, index) => (