Skip to content

Commit

Permalink
chore: specify types for useProgressForDownloads (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefl authored Dec 11, 2024
1 parent 8b4e32a commit c91c5fb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import { useMemo } from "react";

import type { LooseLessonPlan } from "@oakai/aila/src/protocol/schema";
import type {
LessonPlanKeys,
LooseLessonPlan,
} from "@oakai/aila/src/protocol/schema";
import { lessonPlanSectionsSchema } from "@oakai/exports/src/schema/input.schema";
import type { ZodIssue } from "zod";

export type ProgressForDownloads = {
sections: ProgressSection[];
totalSections: number;
totalSectionsComplete: number;
};

export type ProgressSection = {
label: string;
key: LessonPlanKeys;
complete: boolean;
};

export type ProgressSections = ProgressSection[];

/**
* For a given list of Zod issues and lessonPlan fields, checks that none of
* the errors pertain to the fields.
Expand All @@ -16,16 +33,6 @@ function getCompleteness(errors: ZodIssue[], fields: string[]) {

return !hasErrorInSomeField;
}
export type ProgressSections = {
label: string;
key: string;
complete: boolean;
}[];
type ProgressForDownloads = {
sections: ProgressSections;
totalSections: number;
totalSectionsComplete: number;
};

export function useProgressForDownloads({
lessonPlan,
Expand Down Expand Up @@ -60,7 +67,8 @@ export function useProgressForDownloads({
return true;
}
}) ?? [];
const sections = [

const sections: ProgressSection[] = [
{
label: "Lesson details",
key: "title",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { useRef, useState } from "react";

import type { LessonPlanKeys } from "@oakai/aila/src/protocol/schema";

import { useLessonChat } from "@/components/ContextProviders/ChatProvider";

import AiIcon from "../../AiIcon";
Expand Down Expand Up @@ -30,7 +32,9 @@ const ChatRightHandSideLesson = ({
const [showScrollButton, setShowScrollButton] = useState(false);

// This retains this existing bug, but is fixed on subsequent PRs
const sectionRefs = {};
const sectionRefs: Partial<
Record<LessonPlanKeys, React.MutableRefObject<HTMLDivElement | null>>
> = {};

const scrollToBottom = () => {
if (chatEndRef.current) {
Expand All @@ -57,7 +61,7 @@ const ChatRightHandSideLesson = ({

return (
<div
className={`fixed bottom-0 ${showLessonMobile ? "right-0" : "right-[-100%] sm:right-0"} right-0 ${demo.isDemoUser ? "top-8 sm:top-0" : "top-0"} z-30 w-[95%] bg-white shadow-md duration-300 sm:relative sm:z-0 sm:w-[50%] sm:shadow-none lg:w-full`}
className={`fixed bottom-0 ${showLessonMobile ? "right-0" : "right-[-100%] sm:right-0"} right-0 ${demo.isDemoUser ? "top-8 sm:top-0" : "top-0"} z-30 w-[95%] bg-white shadow-md duration-300 sm:relative sm:z-0 sm:w-[50%] sm:shadow-none lg:w-full`}
data-testid="chat-right-hand-side-lesson"
ref={documentContainerRef}
onScroll={handleScroll}
Expand Down Expand Up @@ -92,7 +96,7 @@ const ChatRightHandSideLesson = ({
/>
</div>
<div
className={`${messages.length > 1 && showLessonMobile ? "flex" : "hidden"} fixed bottom-20 left-0 right-0 items-center justify-center duration-150 sm:hidden`}
className={`${messages.length > 1 && showLessonMobile ? "flex" : "hidden"} fixed bottom-20 left-0 right-0 items-center justify-center duration-150 sm:hidden`}
>
<ChatButton
variant="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export const Default: Story = {
learningOutcome: { current: null },
learningCycles: { current: null },
priorKnowledge: { current: null },
"cycle-1": { current: null },
"cycle-2": { current: null },
"cycle-3": { current: null },
cycle1: { current: null },
cycle2: { current: null },
cycle3: { current: null },
},
documentContainerRef: { current: null },
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React, { useState } from "react";

import type { LooseLessonPlan } from "@oakai/aila/src/protocol/schema";
import type {
LessonPlanKeys,
LooseLessonPlan,
} from "@oakai/aila/src/protocol/schema";
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
import { Flex } from "@radix-ui/themes";

Expand All @@ -9,10 +12,12 @@ import { scrollToRef } from "@/utils/scrollToRef";

import { useProgressForDownloads } from "../Chat/hooks/useProgressForDownloads";

type LessonPlanProgressDropdownProps = Readonly<{
export type LessonPlanProgressDropdownProps = Readonly<{
lessonPlan: LooseLessonPlan;
isStreaming: boolean;
sectionRefs: Record<string, React.MutableRefObject<HTMLDivElement | null>>;
sectionRefs: Partial<
Record<LessonPlanKeys, React.MutableRefObject<HTMLDivElement | null>>
>;
documentContainerRef: React.MutableRefObject<HTMLDivElement | null>;
}>;

Expand Down Expand Up @@ -61,10 +66,10 @@ export const LessonPlanProgressDropdown: React.FC<
disabled={!complete}
className="mb-7 flex gap-6"
onClick={() => {
if (key === "cycles" && complete) {
if (sectionRefs["cycle-1"]) {
if (key === "cycle1" && complete) {
if (sectionRefs["cycle1"]) {
scrollToRef({
ref: sectionRefs["cycle-1"],
ref: sectionRefs["cycle1"],
containerRef: documentContainerRef,
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import type { LessonPlanKeys } from "@oakai/aila/src/protocol/schema";
import { OakSmallSecondaryButton } from "@oaknational/oak-components";
import Link from "next/link";

Expand All @@ -11,7 +12,9 @@ import { useDialog } from "../../DialogContext";
import { LessonPlanProgressDropdown } from "./LessonPlanProgressDropdown";

export type ExportButtonsProps = Readonly<{
sectionRefs: Record<string, React.MutableRefObject<HTMLDivElement | null>>;
sectionRefs: Partial<
Record<LessonPlanKeys, React.MutableRefObject<HTMLDivElement | null>>
>;
documentContainerRef: React.MutableRefObject<HTMLDivElement | null>;
}>;

Expand All @@ -26,7 +29,7 @@ const ExportButtons = ({
const demo = useDemoUser();

return (
<div className=" sticky left-0 right-10 top-26 z-10 mt-26 hidden bg-white p-14 px-24 shadow-md sm:block">
<div className="sticky left-0 right-10 top-26 z-10 mt-26 hidden bg-white p-14 px-24 shadow-md sm:block">
<div className="flex flex-col">
<div className="flex items-center space-x-14">
<LessonPlanProgressDropdown
Expand Down

0 comments on commit c91c5fb

Please sign in to comment.