-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
borders between questions, reorder rounds/questions/answers
- Loading branch information
Showing
5 changed files
with
270 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,6 @@ | |
|
||
## Host | ||
|
||
* Reorder questions | ||
* Dividers between questions | ||
* Reload on DELETE | ||
* Round names | ||
|
||
## Player | ||
|
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 |
---|---|---|
@@ -1,59 +1,184 @@ | ||
import { deepSet, removeAt } from "../utils"; | ||
import { deepSet, removeAt, reorder } from '../utils'; | ||
|
||
const ADD_ANSWER = "add_answer"; | ||
const CHANGE_ANSWER = "change_answer"; | ||
const DELETE_ANSWER = "delete_answer"; | ||
const ADD_ANSWER = 'add_answer'; | ||
const CHANGE_ANSWER = 'change_answer'; | ||
const DELETE_ANSWER = 'delete_answer'; | ||
const REORDER_ANSWER = 'reorder_answer'; | ||
|
||
const ADD_ROUND = "add_round"; | ||
const DELETE_ROUND = "delete_round"; | ||
const ADD_ROUND = 'add_round'; | ||
const DELETE_ROUND = 'delete_round'; | ||
const REORDER_ROUND = 'reorder_round'; | ||
|
||
const ADD_QUESTION = "add_question"; | ||
const CHANGE_QUESTION = "change_question"; | ||
const DELETE_QUESTION = "delete_question"; | ||
const ADD_QUESTION = 'add_question'; | ||
const CHANGE_QUESTION = 'change_question'; | ||
const DELETE_QUESTION = 'delete_question'; | ||
const REORDER_QUESTION = 'reorder_question'; | ||
|
||
const CHANGE_NAME = "change_name"; | ||
const CHANGE_NAME = 'change_name'; | ||
|
||
export const types = { | ||
ADD_ANSWER, | ||
CHANGE_ANSWER, | ||
DELETE_ANSWER, | ||
REORDER_ANSWER, | ||
ADD_ROUND, | ||
DELETE_ROUND, | ||
REORDER_ROUND, | ||
ADD_QUESTION, | ||
CHANGE_QUESTION, | ||
DELETE_QUESTION, | ||
REORDER_QUESTION, | ||
CHANGE_NAME | ||
}; | ||
|
||
export function draftGameReducer(state, action) { | ||
let fn; | ||
switch (action.type) { | ||
case ADD_ANSWER: | ||
return deepSet(state, [...state.quizRounds[action.roundIx].questions[action.qIx].answers, { answer: "", points: 0 }], ["quizRounds", action.roundIx, "questions", action.qIx, "answers"]); | ||
fn = add_answer; | ||
break; | ||
case CHANGE_ANSWER: | ||
return deepSet(state, { points: action.points, answer: action.answer }, ["quizRounds", action.roundIx, "questions", action.qIx, "answers", action.answerIx]); | ||
fn = change_answer; | ||
break; | ||
case DELETE_ANSWER: | ||
return deepSet(state, removeAt(state.quizRounds[action.roundIx].questions[action.qIx].answers, action.answerIx), ["quizRounds", action.roundIx, "questions", action.qIx, "answers"]); | ||
fn = delete_answer; | ||
break; | ||
case REORDER_ANSWER: | ||
fn = reorder_answer; | ||
break; | ||
case ADD_ROUND: | ||
return deepSet(state, [...state.quizRounds, { questions: [] }], "quizRounds"); | ||
fn = add_round; | ||
break; | ||
case DELETE_ROUND: | ||
return deepSet(state, removeAt(state.quizRounds, action.roundIx), "quizRounds"); | ||
fn = delete_round; | ||
break; | ||
case REORDER_ROUND: | ||
fn = reorder_round; | ||
break; | ||
case ADD_QUESTION: | ||
return deepSet(state, [...state.quizRounds[action.roundIx].questions, { question: "", answers: [] }], ["quizRounds", action.roundIx, "questions"]); | ||
fn = add_question; | ||
break; | ||
case CHANGE_QUESTION: | ||
return deepSet( | ||
state, | ||
{ | ||
question: action.question, | ||
answers: state.quizRounds[action.roundIx].questions[action.qIx].answers | ||
}, | ||
["quizRounds", action.roundIx, "questions", action.qIx] | ||
); | ||
fn = change_question; | ||
break; | ||
case DELETE_QUESTION: | ||
return deepSet(state, removeAt(state.quizRounds[action.roundIx].questions, action.qIx), ["quizRounds", action.roundIx, "questions"]); | ||
fn = delete_question; | ||
break; | ||
case REORDER_QUESTION: | ||
fn = reorder_question; | ||
break; | ||
case CHANGE_NAME: | ||
return deepSet(state, action.name, "quizName"); | ||
fn = change_name; | ||
break; | ||
default: | ||
console.log(`INVALID ACTION ${action.type}`); | ||
return state; | ||
fn = invalid_action; | ||
break; | ||
} | ||
return fn(state, action); | ||
} | ||
|
||
export const types = { | ||
ADD_ANSWER, | ||
CHANGE_ANSWER, | ||
DELETE_ANSWER, | ||
ADD_ROUND, | ||
DELETE_ROUND, | ||
ADD_QUESTION, | ||
CHANGE_QUESTION, | ||
DELETE_QUESTION, | ||
CHANGE_NAME | ||
}; | ||
function add_answer(state, action) { | ||
return deepSet( | ||
state, | ||
[ | ||
...state.quizRounds[action.roundIx].questions[action.qIx].answers, | ||
{ answer: '', points: 0 } | ||
], | ||
['quizRounds', action.roundIx, 'questions', action.qIx, 'answers'] | ||
); | ||
} | ||
|
||
function change_answer(state, action) { | ||
return deepSet(state, { points: action.points, answer: action.answer }, [ | ||
'quizRounds', | ||
action.roundIx, | ||
'questions', | ||
action.qIx, | ||
'answers', | ||
action.answerIx | ||
]); | ||
} | ||
|
||
function delete_answer(state, action) { | ||
return deepSet( | ||
state, | ||
removeAt( | ||
state.quizRounds[action.roundIx].questions[action.qIx].answers, | ||
action.answerIx | ||
), | ||
['quizRounds', action.roundIx, 'questions', action.qIx, 'answers'] | ||
); | ||
} | ||
|
||
function reorder_answer(state, action) { | ||
return reorder(state, action.answerIx, action.step, [ | ||
'quizRounds', | ||
action.roundIx, | ||
'questions', | ||
action.qIx, | ||
'answers' | ||
]); | ||
} | ||
|
||
function add_round(state, _action) { | ||
return deepSet(state, [...state.quizRounds, { questions: [] }], 'quizRounds'); | ||
} | ||
|
||
function delete_round(state, action) { | ||
return deepSet( | ||
state, | ||
removeAt(state.quizRounds, action.roundIx), | ||
'quizRounds' | ||
); | ||
} | ||
|
||
function reorder_round(state, action) { | ||
return reorder(state, action.roundIx, action.step, ['quizRounds']); | ||
} | ||
|
||
function add_question(state, action) { | ||
return deepSet( | ||
state, | ||
[ | ||
...state.quizRounds[action.roundIx].questions, | ||
{ question: '', answers: [] } | ||
], | ||
['quizRounds', action.roundIx, 'questions'] | ||
); | ||
} | ||
|
||
function change_question(state, action) { | ||
return deepSet( | ||
state, | ||
{ | ||
question: action.question, | ||
answers: state.quizRounds[action.roundIx].questions[action.qIx].answers | ||
}, | ||
['quizRounds', action.roundIx, 'questions', action.qIx] | ||
); | ||
} | ||
|
||
function delete_question(state, action) { | ||
return deepSet( | ||
state, | ||
removeAt(state.quizRounds[action.roundIx].questions, action.qIx), | ||
['quizRounds', action.roundIx, 'questions'] | ||
); | ||
} | ||
|
||
function reorder_question(state, action) { | ||
return reorder(state, action.qIx, action.step, [ | ||
'quizRounds', | ||
action.roundIx, | ||
'questions' | ||
]); | ||
} | ||
|
||
function change_name(state, action) { | ||
return deepSet(state, action.name, 'quizName'); | ||
} | ||
|
||
function invalid_action(state, action) { | ||
console.log(`INVALID ACTION ${action.type}`); | ||
return state; | ||
} |
Oops, something went wrong.