Skip to content

Commit

Permalink
refactor: context as a provider
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsuh committed Dec 7, 2024
1 parent 12143e9 commit e0d9597
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { PlanContext } from '@/context';
import { plans } from '@/data';
import { PlanPage } from '@/pages';
import type { PlanContextProps } from '@/types';
import { useContext } from 'react';
import { use } from 'react';
import { Navigate, Route, Routes } from 'react-router-dom';

function AppRouter() {
const { contextPlan } = useContext<PlanContextProps>(PlanContext);
const { contextPlan } = use<PlanContextProps>(PlanContext);
const { id } = contextPlan;

return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/ModeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { PlanContext } from '@/context';
import type { PlanContextProps, SubjectProps } from '@/types';
import { replaceWhiteSpace } from '@/utils';
import { FormControl, InputLabel, NativeSelect } from '@mui/material';
import { type ChangeEvent, useContext } from 'react';
import { type ChangeEvent, use } from 'react';

function ModeSelect({ subject }: { subject: SubjectProps }) {
const { contextPlan, updateMode } = useContext<PlanContextProps>(PlanContext);
const { contextPlan, updateMode } = use<PlanContextProps>(PlanContext);
const targetSubject = contextPlan.subjects[subject.id];
const contextMode = targetSubject.modes[0];

Expand Down
4 changes: 2 additions & 2 deletions src/components/PlanSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Select,
type SelectChangeEvent,
} from '@mui/material';
import { useContext } from 'react';
import { use } from 'react';
import { useNavigate } from 'react-router-dom';

const selectStyles = {
Expand All @@ -30,7 +30,7 @@ const selectStyles = {
};

function PlanSelect({ availablePlans = plans }) {
const { contextPlan } = useContext<PlanContextProps>(PlanContext);
const { contextPlan } = use<PlanContextProps>(PlanContext);
const navigate = useNavigate();

const handleChangeMenuItem = (event: SelectChangeEvent<string>) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/StatusMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PlanContext } from '@/context';
import type { PlanContextProps, Status, SubjectProps } from '@/types';
import { Box, Divider, Link } from '@mui/material';
import { dividerClasses } from '@mui/material/Divider';
import { useContext } from 'react';
import { use } from 'react';

function StatusMarker({
levelSubjects,
Expand All @@ -13,7 +13,7 @@ function StatusMarker({
renderDivider: boolean;
status: Status;
}) {
const { updateStatuses } = useContext<PlanContextProps>(PlanContext);
const { updateStatuses } = use<PlanContextProps>(PlanContext);

const handleClickStatusMarker = () => {
const newStatus = status;
Expand Down
5 changes: 2 additions & 3 deletions src/components/StatusRadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import {
Radio,
RadioGroup,
} from '@mui/material';
import { type ChangeEvent, useContext } from 'react';
import { type ChangeEvent, use } from 'react';

function StatusRadioGroup({ subject }: { subject: SubjectProps }) {
const { contextPlan, updateStatuses } =
useContext<PlanContextProps>(PlanContext);
const { contextPlan, updateStatuses } = use<PlanContextProps>(PlanContext);
const contextSubject = contextPlan.subjects[subject.id];
const contextStatus = contextSubject.status;

Expand Down
4 changes: 2 additions & 2 deletions src/components/Subject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import type { PlanContextProps, SubjectProps } from '@/types';
import CircleIcon from '@mui/icons-material/Circle';
import { Card, CardActions, CardContent, Typography } from '@mui/material';
import Grid from '@mui/material/Grid2';
import { useContext } from 'react';
import { use } from 'react';

function Subject({ subject }: { subject: SubjectProps }) {
const { contextPlan } = useContext<PlanContextProps>(PlanContext);
const { contextPlan } = use<PlanContextProps>(PlanContext);
const { subjects } = contextPlan;
const contextSubject = subjects[subject.id];
const color = contextSubject.status.color;
Expand Down
4 changes: 2 additions & 2 deletions src/components/SubjectStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { PlanContextProps } from '@/types';
import { findPlanById, replaceWhiteSpace } from '@/utils';
import { Box, Stack, Typography } from '@mui/material';
import Grid from '@mui/material/Grid2';
import { useContext } from 'react';
import { use } from 'react';

function SubjectStack() {
const { contextPlan } = useContext<PlanContextProps>(PlanContext);
const { contextPlan } = use<PlanContextProps>(PlanContext);
const plan = findPlanById(contextPlan.id);
const subjectsByLevel = plan.subjects;
const statusesMaxIndex = Object.values(statuses).length - 1;
Expand Down
4 changes: 2 additions & 2 deletions src/context/PlanProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ function PlanProvider({ children }: { children: ReactNode }) {
}

return (
<PlanContext.Provider
<PlanContext
value={{
contextPlan,
updateMode,
updateStatuses,
}}
>
{children}
</PlanContext.Provider>
</PlanContext>
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useDigraph.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PlanContext } from '@/context';
import type { PlanContextProps } from '@/types';
import { Digraph, findPlanById } from '@/utils';
import { useContext } from 'react';
import { use } from 'react';

function useDigraph() {
const { contextPlan } = useContext<PlanContextProps>(PlanContext);
const { contextPlan } = use<PlanContextProps>(PlanContext);
const plan = findPlanById(contextPlan.id);

function composeDigraph() {
Expand Down

0 comments on commit e0d9597

Please sign in to comment.