From 10f35aae7b9e8e62becdcdb6be019bdfe88c03d2 Mon Sep 17 00:00:00 2001 From: SohamRatnaparkhi Date: Sun, 1 Oct 2023 22:45:01 +0530 Subject: [PATCH] feat: map user meetings Signed-off-by: SohamRatnaparkhi --- .../schedule-meets/components/Calendar.jsx | 75 +++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/frontend/app/schedule-meets/components/Calendar.jsx b/frontend/app/schedule-meets/components/Calendar.jsx index 86a11c65..53c9c727 100644 --- a/frontend/app/schedule-meets/components/Calendar.jsx +++ b/frontend/app/schedule-meets/components/Calendar.jsx @@ -5,7 +5,6 @@ import dayjs from "dayjs"; import NextIcon from "@/app/svg-icons/NextIcon"; import PrevIcon from "@/app/svg-icons/PrevIcon"; import { months, generateDate } from "@/app/utils/calendar"; -import { getMeeting } from "@/app/hooks/MeetApiCalls"; import axios from "axios"; @@ -19,21 +18,65 @@ const Calendar = () => { const [today, setToday] = useState(currentDate); const [selectDate, setSelectDate] = useState(currentDate); const user = useAppStore(state => state.user) + const [meetingsData, setMeetingsData] = useState([]) + const [userMeets, setUserMeets] = useState([]) + const [userPerMonthMeets, setUserPerMonthMeets] = useState([]) + const [showDayMeets, setShowDayMeets] = useState([false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]) useEffect(() => { const getMeets = async () => { - console.log(user.ethAddress) + // console.log(user.ethAddress) const { data } = await axios.patch('/api/meetings', { "address": user.ethAddress }) console.log(data); + setUserMeets(data.data) + const dates = [] + for (let i = 0; i < 12; i++) { + dates.push([]) + } + const meetsMetaData = {} + // console.log(userMeets) + // const meetShow = [] + const processUserMeets = () => { + data.data.forEach((meet) => { + const strDate = meet.meetConfig.date; + const date = new Date(strDate); + if (!date || date === undefined || date === null) { + return; + } + const month = date.getMonth(); + const day = date.getDate(); + const hash = day + "," + month; + if (!meetsMetaData[hash]) { + meetsMetaData[hash] = []; + } + meetsMetaData[hash].push(meet); + dates[month].push(day); + }); + } + processUserMeets(); + setUserPerMonthMeets(dates) + setMeetingsData(meetsMetaData) + // console.log(meetsMetaData) + // setShowDayMeets(meetShow) } - getMeets(); + // console.log(meetingsData) }, []) + const getMeetByDate = (date) => { + console.log(date) + const strDate = new Date(date); + console.log(strDate.toDateString()) + const meet = meetingsData[strDate]; + if (!meet) { + return null; + } + return meet.title; + } return (
@@ -47,7 +90,7 @@ const Calendar = () => { className="relative" onClick={() => { setToday(today.month(today.month() - 1)); - // console.log(`Month: ${today.month()}`); + console.log(`Month: ${today.month()}`); }} > @@ -56,7 +99,7 @@ const Calendar = () => { className="relative" onClick={() => { setToday(today.month(today.month() + 1)); - // console.log(`Year: ${today.year()}`); + console.log(`Year: ${today.year()}`); }} > @@ -101,6 +144,24 @@ const Calendar = () => { " border-[#5D8BF4C7] flex flex-row justify-end items-start p-2 " )} > +
+ {userPerMonthMeets[date.month()]?.includes(date.date()) && ( +
{meetingsData[date.date() + "," + date.month()]?.length} meets
+ )} +
+ { + showDayMeets[index] && ( +
+ { + meetingsData[date.date() + "," + date.month()]?.map((meet, index) => { + return ( +
{meet.title}
+ ) + }) + } +
+ ) + }

{ )} onClick={() => { setSelectDate(date); + var shows = showDayMeets; + var curr = shows[index]; + shows[index] = !curr; + setShowDayMeets(shows) }} > {date.date()}