modaq
Version:
Quiz Bowl Reader using TypeScript, React, and MobX
57 lines • 2.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.throwOutTossup = exports.selectWordFromKeyboardEvent = exports.selectWordFromClick = void 0;
require("react");
const AppState_1 = require("../state/AppState");
require("../state/Cycle");
require("../state/UIState");
function selectWordFromClick(event) {
var _a;
const appState = AppState_1.AppState.instance;
const target = event.target;
// I'd like to avoid looking for a specific HTML element instead of a class. This would mean giving QuestionWord a
// fixed class.
const questionWord = target.closest("span");
if (questionWord == undefined || questionWord.getAttribute == undefined) {
return;
}
const index = parseInt((_a = questionWord.getAttribute("data-index")) !== null && _a !== void 0 ? _a : "", 10);
if (index < 0 || isNaN(index)) {
return;
}
const uiState = appState.uiState;
const selectedIndex = uiState.selectedWordIndex === index ? -1 : index;
uiState.setSelectedWordIndex(selectedIndex);
uiState.showBuzzMenu(/* clearSelectedWordOnClose */ true);
event.preventDefault();
event.stopPropagation();
}
exports.selectWordFromClick = selectWordFromClick;
function selectWordFromKeyboardEvent(event) {
const appState = AppState_1.AppState.instance;
const target = event.target;
// We're looking for spans with the word index that matches the selectedWordIndex
const selectedWordIndexString = appState.uiState.selectedWordIndex.toString();
const questionWords = target.getElementsByTagName("span");
for (let i = 0; i < questionWords.length; i++) {
const questionWord = questionWords[i];
if (questionWord.getAttribute("data-index") === selectedWordIndexString) {
appState.uiState.showBuzzMenu(/* clearSelectedWordOnClose */ false);
break;
}
}
event.preventDefault();
event.stopPropagation();
}
exports.selectWordFromKeyboardEvent = selectWordFromKeyboardEvent;
function throwOutTossup(cycle, tossupNumber) {
const appState = AppState_1.AppState.instance;
appState.uiState.dialogState.showOKCancelMessageDialog("Throw out Tossup", "Click OK to throw out the tossup. To undo this, click on the X next to its event in the Event Log.", () => onConfirmThrowOutTossup(cycle, tossupNumber));
}
exports.throwOutTossup = throwOutTossup;
function onConfirmThrowOutTossup(cycle, tossupNumber) {
const appState = AppState_1.AppState.instance;
cycle.addThrownOutTossup(tossupNumber - 1);
appState.uiState.setSelectedWordIndex(-1);
}
//# sourceMappingURL=TossupQuestionController.js.map