Skip to content

Commit

Permalink
Making Cards disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
NegarSal committed Mar 10, 2024
1 parent 2965909 commit 33c645f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function App() {
const [turns, setTurns] = useState(0)
const [choiceOne, setChoiceOne] = useState(null)
const [choiceTwo, setChoiceTwo] = useState(null)
const [disabled, setDisabled] = useState(false)

// shuffle cards
const shuffleCards = () => {
Expand All @@ -33,6 +34,7 @@ function App() {
// compare 2 selected cards
useEffect(() => {
if (choiceOne && choiceTwo) {
setDisabled(true)
if (choiceOne.src === choiceTwo.src) {
setCards(prevCards => {
return prevCards.map(card => {
Expand All @@ -57,6 +59,7 @@ function App() {
setChoiceOne(null)
setChoiceTwo(null)
setTurns(prevTurns => prevTurns + 1)
setDisabled(false)
}

return (
Expand All @@ -71,6 +74,7 @@ function App() {
card={card}
handleChoice={handleChoice}
flipped={card === choiceOne || card === choiceTwo || card.matched}
disabled={disabled}
/>
))}
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/components/SingleCard.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import './SingleCard.css'

export default function SingleCard({ card, handleChoice, flipped }) {
export default function SingleCard({ card, handleChoice, flipped, disabled }) {

const handleClick = () => {
handleChoice(card)
if (!disabled) {
handleChoice(card)
}
}

return (
Expand Down

0 comments on commit 33c645f

Please sign in to comment.