Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix remaining type inconsistencies #134

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 3 additions & 29 deletions apps/next-app/pages/modules/[questionBank]/docs/[docId].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ import {
useDisclose,
useMediaQuery,
} from "@chair-flight/react/components";
import {
DocContent,
LayoutModule,
LearningObjectiveQuestions,
LearningObjectiveTree,
} from "@chair-flight/react/containers";
import { DocContent, LayoutModule } from "@chair-flight/react/containers";
import { trpc } from "@chair-flight/trpc/client";
import { staticHandler, staticPathsHandler } from "@chair-flight/trpc/server";
import type { QuestionBankName } from "@chair-flight/core/question-bank";
Expand Down Expand Up @@ -103,16 +98,6 @@ export const Page: NextPage<PageProps> = ({ docId, questionBank }) => {
<Typography level="h3" sx={{ m: 1, mt: 1.5 }}>
Learning Objectives
</Typography>
<LearningObjectiveTree
questionBank={questionBank}
learningObjectiveId={doc.learningObjective}
forceMode="mobile"
sx={{
flex: 1,
border: "none",
overflowY: "scroll",
}}
/>
</Drawer>

<Drawer
Expand All @@ -125,16 +110,6 @@ export const Page: NextPage<PageProps> = ({ docId, questionBank }) => {
<Typography level="h3" sx={{ m: 1, mt: 1.5 }}>
Questions
</Typography>
<LearningObjectiveQuestions
questionBank={questionBank}
learningObjectiveId={doc.learningObjective}
forceMode="mobile"
sx={{
flex: 1,
border: "none",
overflowY: "scroll",
}}
/>
</Drawer>
</Stack>
</LayoutModule>
Expand All @@ -144,11 +119,10 @@ export const Page: NextPage<PageProps> = ({ docId, questionBank }) => {
export const getStaticProps = staticHandler<PageProps, PageParams>(
async ({ params: rawParams, helper }) => {
const data = await helper.containers.docs.getDoc.fetch(rawParams);
const learningObjectiveId = data.doc.learningObjective;
const params = { ...rawParams, learningObjectiveId };
const learningObjective = data.doc.learningObjective;
const params = { ...rawParams, learningObjective };
await LayoutModule.getData({ helper, params });
await DocContent.getData({ helper, params });
await LearningObjectiveTree.getData({ helper, params });
return { props: params };
},
fs,
Expand Down
18 changes: 10 additions & 8 deletions apps/next-app/pages/modules/[questionBank]/docs/index.page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as fs from "node:fs/promises";
import { AppHead } from "@chair-flight/react/components";
import { DocSearch, LayoutModule } from "@chair-flight/react/containers";
import { staticHandler } from "@chair-flight/trpc/server";
import { staticHandler, staticPathsHandler } from "@chair-flight/trpc/server";
import type { QuestionBankName } from "@chair-flight/core/question-bank";
import type { Breadcrumbs } from "@chair-flight/react/containers";
import type { GetStaticPaths, NextPage } from "next";
import type { NextPage } from "next";

type PageProps = {
questionBank: QuestionBankName;
Expand Down Expand Up @@ -37,10 +37,12 @@ export const getStaticProps = staticHandler<PageProps, PageParams>(
fs,
);

export const getStaticPaths: GetStaticPaths<PageParams> = async () => {
const banks: QuestionBankName[] = ["atpl"];
const paths = banks.map((questionBank) => ({ params: { questionBank } }));
return { fallback: false, paths };
};

export const getStaticPaths = staticPathsHandler<PageParams>(
async ({ helper }) => {
const getPaths = helper.pageGeneration.modules.getIndexGenerationPaths;
const paths = await getPaths.fetch({ resource: "docs" });
return { fallback: false, paths };
},
fs,
);
export default Page;
11 changes: 11 additions & 0 deletions libs/core/question-bank/src/entities/question-bank.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { z } from "zod";
import type { Annex } from "./question-bank-annex";
import type { Course } from "./question-bank-course";
import type { Doc } from "./question-bank-doc";
Expand All @@ -19,6 +20,16 @@ export type QuestionBankNameToType = {

export type QuestionBankResource = keyof QuestionBankNameToType;

export const questionBankResourceSchema = z.enum([
"questions",
"learningObjectives",
"annexes",
"flashcards",
"courses",
"subjects",
"docs",
]);

export type QuestionBankResourceArrays = {
[K in QuestionBankResource]: QuestionBankNameToType[K][] | undefined;
};
Expand Down
1 change: 1 addition & 0 deletions libs/core/question-bank/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export * from "./entities/test-types";
export * from "./questions/get-new-variant";
export * from "./questions/get-question-preview";
export * from "./tests/create-test";
export * from "./tests/get-number-of-available-questions";
export * from "./tests/create-test-question";
export * from "./tests/process-test";
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { LearningObjectiveId } from "../entities/ids";

export const getNumberOfAvailableQuestions = (
subject: {
learningObjectives: Array<{
id: LearningObjectiveId;
numberOfQuestions: number;
learningObjectives: Array<{
id: LearningObjectiveId;
numberOfQuestions: number;
}>;
}>;
},
selectedLearningObjectives: LearningObjectiveId[],
) => {
return subject.learningObjectives.reduce((sum, lo) => {
if (selectedLearningObjectives.includes(lo.id)) {
return sum + lo.numberOfQuestions;
}
lo.learningObjectives.forEach((lo2) => {
if (!selectedLearningObjectives.includes(lo2.id)) return;
sum += lo2.numberOfQuestions;
});
return sum;
}, 0);
};
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const readAllAnnexesFromFs = async (
const jsonData = JSON.parse(json || "[]") as Annex[];
const annexData = jsonData.map((a) => ({
...a,
href: `/content/${projectName}/media/${a.href}.${a.format}`,
href: `/content/${projectName}/media/${a.id}.${a.format}`,
doc: "",
questions: [],
subjects: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const Playground: Story = {
args: {
correct: false,
questionTemplateId: "123124",
questionVariantId: "abcbacabc",
title: "Question 5",
question: "what is the capital of France?",
correctOption: "Paris",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type TestQuestionResultProps = {
correct?: boolean;
question?: string;
questionTemplateId?: string;
questionVariantId?: string;
correctOption?: string;
selectedOption?: string;
learningObjectives?: string[];
Expand All @@ -28,7 +27,6 @@ export const TestQuestionResult = forwardRef<
correctOption,
selectedOption,
questionTemplateId,
questionVariantId,
learningObjectives,
...props
},
Expand All @@ -48,7 +46,7 @@ export const TestQuestionResult = forwardRef<
}}
>
<Typography level="body-sm" fontWeight={900}>
{`${questionTemplateId} (${questionVariantId})`}
{questionTemplateId}
</Typography>
<Box sx={{ fontSize: "sm" }}>
<MarkdownClient>{question ?? ""}</MarkdownClient>
Expand Down
Loading
Loading