Feat: added diff hint
This commit is contained in:
parent
9109554f45
commit
82b8a87b17
|
@ -14,6 +14,7 @@
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-checkbox-tree": "^1.8.0",
|
"react-checkbox-tree": "^1.8.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
|
"react-string-diff": "^0.2.0",
|
||||||
"underscore": "^1.13.6"
|
"underscore": "^1.13.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -17,6 +17,9 @@ dependencies:
|
||||||
react-dom:
|
react-dom:
|
||||||
specifier: ^18.2.0
|
specifier: ^18.2.0
|
||||||
version: 18.2.0(react@18.2.0)
|
version: 18.2.0(react@18.2.0)
|
||||||
|
react-string-diff:
|
||||||
|
specifier: ^0.2.0
|
||||||
|
version: 0.2.0(react@18.2.0)
|
||||||
underscore:
|
underscore:
|
||||||
specifier: ^1.13.6
|
specifier: ^1.13.6
|
||||||
version: 1.13.6
|
version: 1.13.6
|
||||||
|
@ -842,6 +845,11 @@ packages:
|
||||||
object-keys: 1.1.1
|
object-keys: 1.1.1
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/diff@4.0.2:
|
||||||
|
resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==}
|
||||||
|
engines: {node: '>=0.3.1'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/doctrine@2.1.0:
|
/doctrine@2.1.0:
|
||||||
resolution: {integrity: sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==}
|
resolution: {integrity: sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
|
@ -1733,6 +1741,16 @@ packages:
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/react-string-diff@0.2.0(react@18.2.0):
|
||||||
|
resolution: {integrity: sha512-wB8Dr2T8CD/nuRMSEs9PHQ08e+o4a65SmkMZYrZRIEFzrbFpyrb9GuDmBwE7dxqcw06CqrLWXEuibUDJQX60LQ==}
|
||||||
|
engines: {node: '>=10'}
|
||||||
|
peerDependencies:
|
||||||
|
react: '>=16'
|
||||||
|
dependencies:
|
||||||
|
diff: 4.0.2
|
||||||
|
react: 18.2.0
|
||||||
|
dev: false
|
||||||
|
|
||||||
/react@18.2.0:
|
/react@18.2.0:
|
||||||
resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==}
|
resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.reference-box {
|
.reference-box {
|
||||||
min-width:400px;
|
max-width:400px;
|
||||||
height: 5vh;
|
height: 5vh;
|
||||||
display: block;
|
display: block;
|
||||||
width: 99%;
|
width: 99%;
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.chapter-title-box {
|
.chapter-title-box {
|
||||||
min-width:400px;
|
max-width:400px;
|
||||||
height: 5vh;
|
height: 5vh;
|
||||||
display: block;
|
display: block;
|
||||||
width: 99%;
|
width: 99%;
|
||||||
|
@ -40,8 +40,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.verse-box {
|
.verse-box {
|
||||||
/*padding: 5px;*/
|
max-width:400px;
|
||||||
min-width:400px;
|
|
||||||
height: 10vh;
|
height: 10vh;
|
||||||
display: block;
|
display: block;
|
||||||
width: 99%;
|
width: 99%;
|
||||||
|
@ -50,17 +49,19 @@
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.verse-box {
|
.answer-button-box {
|
||||||
/*padding: 5px;*/
|
display: flex;
|
||||||
min-width:400px;
|
gap: 10px;
|
||||||
height: 10vh;
|
padding-top: 10px;
|
||||||
display: block;
|
|
||||||
width: 99%;
|
|
||||||
border: 1px solid grey;
|
|
||||||
border-radius: 5px;
|
|
||||||
font-size: 15px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.answer-box {
|
||||||
|
width: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.diff-box {
|
||||||
|
width: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
.correct {
|
.correct {
|
||||||
background-color: #e6ffe6; /* Change the background color as needed */
|
background-color: #e6ffe6; /* Change the background color as needed */
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import "./VerseValidator.css";
|
import "./VerseValidator.css";
|
||||||
|
import { StringDiff } from "react-string-diff";
|
||||||
|
|
||||||
|
|
||||||
// function to render and handle logic of each of the cells
|
// function to render and handle logic of each of the cells
|
||||||
|
@ -14,6 +15,7 @@ const VerseValidator = ({ element: { pack, title, chapterTitle, reference, verse
|
||||||
const [inputVerse, setVerse] = useState('')
|
const [inputVerse, setVerse] = useState('')
|
||||||
const [verseBool, setVerseBool] = useState(false)
|
const [verseBool, setVerseBool] = useState(false)
|
||||||
const[hintBool, setHintBool] = useState(false)
|
const[hintBool, setHintBool] = useState(false)
|
||||||
|
const[diffBool, setDiffBool] = useState(false)
|
||||||
|
|
||||||
|
|
||||||
// function to check correctness of verse input
|
// function to check correctness of verse input
|
||||||
|
@ -96,39 +98,54 @@ const VerseValidator = ({ element: { pack, title, chapterTitle, reference, verse
|
||||||
setChapterTitleBool(bool);
|
setChapterTitleBool(bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DiffViewer = ({oldValue, newValue}) => {
|
||||||
|
const string1 = String(oldValue)
|
||||||
|
.replace(/[^\w\s]/g, "")
|
||||||
|
.toLowerCase();
|
||||||
|
|
||||||
|
const string2 = String(newValue)
|
||||||
|
.replace(/[^\w\s]/g, "")
|
||||||
|
.toLowerCase();
|
||||||
|
|
||||||
|
return (<StringDiff oldValue={string1} newValue={string2} diffMethod="diffWords" />)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="VerseValidator">
|
<div className="VerseValidator">
|
||||||
|
{/* toggle hiding reference */}
|
||||||
{toHideReference ? (
|
{toHideReference ? (
|
||||||
<div>
|
<div>
|
||||||
<label className="reference-label" htmlFor="referenceBox">
|
<label className="reference-label" htmlFor="referenceBox">
|
||||||
Input Verse Reference:
|
Input Verse Reference:
|
||||||
</label>
|
</label>
|
||||||
<textarea
|
<textarea
|
||||||
className={`reference-box${referenceBool ? ' correct' : ''}`}
|
className={`reference-box${referenceBool ? " correct" : ""}`}
|
||||||
type="text"
|
type="text"
|
||||||
id="referenceBox"
|
id="referenceBox"
|
||||||
name="referenceBox"
|
name="referenceBox"
|
||||||
onChange={referenceChange}
|
onChange={referenceChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
) : (
|
) : (
|
||||||
<h2>{pack} - {reference}</h2>
|
<h2>
|
||||||
|
{pack} - {reference}
|
||||||
|
</h2>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* toggle chapterTitle */}
|
||||||
{chapterTitle && (
|
{chapterTitle && (
|
||||||
<div>
|
<div>
|
||||||
<label className="main-title-box-label" htmlFor="chapterTitleBox">
|
<label className="main-title-box-label" htmlFor="chapterTitleBox">
|
||||||
Input Chapter Title:
|
Input Chapter Title:
|
||||||
</label>
|
</label>
|
||||||
<textarea
|
<textarea
|
||||||
className={`chapter-title-box${chapterTitleBool ? ' correct' : ''}`}
|
className={`chapter-title-box${chapterTitleBool ? " correct" : ""}`}
|
||||||
type="text"
|
type="text"
|
||||||
id="chapterTitleBox"
|
id="chapterTitleBox"
|
||||||
name="chapterTitleBox"
|
name="chapterTitleBox"
|
||||||
onChange={chapterTitleChange}
|
onChange={chapterTitleChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -137,7 +154,7 @@ const VerseValidator = ({ element: { pack, title, chapterTitle, reference, verse
|
||||||
Input Title:
|
Input Title:
|
||||||
</label>
|
</label>
|
||||||
<textarea
|
<textarea
|
||||||
className={`title-box${titleBool ? ' correct' : ''}`}
|
className={`title-box${titleBool ? " correct" : ""}`}
|
||||||
type="text"
|
type="text"
|
||||||
id="titleBox"
|
id="titleBox"
|
||||||
name="titleBox"
|
name="titleBox"
|
||||||
|
@ -149,24 +166,56 @@ const VerseValidator = ({ element: { pack, title, chapterTitle, reference, verse
|
||||||
Input Verse:
|
Input Verse:
|
||||||
</label>
|
</label>
|
||||||
<textarea
|
<textarea
|
||||||
className={`verse-box${verseBool ? ' correct' : ''}`}
|
className={`verse-box${verseBool ? " correct" : ""}`}
|
||||||
type="text"
|
type="text"
|
||||||
id="verseBox"
|
id="verseBox"
|
||||||
name="verseBox"
|
name="verseBox"
|
||||||
onChange={verseChange}
|
onChange={verseChange}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* button to toggle show answer*/}
|
|
||||||
<button onClick={() => setHintBool(!hintBool)}>Show Answer:</button>
|
|
||||||
|
|
||||||
{/* This shows the answers*/}
|
{/* button to toggle show answer*/}
|
||||||
|
<div className="answer-button-box">
|
||||||
|
<button onClick={() => setHintBool(!hintBool)}>Show Answer:</button>
|
||||||
|
<button onClick={() => setDiffBool(!diffBool)}>Show Diff:</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* This shows the answers*/}
|
||||||
{hintBool && (
|
{hintBool && (
|
||||||
<>
|
<div className="answer-box">
|
||||||
<p>{reference}</p>
|
<h3>Answers</h3>
|
||||||
<p>{chapterTitle}</p>
|
<p>Reference:<br />{reference}</p>
|
||||||
<p>{title}</p>
|
{chapterTitle && (
|
||||||
<p>{verse}</p>
|
<>
|
||||||
</>
|
<p>ChapterTitle<br />{chapterTitle}</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<p>Title:<br />{title}</p>
|
||||||
|
<p>Verse:<br />{verse}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* This shows the difference between given and input answers*/}
|
||||||
|
{diffBool && (
|
||||||
|
<div className="diff-box">
|
||||||
|
<h3>Differences</h3>
|
||||||
|
{chapterTitle && (
|
||||||
|
<div>
|
||||||
|
ChapterTitle:
|
||||||
|
<DiffViewer
|
||||||
|
oldValue={chapterTitle}
|
||||||
|
newValue={inputChapterTitle}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<p></p>
|
||||||
|
<div>
|
||||||
|
Title: <DiffViewer oldValue={title} newValue={inputTitle} />
|
||||||
|
</div>
|
||||||
|
<p></p>
|
||||||
|
<div>
|
||||||
|
Verse: <DiffViewer oldValue={verse} newValue={inputVerse} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue