Skip to content

Commit 17ab025

Browse files
committed
common type refactor
1 parent 4f07950 commit 17ab025

File tree

5 files changed

+34
-46
lines changed

5 files changed

+34
-46
lines changed

src/lib/components/nav/WeekDateBtn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { useState } from "react";
22
import DateProvider from "../hoc/DateProvider";
33
import { Button, Popover } from "@mui/material";
44
import { endOfWeek, format, startOfWeek, addDays } from "date-fns";
5-
import { WeekProps } from "../../views/Week";
65
import { LocaleArrow } from "../common/LocaleArrow";
76
import { DateCalendar } from "@mui/x-date-pickers";
87
import useStore from "../../hooks/useStore";
98
import useArrowDisable from "../../hooks/useArrowDisable";
9+
import { WeekProps } from "../../types";
1010

1111
interface WeekDateBtnProps {
1212
selectedDate: Date;

src/lib/types.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import { DragEvent } from "react";
55
import { SelectOption } from "./components/inputs/SelectInput";
66
import { View } from "./components/nav/Navigation";
77
import { Store } from "./store/types";
8-
import { DayProps } from "./views/Day";
98
import { StateItem } from "./views/Editor";
10-
import { MonthProps } from "./views/Month";
11-
import { WeekProps } from "./views/Week";
129
import type { RRule } from "rrule";
1310
import type { JSX } from "react";
1411

@@ -39,6 +36,33 @@ export type DayHours =
3936
| 23
4037
| 24;
4138

39+
export type WeekDays = 0 | 1 | 2 | 3 | 4 | 5 | 6;
40+
41+
interface CommonWeekViewProps {
42+
weekDays: WeekDays[];
43+
weekStartOn: WeekDays;
44+
disableGoToDay?: boolean;
45+
}
46+
47+
interface CommonViewProps {
48+
startHour: DayHours;
49+
endHour: DayHours;
50+
cellRenderer?(props: CellRenderedProps): JSX.Element;
51+
headRenderer?(day: Date): JSX.Element;
52+
navigation?: boolean;
53+
step: number;
54+
}
55+
56+
export interface MonthProps extends CommonWeekViewProps, CommonViewProps {}
57+
58+
export interface WeekProps extends CommonWeekViewProps, CommonViewProps {
59+
hourRenderer?(hour: string): JSX.Element;
60+
}
61+
62+
export interface DayProps extends CommonViewProps {
63+
hourRenderer?(hour: string): JSX.Element;
64+
}
65+
4266
export interface CellRenderedProps {
4367
day: Date;
4468
start: Date;

src/lib/views/Day.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useCallback, Fragment, JSX } from "react";
1+
import { useEffect, useCallback, Fragment } from "react";
22
import { Typography } from "@mui/material";
33
import {
44
format,
@@ -14,7 +14,7 @@ import {
1414
} from "date-fns";
1515
import TodayTypo from "../components/common/TodayTypo";
1616
import EventItem from "../components/events/EventItem";
17-
import { CellRenderedProps, DayHours, DefaultResource, ProcessedEvent } from "../types";
17+
import { DefaultResource, ProcessedEvent } from "../types";
1818
import {
1919
calcCellHeight,
2020
calcMinuteHeight,
@@ -31,16 +31,6 @@ import { MULTI_DAY_EVENT_HEIGHT } from "../helpers/constants";
3131
import useStore from "../hooks/useStore";
3232
import { DayAgenda } from "./DayAgenda";
3333

34-
export interface DayProps {
35-
startHour: DayHours;
36-
endHour: DayHours;
37-
step: number;
38-
cellRenderer?(props: CellRenderedProps): JSX.Element;
39-
headRenderer?(day: Date): JSX.Element;
40-
hourRenderer?(hour: string): JSX.Element;
41-
navigation?: boolean;
42-
}
43-
4434
const Day = () => {
4535
const {
4636
day,

src/lib/views/Month.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
import { useEffect, useCallback, JSX } from "react";
1+
import { useEffect, useCallback } from "react";
22
import { addDays, eachWeekOfInterval, endOfMonth, startOfMonth } from "date-fns";
3-
import { CellRenderedProps, DayHours, DefaultResource } from "../types";
3+
import { DefaultResource } from "../types";
44
import { getResourcedEvents, sortEventsByTheEarliest } from "../helpers/generals";
55
import { WithResources } from "../components/common/WithResources";
66
import useStore from "../hooks/useStore";
77
import { MonthAgenda } from "./MonthAgenda";
88
import MonthTable from "../components/month/MonthTable";
99

10-
export type WeekDays = 0 | 1 | 2 | 3 | 4 | 5 | 6;
11-
export interface MonthProps {
12-
weekDays: WeekDays[];
13-
weekStartOn: WeekDays;
14-
startHour: DayHours;
15-
endHour: DayHours;
16-
cellRenderer?(props: CellRenderedProps): JSX.Element;
17-
headRenderer?(day: Date): JSX.Element;
18-
navigation?: boolean;
19-
disableGoToDay?: boolean;
20-
}
21-
2210
const Month = () => {
2311
const {
2412
month,

src/lib/views/Week.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
import { useEffect, useCallback, JSX } from "react";
1+
import { useEffect, useCallback } from "react";
22
import { startOfWeek, addDays, eachMinuteOfInterval, endOfDay, startOfDay, set } from "date-fns";
3-
import { CellRenderedProps, DayHours, DefaultResource } from "../types";
4-
import { WeekDays } from "./Month";
3+
import { DefaultResource } from "../types";
54
import { calcCellHeight, calcMinuteHeight, getResourcedEvents } from "../helpers/generals";
65
import { WithResources } from "../components/common/WithResources";
76
import useStore from "../hooks/useStore";
87
import { WeekAgenda } from "./WeekAgenda";
98
import WeekTable from "../components/week/WeekTable";
109

11-
export interface WeekProps {
12-
weekDays: WeekDays[];
13-
weekStartOn: WeekDays;
14-
startHour: DayHours;
15-
endHour: DayHours;
16-
step: number;
17-
cellRenderer?(props: CellRenderedProps): JSX.Element;
18-
headRenderer?(day: Date): JSX.Element;
19-
hourRenderer?(hour: string): JSX.Element;
20-
navigation?: boolean;
21-
disableGoToDay?: boolean;
22-
}
23-
2410
const Week = () => {
2511
const {
2612
week,

0 commit comments

Comments
 (0)