aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2024-07-11 02:24:08 +0100
committerGravatar Joe Banks <[email protected]>2024-07-11 02:24:08 +0100
commit572454f01749b4e8b43bfd9c1fcc47210d86fa0f (patch)
tree502cf17a916ea00bc2c54af2e0103c13df938408
parentAdd new vote component and voting redux store (diff)
Handle voting component callbacks
-rw-r--r--src/api/question.ts1
-rw-r--r--src/components/InputTypes/index.tsx5
-rw-r--r--src/components/Question.tsx18
3 files changed, 21 insertions, 3 deletions
diff --git a/src/api/question.ts b/src/api/question.ts
index 56706e2..0fcea03 100644
--- a/src/api/question.ts
+++ b/src/api/question.ts
@@ -8,6 +8,7 @@ export enum QuestionType {
Range = "range",
Section = "section",
TimeZone = "timezone",
+ Vote = "vote"
}
export interface Question {
diff --git a/src/components/InputTypes/index.tsx b/src/components/InputTypes/index.tsx
index ee92ef1..1880bcd 100644
--- a/src/components/InputTypes/index.tsx
+++ b/src/components/InputTypes/index.tsx
@@ -11,6 +11,7 @@ import {QuestionType} from "../../api/question";
import RenderedQuestion from "../Question";
import Code from "./Code";
import TimeZone from "./TimeZone";
+import Vote from "./Vote";
export default function create_input(
{props: renderedQuestionProps, realState}: RenderedQuestion,
@@ -67,6 +68,10 @@ export default function create_input(
result = <TimeZone question={renderedQuestionProps.selfRef} valid={valid} onBlurHandler={onBlurHandler}/>;
break;
+ case QuestionType.Vote:
+ result = <Vote question={renderedQuestionProps.selfRef} handler={handler} questionId={question.id} valid={valid} options={options}/>;
+ break;
+
default:
result = <TextArea handler={handler} valid={valid} onBlurHandler={onBlurHandler} focus_ref={focus_ref}/>;
}
diff --git a/src/components/Question.tsx b/src/components/Question.tsx
index fb5c419..66784d0 100644
--- a/src/components/Question.tsx
+++ b/src/components/Question.tsx
@@ -13,12 +13,13 @@ const skip_normal_state: Array<QuestionType> = [
QuestionType.Select,
QuestionType.TimeZone,
QuestionType.Section,
- QuestionType.Range
+ QuestionType.Range,
+ QuestionType.Vote
];
export interface QuestionState {
// Common keys
- value: string | null | Map<string, boolean>
+ value: string | null | Map<string, boolean> | Record<string, number | null>
// Validation
valid: boolean
@@ -56,6 +57,8 @@ class RenderedQuestion extends React.Component<QuestionProp> {
this.handler = this.text_area_handler.bind(this);
} else if (props.question.type === QuestionType.Code) {
this.handler = this.code_field_handler.bind(this);
+ } else if (props.question.type === QuestionType.Vote) {
+ this.handler = this.vote_handler.bind(this);
} else {
this.handler = this.normal_handler.bind(this);
}
@@ -74,7 +77,7 @@ class RenderedQuestion extends React.Component<QuestionProp> {
}
// This is here to allow dynamic selection between the general handler, textarea, and code field handlers.
- handler(_: ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | string): void {} // eslint-disable-line
+ handler(_: ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | string | Record<string, number | null>): void {} // eslint-disable-line
blurHandler(): void {
if (this.props.question.required) {
@@ -150,6 +153,14 @@ class RenderedQuestion extends React.Component<QuestionProp> {
}
}
+ vote_handler(event: Record<string, number | null>) {
+ this.setState({
+ value: event,
+ valid: true,
+ error: ""
+ });
+ }
+
text_area_handler(event: ChangeEvent<HTMLTextAreaElement>): void {
// We will validate again when focusing out.
this.setState({
@@ -194,6 +205,7 @@ class RenderedQuestion extends React.Component<QuestionProp> {
case QuestionType.Select:
case QuestionType.Range:
case QuestionType.TimeZone:
+ case QuestionType.Vote:
case QuestionType.Radio:
if (!this.realState.value) {
valid = false;