Skip to content

Commit

Permalink
calendar view done
Browse files Browse the repository at this point in the history
  • Loading branch information
logolica99 committed Oct 27, 2022
1 parent bc2c60d commit 6c6adbb
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 2 deletions.
42 changes: 42 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"@emotion/styled": "^11.10.4",
"@fullcalendar/core": "^5.11.3",
"@fullcalendar/daygrid": "^5.11.3",
"@fullcalendar/interaction": "^5.11.3",
"@fullcalendar/list": "^5.11.3",
"@fullcalendar/react": "^5.11.2",
"@fullcalendar/timegrid": "^5.11.3",
"@mui/icons-material": "^5.10.9",
"@mui/material": "^5.10.10",
Expand Down
4 changes: 2 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Form from "./scenes/form";
// import Pie from "./scenes/pie";
// import FAQ from "./scenes/faq";
// import Geography from "./scenes/geography";
// import Calendar from "./scenes/calendar";
import Calendar from "./scenes/calendar";

function App() {
const [theme, colorMode] = useMode();
Expand All @@ -37,7 +37,7 @@ function App() {
{/* <Route path="/line" element={<Line />} /> */}
{/* <Route path="/faq" element={<FAQ />} /> */}
{/* <Route path="/geography" element={<Geography />} /> */}
{/* <Route path="/calendar" element={<Calendar />} /> */}
<Route path="/calendar" element={<Calendar />} />
</Routes>
</main>
</div>
Expand Down
130 changes: 130 additions & 0 deletions src/scenes/calendar/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { useState } from "react";
import FullCalendar, { formatDate } from "@fullcalendar/react";
import dayGridPlugin from "@fullcalendar/daygrid";
import timeGridPlugin from "@fullcalendar/timegrid";
import interactionPlugin from "@fullcalendar/interaction";
import listPlugin from "@fullcalendar/list";
import {
Box,
List,
ListItem,
ListItemText,
Typography,
useTheme,
} from "@mui/material";
import Header from "../../components/Header";
import { tokens } from "../../theme";

export default function Calendar() {
const theme = useTheme();
const colors = tokens(theme.palette.mode);
const [currentEvents, setCurrentEvents] = useState([]);

const handleDateClick = (selected) => {
console.log(selected);
const title = prompt("Please enter a new title for your event");
const calendarApi = selected.view.calendar;
calendarApi.unselect();

if (title) {
calendarApi.addEvent({
id: `${selected.startStr}-${title}`,
title,
start: selected.startStr,
end: selected.endStr,
allDay: selected.allDay,
});
}
};

const handleEventClick = (selected) => {
if (
window.confirm(
`Are you sure you want to delete the event '${selected.event.title}'`
)
) {
selected.event.remove();
}
};

return (
<Box m="20px">
<Header title="Calendar" subtitle="Full Calendar Interactive Page" />

<Box display="flex" justifyContent="space-between">
{/* CALENDAR SIDEBAR */}
<Box
flex="1 1 20%"
backgroundColor={colors.primary[400]}
p="15px"
borderRadius="4px"
>
<Typography variant="h5">Events</Typography>
<List>
{currentEvents.map((event) => (
<ListItem
key={event.id}
sx={{
backgroundColor: colors.greenAccent[500],
margin: "10px 0",
borderRadius: "2px",
}}
>
<ListItemText
primary={event.title}
secondary={
<Typography>
{formatDate(event.start, {
year: "numeric",
month: "short",
day: "numeric",
})}
</Typography>
}
/>
</ListItem>
))}
</List>
</Box>

{/* CALENDAR */}
<Box flex="1 1 100%" ml="15px">
<FullCalendar
height="75vh"
plugins={[
dayGridPlugin,
timeGridPlugin,
interactionPlugin,
listPlugin,
]}
headerToolbar={{
left: "prev,next today",
center: "title",
right: "dayGridMonth,timeGridWeek,timeGridDay,listMonth",
}}
initialView="dayGridMonth"
editable={true}
selectable={true}
selectMirror={true}
dayMaxEvents={true}
select={handleDateClick}
eventClick={handleEventClick}
eventsSet={(events) => setCurrentEvents(events)}
initialEvents={[
{
id: "12315",
title: "All-day event",
date: "2022-09-14",
},
{
id: "5123",
title: "Timed event",
date: "2022-09-28",
},
]}
/>
</Box>
</Box>
</Box>
);
}

0 comments on commit 6c6adbb

Please sign in to comment.