Skip to content

Commit

Permalink
Merge pull request #12 from jlsuh/develop
Browse files Browse the repository at this point in the history
Stuff
  • Loading branch information
jlsuh authored Feb 3, 2024
2 parents f6ca679 + c0b91b4 commit 8004ebf
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 238 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@
"dependencies": {
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.15.6",
"@mui/material": "^5.15.6",
"@mui/icons-material": "^5.15.7",
"@mui/material": "^5.15.7",
"@viz-js/viz": "^3.2.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.21.3"
"react-router-dom": "^6.22.0"
},
"devDependencies": {
"@testing-library/dom": "^9.3.4",
"@testing-library/react": "^14.1.2",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@types/react": "^18.2.48",
"@types/react": "^18.2.52",
"@types/react-dom": "^18.2.18",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@vitejs/plugin-react-swc": "^3.5.0",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"@vitejs/plugin-react-swc": "^3.6.0",
"eslint": "^8.56.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/__tests__/fixture.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DEFAULT_STATUS, modes } from "../../data";
import { DataPlan, Plan, PlanContextProps } from "../../types/types";
import { ContextPlan, DataPlan, PlanContextProps } from "../../types/types";

const id1 = "subject-1";
const id2 = "subject-2";
Expand All @@ -10,7 +10,7 @@ const planId2 = "plan-2";
const subjectName1 = "Subject 1";
const subjectName2 = "Subject 2";

const contextPlan: Plan = {
const contextPlan: ContextPlan = {
id: planId1,
branch: "planBranch-1",
subjects: {
Expand Down
6 changes: 3 additions & 3 deletions src/context/PlanProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode, useReducer } from "react";
import { useLocation } from "react-router-dom";
import { PlanContext } from ".";
import { plans } from "../data";
import { DataPlan, Plan, Status, Subject } from "../types/types";
import { ContextPlan, DataPlan, Status, Subject } from "../types/types";
import { planReducer } from "./planReducer";
import { planTypes } from "./planTypes";

Expand All @@ -29,7 +29,7 @@ const getFlattenedPlan = ({ id, branch, subjects }: DataPlan) => {
};
};

const initializer = (initialArg: Plan) => {
const initializer = (initialArg: ContextPlan) => {
const subjectsJSON = localStorage.getItem(SUBJECTS_KEY);
if (subjectsJSON === null) {
localStorage.setItem(SUBJECTS_KEY, JSON.stringify(initialArg));
Expand All @@ -49,7 +49,7 @@ export const PlanProvider = ({ children }: { children: ReactNode }) => {
(plan) => plan.id === location.pathname.slice(1),
);

const updatePlan = (newPlan: Plan) => {
const updatePlan = (newPlan: ContextPlan) => {
localStorage.setItem(SUBJECTS_KEY, JSON.stringify(newPlan));
const action = {
type: planTypes.updatePlan,
Expand Down
6 changes: 3 additions & 3 deletions src/context/planReducer.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Plan } from "../types/types";
import { ContextPlan } from "../types/types";
import { planTypes } from "./planTypes";

interface PlanAction {
readonly type: string;
readonly payload: {
readonly newPlan: Plan;
readonly newPlan: ContextPlan;
};
}

export const planReducer = (state: Plan, action: PlanAction) => {
export const planReducer = (state: ContextPlan, action: PlanAction) => {
switch (action.type) {
case planTypes.updatePlan:
return action.payload.newPlan;
Expand Down
34 changes: 17 additions & 17 deletions src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
export interface Plan<T> {
readonly id: string;
readonly branch: string;
readonly subjects: T;
}

export interface PlanContextProps {
readonly contextPlan: ContextPlan;
readonly updateMode: (subjectId: string, newMode: string) => void;
readonly updateStatuses: (
subjects: ReadonlyArray<Subject>,
newStatus: Status,
) => void;
}

export interface Status {
readonly color: string;
readonly name: string;
Expand All @@ -12,21 +27,6 @@ export interface Subject {
readonly taken: ReadonlyArray<string>;
}

export interface Plan {
readonly id: string;
readonly branch: string;
readonly subjects: Record<string, Subject>;
}
export type ContextPlan = Plan<Record<string, Subject>>;

export interface DataPlan extends Omit<Plan, "subjects"> {
readonly subjects: ReadonlyArray<ReadonlyArray<Subject>>;
}

export interface PlanContextProps {
readonly contextPlan: Plan;
readonly updateMode: (subjectId: string, newMode: string) => void;
readonly updateStatuses: (
subjects: ReadonlyArray<Subject>,
newStatus: Status,
) => void;
}
export type DataPlan = Plan<ReadonlyArray<ReadonlyArray<Subject>>>;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
"useDefineForClassFields": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
"references": [{ "path": "./tsconfig.vite.json" }]
}
File renamed without changes.
6 changes: 0 additions & 6 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/// <reference types="vitest" />
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: "jsdom",
include: ["src/**/*.{test,spec}.{js,ts,tsx}"],
},
});
9 changes: 9 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: true,
environment: "jsdom",
include: ["src/**/*.{test,spec}.{js,ts,tsx}"],
},
});
Loading

0 comments on commit 8004ebf

Please sign in to comment.