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

Convert AppRoutes to TS & Type Lessons' props better #169

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 5 additions & 8 deletions src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ import {
UserSettings,
LookupDictWithNamespacedDictsAndConfig,
MetWords,
ImportedPersonalDictionaries,
CurrentLessonStrokes, ActualTypedText
CurrentLessonStrokes, ActualTypedText, PersonalDictionaryNameAndContents
} from "./types";
import { Location } from "history";
import { CustomLessonMaterialValidationState } from "./pages/lessons/custom/components/CustomLessonIntro";
import { RecentLessonHistoryItem } from "./pages/progress/components/RecentLessons";

const AsyncBreak = Loadable({
loader: () => import("./pages/break/Break"),
Expand Down Expand Up @@ -166,7 +166,7 @@ type AppStateForDescendants = {
customLessonMaterial: string,
customLessonMaterialValidationMessages: string[],
customLessonMaterialValidationState: CustomLessonMaterialValidationState,
customLesson: unknown,
customLesson: Lesson,
actualText: ActualTypedText,
dictionaryIndex: unknown, // TODO: type like [{
// "title": "Dictionary",
Expand Down Expand Up @@ -202,7 +202,7 @@ type AppStateForDescendants = {
// isGlobalLookupDictionaryLoaded: false,
lookupTerm: string,
recommendationHistory: unknown // TODO: type like { currentStep: null },
personalDictionaries: ImportedPersonalDictionaries,
personalDictionaries: PersonalDictionaryNameAndContents[],
previousCompletedPhraseAsTyped: ActualTypedText,
repetitionsRemaining: number,
startTime: Date,
Expand Down Expand Up @@ -236,7 +236,7 @@ type AppStateForDescendants = {
// "subcategory": "",
// "path": process.env.PUBLIC_URL + "/drills/steno/lesson.txt"
// }],
recentLessons: { history: unknown },
recentLessons: { history: RecentLessonHistoryItem[] },
recommendedNextLesson: unknown, // TODO type like {
// studyType: "practice",
// limitNumberOfWords: 50,
Expand Down Expand Up @@ -606,15 +606,13 @@ const AppRoutes: React.FC<Props> = ({ appProps, appState, appMethods }) => {
updatePersonalDictionaries={
appMethods.updatePersonalDictionaries
}
lessonsProgress={appState.lessonsProgress}
lessonNotFound={appState.lessonNotFound}
fullscreen={appState.fullscreen}
changeFullscreen={appMethods.changeFullscreen}
restartLesson={appMethods.restartLesson}
reviseLesson={appMethods.reviseLesson}
lessonSubTitle={appState.lesson.subtitle}
lessonTitle={appState.lesson.title}
path={appState.lesson.path}
handleStopLesson={appMethods.handleStopLesson}
lessonIndex={appState.lessonIndex}
lesson={appState.lesson}
Expand Down Expand Up @@ -680,7 +678,6 @@ const AppRoutes: React.FC<Props> = ({ appProps, appState, appMethods }) => {
sayCurrentPhraseAgain={appMethods.sayCurrentPhraseAgain}
startFromWordOne={appMethods.startFromWordOne}
startTime={appState.startTime}
stenoHintsOnTheFly={appProps.stenohintsonthefly}
stopLesson={appMethods.stopLesson}
startCustomLesson={appMethods.startCustomLesson}
setUpProgressRevisionLesson={
Expand Down
4 changes: 2 additions & 2 deletions src/components/TypedText.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useEffect } from "react";
import { TransitionGroup, CSSTransition } from "react-transition-group";
import GoogleAnalytics from "react-ga4";
import { UserSettings } from "../types";
import { CurrentLessonStrokes, UserSettings } from "../types";

type Props = {
actualText: string;
completedPhrases: any;
currentLessonStrokes: any;
currentLessonStrokes: CurrentLessonStrokes[];
didoesdigital marked this conversation as resolved.
Show resolved Hide resolved
currentPhrase: string;
previousCompletedPhraseAsTyped: string;
sayCurrentPhraseAgain: () => void;
Expand Down
35 changes: 22 additions & 13 deletions src/pages/lessons/Lessons.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Route, Switch } from "react-router-dom";
import React, { ComponentProps } from "react";
import { Route, RouteComponentProps, Switch } from "react-router-dom";
import DocumentTitle from "react-document-title";
import ErrorBoundary from "../../components/ErrorBoundary";
import Lesson from "./Lesson";
Expand All @@ -8,17 +8,14 @@ import CustomLessonSetup from "./custom/CustomLessonSetup";
import Loadable from "react-loadable";
import PageLoading from "../../components/PageLoading";

type LessonsRoutingProps = {
customiseLesson: () => void;
customLesson: any;
generateCustomLesson: any;
handleLesson: any;
lesson: any;
lessonIndex: any;
match: any;
stopLesson: any;
[key: string]: any;
};
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
type LessonsRoutingProps = Optional<
& RouteComponentProps
& ComponentProps<typeof Lesson>
& ComponentProps<typeof CustomLessonSetup>
& ComponentProps<typeof AsyncCustomLessonGenerator>
didoesdigital marked this conversation as resolved.
Show resolved Hide resolved
// TODO: check this. it's not passed from parent
, "lessonLength">
didoesdigital marked this conversation as resolved.
Show resolved Hide resolved

const AsyncCustomLessonGenerator = Loadable({
loader: () => import("./custom/CustomLessonGenerator"),
Expand Down Expand Up @@ -159,6 +156,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down Expand Up @@ -246,6 +244,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down Expand Up @@ -333,6 +332,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down Expand Up @@ -420,6 +420,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down Expand Up @@ -507,6 +508,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down Expand Up @@ -594,6 +596,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down Expand Up @@ -682,6 +685,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down Expand Up @@ -770,6 +774,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down Expand Up @@ -858,6 +863,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down Expand Up @@ -987,6 +993,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down Expand Up @@ -1075,6 +1082,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down Expand Up @@ -1163,6 +1171,7 @@ const Lessons = ({
toggleHideOtherSettings={toggleHideOtherSettings}
lesson={lesson}
lessonIndex={lessonIndex}
// @ts-expect-error
lessonLength={lessonLength}
lessonNotFound={lessonNotFound}
lessonSubTitle={lessonSubTitle}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/lessons/MainLessonView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Props = {
changeVoiceUserSetting: (voiceName: string, voiceURI: string) => void;
chooseStudy: () => void;
completedPhrases: MaterialText[];
currentLessonStrokes: CurrentLessonStrokes;
currentLessonStrokes: CurrentLessonStrokes[];
currentPhrase: MaterialText;
currentPhraseID: number;
currentStroke: Outline;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/lessons/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type LessonProps = {
changeVoiceUserSetting: (voiceName: string, voiceURI: string) => void;
chooseStudy: () => void;
completedPhrases: any;
currentLessonStrokes: CurrentLessonStrokes;
currentLessonStrokes: CurrentLessonStrokes[];
currentPhrase: string;
currentPhraseID: number;
currentStroke: string;
Expand Down