Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added validation to current row submission #8

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Jing1524
Copy link

@Jing1524 Jing1524 commented Jun 25, 2023

Updates:

Added 2 piece of states: invalidWordError and wordList to handle the current row validation.

const [wordList, setWordList] = useState<string[]>([])
// Added state for invalid word error
const [invalidWordError, setInvalidWordError] = useState(false)
const [invalidWordRowIndex, setInvalidWordRowIndex] = useState(-1)

below is the check for the current row:
const isValidWord = wordList.includes(currentRow.join('').toLowerCase())
if (!isValidWord) {
setInvalidWordError(true)
setInvalidWordRowIndex(currentRowIndex) // Store the index of the invalid word
return // prevent user going to next row after invalid error thrown
}

Also updated below to clear the background color when the word is invalid, while not interrupt the previous row background color:

if (
wordleSolution === '' ||
letter === '' ||
userSolution[rowIndex] === '' ||
(invalidWordError && rowIndex === invalidWordRowIndex)
) {
className = ''

Aside from the logic, also updated the background color for incorrect letter, so its more readable.

Fixes #2

@vercel
Copy link

vercel bot commented Jun 25, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-wordle-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2023 0:08am

@Jing1524 Jing1524 changed the title added validation to current row submission [WIP]: added validation to current row submission Jun 25, 2023
@Jing1524 Jing1524 changed the title [WIP]: added validation to current row submission Added validation to current row submission Jun 26, 2023
@Jing1524
Copy link
Author

@kirandash This PR is ready for review when you get a chance :) Im trying to assign you as reviewer, but for some reason it won't let me. so im leaving a comment here.

Copy link
Member

@kirandash kirandash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Jing1524 Thanks for the PR 🙏🏻

It's awesome ⭐️

There is just a minor bug though. Please fix it before I can merge. Feel free to let me know if you face any issues.

And sorry for the late response.

setInvalidWordRowIndex(currentRowIndex) // Store the index of the invalid word
return // prevent user going to next row after invalid error thrown
}

Copy link
Member

@kirandash kirandash Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also do setInvalidWordError(false) in your code.

Because of this there is a bug now. If you enter a wrong word, it's showing the error message properly. But when user corrects the word, the highlighting of letters does not work. Because invalidWordError is still true.

How to Fix?

  1. You can do setInvalidWordError(false) here in else condition or,
  2. Run a timer and set it to false after 2 seconds or
  3. Set it to false when user hits "Backspace"

I would prefer the second option since that's what is implemented on the official wordle site https://www.nytimes.com/games/wordle/index.html

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Point!

will sort that out later today, and let you know once im done! Thank you for the feedback. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check if current row submission is not in the list of words and throw invalid word error if true
2 participants