Skip to content

Commit

Permalink
Enahnce Wikipedia link
Browse files Browse the repository at this point in the history
  • Loading branch information
Dvd848 committed Feb 18, 2024
1 parent 3b3d0c3 commit 836ef44
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
11 changes: 10 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/bootstrap": "^5.2.10",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^6.21.0",
Expand Down
2 changes: 1 addition & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ h3 {
#loader {
margin: 20px auto;
text-align: center;
}
}
28 changes: 24 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState, Dispatch, SetStateAction } from 'react'
import { useEffect, useState, Dispatch, SetStateAction, useRef } from 'react'
import Header from './components/Header.tsx'
import { Tooltip } from 'bootstrap';
import './App.css'

type RawQuestion = {
Expand Down Expand Up @@ -241,6 +242,7 @@ const useGame = (question: ParsedQuestion, showNewQuestion: () => void, setNumQu

function Game({ question, showNewQuestion, setNumQuestionsCorrect }: GameProps) {
const words = question.parsedTitle.split(/\s+/);
const tooltipRef = useRef(null);

// TODO: There must be a better way...
const {
Expand All @@ -257,6 +259,19 @@ function Game({ question, showNewQuestion, setNumQuestionsCorrect }: GameProps)
return () => window.removeEventListener('keyup', handleKeyup)
}, [handleKeyup]);

useEffect(() => {
if (tooltipRef.current != null) {
const tooltip = new Tooltip(tooltipRef.current, {
container: 'body',
trigger: 'hover',
});

return () => {
tooltip.dispose();
};
}
}, []);

let currentGuessIndex = 0;
const description = (isCorrect) ? question.description : question.censoredDescription;
const wikiPage = "https://he.wikipedia.org/?curid=" + question.pageid;
Expand Down Expand Up @@ -298,7 +313,12 @@ function Game({ question, showNewQuestion, setNumQuestionsCorrect }: GameProps)
))
}
</div>
<div id="reference">מקור: <a href={wikiPage} target="_BLANK">ויקיפדיה</a>, רשיון: <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA</a></div>
<div id="reference">
מקור: <a href={wikiPage} ref={tooltipRef} target="_BLANK" data-bs-toggle="tooltip"
data-bs-title="זהירות! לחיצה על הקישור תוביל לדף הערך בויקיפדיה ותחשוף את התשובה!"
onClick={showNewQuestion} onAuxClick={showNewQuestion}>ויקיפדיה</a>,
רשיון: <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA</a>
</div>
</div>
<div style={{textAlign: "center"}}>
{!isCorrect && <button onClick={checkSolution} className='btn btn-dark'>בדיקת הפתרון</button>}
Expand Down Expand Up @@ -355,7 +375,7 @@ function App(): JSX.Element {
const MIN_DESC_LENGTH = 150;
let rawQuestion : RawQuestion;

const skipTerms = [
const skipTermsInDesc = [
" " // Found in math articles which don't render correctly
]

Expand All @@ -369,7 +389,7 @@ function App(): JSX.Element {
throw new Error(`Skipping ${rawQuestion.title} since description length is smaller than minimum`);
}

if (skipTerms.some(forbiddenStr => rawQuestion.extract.includes(forbiddenStr))) {
if (skipTermsInDesc.some(forbiddenStr => rawQuestion.extract.includes(forbiddenStr))) {
throw new Error(`Skipping ${rawQuestion.title} since description contains forbidden term`);
}

Expand Down

0 comments on commit 836ef44

Please sign in to comment.