-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: move selectors to their own directory and files.
- Loading branch information
1 parent
c99ddfb
commit 0576f44
Showing
9 changed files
with
103 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { RootState } from '../stores/store'; | ||
|
||
export const selectPlayers = (state: RootState) => { | ||
const status = state.quiz.status.data; | ||
|
||
if (status === null) { | ||
return []; | ||
} | ||
|
||
return status.players; | ||
} | ||
|
||
export const selectQuestion = (state: RootState, questionIndex: number) => { | ||
const quiz = state.quiz; | ||
|
||
const questions = quiz.questions.data; | ||
const votes = quiz.votes.data; | ||
|
||
if (questions === null || votes === null) { | ||
return null; | ||
} | ||
|
||
return questions[questionIndex]; | ||
} | ||
|
||
export const selectAnswer = (state: RootState, questionIndex: number) => { | ||
const quiz = state.quiz; | ||
|
||
const questions = quiz.questions.data; | ||
const votes = quiz.votes.data; | ||
|
||
if (questions === null || votes === null) { | ||
return null; | ||
} | ||
|
||
const question = questions[questionIndex]; | ||
const vote = votes[questionIndex]; | ||
const answer = question.options[vote]; | ||
|
||
return answer; | ||
} | ||
|
||
export const selectCorrectAnswer = (state: RootState, questionIndex: number) => { | ||
const quiz = state.quiz; | ||
|
||
const questions = quiz.questions.data; | ||
|
||
if (questions === null) { | ||
return null; | ||
} | ||
|
||
const question = questions[questionIndex]; | ||
const answer = question.options[question.answer]; | ||
|
||
return answer; | ||
} | ||
|
||
export const selectVote = (state: RootState, questionIndex: number) => { | ||
const quiz = state.quiz; | ||
|
||
const questions = quiz.questions.data; | ||
const votes = quiz.votes.data; | ||
|
||
if (questions === null || votes === null || votes.length < questionIndex + 1) { | ||
return { | ||
voteIndex: null, | ||
vote: null, | ||
}; | ||
} | ||
|
||
const question = questions[questionIndex]; | ||
const voteIndex = votes[questionIndex]; | ||
const vote = question.options[voteIndex]; | ||
|
||
return { | ||
voteIndex, | ||
vote, | ||
}; | ||
} | ||
|
||
export const haveAllPlayersAnswered = (state: RootState, questionIndex: number) => { | ||
const quiz = state.quiz; | ||
|
||
const status = quiz.status.data; | ||
const votes = quiz.votes.data; | ||
const players = selectPlayers(state); | ||
|
||
if (status === null || votes === null || players === null) { | ||
return false; | ||
} | ||
|
||
const { votesCount } = status; | ||
|
||
return votesCount[questionIndex] === players.length; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { RootState } from '../stores/store'; | ||
|
||
export const selectAuthentication = (state: RootState) => state.user; |