From 0dfd9a6bee99255ace03e4169d355816214967c6 Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Mon, 6 Mar 2023 08:46:02 +0100 Subject: [PATCH] made reminder list to link to calendar --- src/components/Calendar/CalendarTable.jsx | 110 +++++++++++++++++++++- 1 file changed, 107 insertions(+), 3 deletions(-) diff --git a/src/components/Calendar/CalendarTable.jsx b/src/components/Calendar/CalendarTable.jsx index d2c4552..9353df8 100755 --- a/src/components/Calendar/CalendarTable.jsx +++ b/src/components/Calendar/CalendarTable.jsx @@ -1,16 +1,45 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import dataImage1 from "../../assets/images/data-table-user-1.png"; import dataImage2 from "../../assets/images/data-table-user-2.png"; import dataImage3 from "../../assets/images/data-table-user-3.png"; import dataImage4 from "../../assets/images/data-table-user-4.png"; import SelectBox from "../Helpers/SelectBox"; + +import usersService from "../../services/UsersService"; // API SERVICE +import localImgLoad from "../../lib/localImgLoad"; // img loader + + import Calendar from 'react-calendar'; import 'react-calendar/dist/Calendar.css'; export default function CalendarTable({ className }) { + const [isLoading, setIsLoading] = useState(true) // for determining when a page is awating request call + const filterCategories = ["All Categories", "Explore", "Featured"]; const [selectedCategory, setCategory] = useState(filterCategories[0]); - const [value, onChange] = useState(new Date()); + + const [value, onChange] = useState(new Date()); // value of calendar date and onchange handler for calendar + const [remDate, setRemDate] = useState([]) // for holding dates on reminders to display on calendar + + const reminderApi = new usersService(); // instantiating the API SERVICE + + const getUserReminders = async () => { + try { + const res = await reminderApi.getUserReminders(); + if(res.status == 200 && res.data.status > 0){ + setRemDate(res.data.reminders) + setIsLoading(false) + return + } + setIsLoading(false) + }catch(error) { + setIsLoading(false) + } + }; + + useEffect(() => { + getUserReminders(); + }, []); return (
- + + { + isLoading ? +
+ + Loading... +
+ : + { + const reminder = [] + remDate.map((x) => { + // console.log(new Date(date).toDateString() == new Date(x.start_date).toDateString()) + if(date.toDateString() == new Date(x.start_date.split(' ')[0]).toDateString()){ + if(reminder.length < 1) { + reminder.push([x]) + }else{ + for(let i=0; i { + if(rem){ + return + } + }) : ""; + }} + + /> + } +
); +} + +const ReminderThumbnail = ({reminders}) => { + return ( +
+ {reminders.map((reminder, index) => ( +
+
+ data +
+
+

+ {reminder.description?.substring(0, 20)+ ' ...'} +

+ + + Added + {reminder.start_date.split(' ')[0]} + + +
+
+ ))} + +
+ ) } \ No newline at end of file