Skip to content

Commit 77b9e68

Browse files
committed
feat: use EventState at Calendar
1 parent 4f59b43 commit 77b9e68

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

โ€Žsrc/components/common/Calendar.tsxโ€Ž

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ import FullCalendar from '@fullcalendar/react';
22
import dayGridPlugin from '@fullcalendar/daygrid';
33
import interactionPlugin from '@fullcalendar/interaction';
44
import { useRef, useState, useEffect } from 'react';
5-
6-
const events = [
7-
{ title: 'Meeting', start: new Date() },
8-
{ title: 'Meeting2', start: '2024-05-08', end: '2024-05-12', backgroundColor: 'red', borderColor: 'red' },
9-
{ title: 'Meeting3', start: '2024-05-08', end: '2024-05-10', backgroundColor: 'green', borderColor: 'green' },
10-
{ title: 'Meeting4', start: '2024-05-08', end: '2024-05-11' },
11-
];
5+
import { useEventState } from '@/stores/myEventsStore';
126

137
const Calendar: React.FC = () => {
148
const [calendarHeight, setCalendarHeight] = useState<string | number>('auto');
@@ -43,6 +37,7 @@ const Calendar: React.FC = () => {
4337
return () => window.removeEventListener('resize', updateSize);
4438
}, []);
4539

40+
const events = useEventState();
4641
return (
4742
<div>
4843
<FullCalendar
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { create } from 'zustand';
2+
import { Events } from '../utils/index.ts';
3+
4+
const initialEventsState: Events[] = [
5+
{ title: 'Meeting', start: new Date(), end: new Date() },
6+
{ title: 'Meeting2', start: '2024-05-08', end: '2024-05-12', backgroundColor: 'red', borderColor: 'red' },
7+
{ title: 'Meeting3', start: '2024-05-08', end: '2024-05-10', backgroundColor: 'green', borderColor: 'green' },
8+
{ title: 'Meeting4', start: '2024-05-08', end: '2024-05-11' },
9+
];
10+
11+
interface EventsState {
12+
events: Events[];
13+
addEvents: (event: Events) => void;
14+
initEvents: () => void;
15+
}
16+
17+
export const useEventState = create<EventsState>()((set) => ({
18+
events: [...initialEventsState],
19+
20+
addEvents: (newEvent: Events) => set((state) => ({ events: [...state.events, newEvent] })),
21+
initEvents: () => set(() => ({ events: [] })),
22+
}));

โ€Žsrc/utils/index.tsโ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface Events {
2+
id?: string;
3+
title: string;
4+
start: Date | string;
5+
end: Date | string;
6+
backgroundColor?: string;
7+
borderColor?: string;
8+
textColor?: string;
9+
}

0 commit comments

Comments
ย (0)