Skip to content

Commit b8c5d9c

Browse files
committed
Restore print
1 parent f53cffb commit b8c5d9c

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

src/components/Print.stories.tsx

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { ExerciseData, ExerciseQueryData, ExerciseQuestionData, StepBase } from '../../src/types';
2+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
3+
// @ts-ignore
4+
import data from '../../exercises.json';
5+
import styled from 'styled-components';
6+
import { Exercise } from './Exercise';
7+
8+
const ExerciseWrapper = styled.div`
9+
break-inside: avoid;
10+
11+
.step-card-body {
12+
padding: 24px 48px !important;
13+
}
14+
15+
.step-card-footer {
16+
display: none;
17+
}
18+
19+
.exercise-id {
20+
height: auto;
21+
}
22+
23+
.exercise-step {
24+
min-height: auto;
25+
}
26+
27+
.question-feedback {
28+
box-shadow: none !important;
29+
}
30+
31+
.openstax-answer {
32+
break-inside: avoid;
33+
34+
.answer-letter-wrapper::after {
35+
content: '' !important;
36+
}
37+
}
38+
`;
39+
40+
const exercises = (data as ExerciseQueryData).exercises as ExerciseData[];
41+
42+
const firstQuestionNumByExercise = exercises.reduce((acc, ex) => ({
43+
...acc,
44+
[ex.uuid]: acc.questionCounter + 1,
45+
questionCounter: acc.questionCounter + ex.questions.length
46+
}), {questionCounter: 0});
47+
48+
// placeholder until exercise data contains correct answer IDs
49+
const formatAnswerData = (questions: ExerciseQuestionData[]) => questions.map((q) => (
50+
{id: q.id, correct_answer_id: (q.answers.find((a) => a.correctness === '1.0')?.id || '')}));
51+
52+
const questionStateFields = {
53+
available_points: '1.0',
54+
is_completed: true,
55+
answer_id: '1',
56+
free_response: '',
57+
feedback_html: '',
58+
correct_answer_feedback_html: '',
59+
attempts_remaining: 0,
60+
attempt_number: 1,
61+
incorrectAnswerId: 0
62+
}
63+
64+
export const Default = () => (
65+
<>
66+
{data.title && <h2>Exercises for {data.title}</h2>}
67+
{exercises.map(((exercise) => {
68+
69+
const step: StepBase = {
70+
id: 1,
71+
uid: exercise.uid,
72+
available_points: '1.0',
73+
};
74+
75+
const questionStates = formatAnswerData(exercise.questions).reduce((acc, answer) => {
76+
const {id, correct_answer_id} = answer;
77+
return {...acc, [id]: {...questionStateFields, correct_answer_id}};
78+
}, {});
79+
80+
return (
81+
<ExerciseWrapper key={exercise.uid}>
82+
<Exercise
83+
key={exercise.uid}
84+
canAnswer={true}
85+
needsSaved={true}
86+
hasMultipleAttempts={false}
87+
onAnswerChange={() => undefined}
88+
onAnswerSave={() => undefined}
89+
onNextStep={() => undefined}
90+
apiIsPending={false}
91+
canUpdateCurrentStep={false}
92+
exercise={exercise}
93+
step={step}
94+
questionNumber={firstQuestionNumByExercise[exercise.uuid]}
95+
numberOfQuestions={exercises.length}
96+
questionStates={questionStates}
97+
show_all_feedback={true} />
98+
</ExerciseWrapper>
99+
)
100+
}))}
101+
</>);

0 commit comments

Comments
 (0)