diff --git a/src/components/Question.js b/src/components/Question.js
index 8c100db..a8b30dd 100644
--- a/src/components/Question.js
+++ b/src/components/Question.js
@@ -1,27 +1,41 @@
-import React, { PureComponent } from 'react'
+import React from 'react'
-class Question extends PureComponent {
- render() {
- const { question } = this.props
-
- let qdata = question.data
- if (typeof qdata === 'object' && qdata.type === 'simple') {
- qdata = ''
- }
- if (qdata) {
- try {
- qdata = JSON.stringify(qdata)
- } catch (e) {}
- }
-
- return (
-
-
{question.Q}
-
{question.A}
-
{qdata || null}
-
- )
- }
+function highlightText(text, toHighlight) {
+ const re = new RegExp(toHighlight, 'gi')
+ return text.replace(re, `${toHighlight}`)
}
-export default Question
+export default function Question({ question, searchTerm }) {
+ let qdata = question.data
+ if (typeof qdata === 'object' && qdata.type === 'simple') {
+ qdata = ''
+ }
+ if (qdata) {
+ try {
+ qdata = JSON.stringify(qdata)
+ } catch (e) {
+ //
+ }
+ }
+
+ const questionText = searchTerm
+ ? highlightText(question.Q, searchTerm)
+ : question.Q
+ const answerText = searchTerm
+ ? highlightText(question.A, searchTerm)
+ : question.A
+
+ return (
+
+ )
+}
diff --git a/src/components/QuestionSearchResult.js b/src/components/QuestionSearchResult.js
index b1eac5b..201fe03 100644
--- a/src/components/QuestionSearchResult.js
+++ b/src/components/QuestionSearchResult.js
@@ -73,7 +73,7 @@ export default function QuestionSearchResult({ data, searchTerm }) {
)
diff --git a/src/components/Questions.js b/src/components/Questions.js
index a82563f..beda762 100644
--- a/src/components/Questions.js
+++ b/src/components/Questions.js
@@ -6,7 +6,7 @@ import styles from './Questions.module.css'
class Questions extends PureComponent {
render() {
- const { subjs } = this.props
+ const { subjs, searchTerm } = this.props
return (
@@ -16,7 +16,13 @@ class Questions extends PureComponent {
{subj.Name}
{subj.Questions.map((question, i) => {
- return
+ return (
+
+ )
})}
)
diff --git a/src/pages/allQuestions.js b/src/pages/allQuestions.js
index cb3b98b..ae4196f 100644
--- a/src/pages/allQuestions.js
+++ b/src/pages/allQuestions.js
@@ -89,6 +89,7 @@ export default function AllQuestions({ router }) {
const querySearch = router.query.question
? decodeURIComponent(router.query.question)
: ''
+
console.log(querySearch)
fetchDbs().then((res) => {