Skip to content

Commit

Permalink
Suppression de la lib array-french-word-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Neleoko committed Apr 1, 2024
1 parent c8bf61e commit dc9f5a0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 37 deletions.
6 changes: 0 additions & 6 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"@types/node": "^16.18.71",
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"array-french-word-ts": "^1.0.0",
"axios": "^1.6.7",
"localforage": "^1.10.0",
"match-sorter": "^6.3.3",
Expand Down
7 changes: 3 additions & 4 deletions src/components/DictionaryRuleProcessor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import { type Theme } from '../type'
export type DictionaryRuleProcessorPros = {
setAnswer: (answer: string) => void
locationDifficulty: LocationDifficulty
alias: string
style: string
}

export default function DictionaryRuleProcessor ({
setAnswer,
locationDifficulty,
alias
style
}: DictionaryRuleProcessorPros) {
const urlParams = 'mc'
const { data } = useApi<Theme[]>('/themes/byAlias/' + urlParams)
const { data } = useApi<Theme[]>('theme/alias/' + style)
const minLetters = 1
const maxLetters = 10
const wordsUtils = new WordsUtils()
Expand Down
24 changes: 17 additions & 7 deletions src/components/InputAnswer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { useState } from 'react'
import { type LocationDifficulty } from '../entities/LocationDifficulty'
import { WordsUtils } from '../utils/WordsUtils'
import useApi from '../hook/useApi'
import type { Word } from '../type'
import type { Theme, Word } from '../type'

export type WordHistoryProps = {
answer: string
Expand All @@ -11,21 +10,21 @@ export type WordHistoryProps = {
inputValue: string
setInputValue: (answer: string) => void
locationDifficulty: LocationDifficulty
style: string
}
export default function InputAnswer ({
answer,
historyInput,
setHistoryInput,
inputValue,
setInputValue,
locationDifficulty
locationDifficulty,
style
}: WordHistoryProps) {
const [textErrorInput, setTextErrorInput] = useState<string>('')
const nbInputStringLeft = answer.length - inputValue.length
const wordsUtils = new WordsUtils()
const [win, setWin] = useState(false)
const { data: wordsDataApi } = useApi<Word[]>('/words/')

const { data: wordsDataApi } = useApi<Theme[]>('theme/alias/' + style)
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setInputValue(event.target.value)
}
Expand All @@ -42,11 +41,22 @@ export default function InputAnswer ({
}

async function errorInput (wordInput: string): Promise<boolean> {
const wordExists = await wordsUtils.wordDontExist(wordInput.toLowerCase(), wordsDataApi)
const wordExists = await wordDontExist(wordInput.toLowerCase())
setTextErrorInput(wordExists ? '' : `Le mot ${wordInput} n'existe pas dans le dictionnaire. Veuillez réessayer.`)
return wordExists
}

async function wordDontExist (searchedWord: string): Promise<boolean> {
if (!wordsDataApi) {
throw new Error('No data')
}

const wordDoesExistApi = wordsDataApi[0].words.some((word: Word) => word.word === searchedWord.toLowerCase()) // si le mot existe dans l'api return true, sinon false
if (!wordDoesExistApi) return false // si le mot n'existe pas dans l'api ou dans la librairie return false

return true
}

const handlePressEnter = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Enter') {
handleClick()
Expand Down
5 changes: 3 additions & 2 deletions src/home/Motus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ export default function Motus () {
}

const theme: string = location.state.style

useEffect(() => {
document.body.classList.add(theme) // Récupérer la classe envoyée

return () => {
document.body.classList.remove(theme)
}
}, [])
console.log(answer)

return (
<section>
<div className="column-left">
<DictionaryRuleProcessor
setAnswer={setAnswer} locationDifficulty={locationDifficulty} alias={location.state.alias}
setAnswer={setAnswer} locationDifficulty={locationDifficulty} style={location.state.style}
/>
<div>

Expand All @@ -58,6 +58,7 @@ export default function Motus () {
inputValue={inputValue}
setInputValue={setInputValue}
locationDifficulty={locationDifficulty}
style={location.state.style}
/>
<WordHistory
answer={answer}
Expand Down
1 change: 0 additions & 1 deletion src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export interface Word {
id: number
word: string
definition: string
theme_id: number
}

export interface Theme {
Expand Down
16 changes: 0 additions & 16 deletions src/utils/WordsUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { getWordsFromFile } from 'array-french-word-ts'

import { type Word } from '../type'

export class WordsUtils {
Expand All @@ -11,18 +9,4 @@ export class WordsUtils {
word.length <= maxLetters)
)
}

public async wordDontExist (searchedWord: string, wordApiData: Word[] | undefined): Promise<boolean> {
if (!wordApiData) {
throw new Error('No data')
}
const wordDoesExistApi = wordApiData.some((word: Word) => word.word === searchedWord.toLowerCase()) // si le mot existe dans l'api return true, sinon false

const wordsArray = await getWordsFromFile()
const wordDoesExistLib = wordsArray.includes(searchedWord.toLowerCase()) // récupère le tableau de mots de la librairie

if (!wordDoesExistApi && !wordDoesExistLib) return false // si le mot n'existe pas dans l'api ou dans la librairie return false

return true // si le mot existe dans l'api et dans la librairie return true
}
}

0 comments on commit dc9f5a0

Please sign in to comment.