From a74f3a12061cd593a99e19775605998b3977d69c Mon Sep 17 00:00:00 2001 From: anshuk Date: Tue, 9 Apr 2024 12:51:06 +0530 Subject: [PATCH] - Fixed bug with recurring task. - Editing the task will now only set done status for the current recurrence id. - Add task component's input is now cleared with the task editor box opens - Fixed #159 - Problem arose because of the type of any event created in other clients was not being recognised. - Version bump to 0.5.1 --- CHANGELOG | 7 ++ COMMITMESSAGE.md | 9 ++- package.json | 2 +- .../common/AddTask/AddTaskFunctional.tsx | 3 +- .../CalendarViewWithStateManagement.tsx | 2 + .../TaskEditorWithStateManagement.tsx | 74 ++++++++++++++----- src/config/constants.js | 2 +- src/helpers/api/cal/caldav.js | 10 ++- src/helpers/frontend/calendar.js | 5 +- src/helpers/frontend/events.js | 1 + src/pages/api/v2/calendars/events/fetch.ts | 8 +- 11 files changed, 90 insertions(+), 33 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bb2a346..023eb89 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,10 @@ +v0.5.1 +- Fixed bug with recurring task. + - Editing the task will now only set done status for the current recurrence id. +- Add task component's input is now cleared with the task editor box opens +- Fixed #159 + - Problem arose because of the type of any event created in other clients was not being recognised. + v0.5.0 - Version Bump to 0.5.0 - Added Jotai for state management diff --git a/COMMITMESSAGE.md b/COMMITMESSAGE.md index 39ed112..0d57ddf 100644 --- a/COMMITMESSAGE.md +++ b/COMMITMESSAGE.md @@ -1,3 +1,6 @@ -- Added move to calendar option to Task Editor. -- Before setting a default calendar in Event and Taskeditors, added a check to make sure it is a valid id. -- UI Improvement to Home Page \ No newline at end of file +- Fixed bug with recurring task. + - Editing the task will now only set done status for the current recurrence id. +- Add task component's input is now cleared with the task editor box opens +- Fixed #159 + - Problem arose because of the type of any event created in other clients was not being recognised. +- Version bump to 0.5.1 diff --git a/package.json b/package.json index 66e71c3..9afa367 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "manage-my-damn-life-nextjs", - "version": "0.5.0", + "version": "0.5.1", "private": true, "scripts": { "dev": "next dev", diff --git a/src/components/common/AddTask/AddTaskFunctional.tsx b/src/components/common/AddTask/AddTaskFunctional.tsx index 58a9b6f..bacbe63 100644 --- a/src/components/common/AddTask/AddTaskFunctional.tsx +++ b/src/components/common/AddTask/AddTaskFunctional.tsx @@ -87,11 +87,12 @@ export function AddTaskFunctional(props) { const openTaskEditor = () =>{ let dataToPush = {...data} - + if(calDavObject && calDavObject.calendars_id){ dataToPush.calendar_id= calDavObject.calendars_id } setTaskInputAtom(dataToPush) + setNewTaskSummary("") showTaskEditor(true) diff --git a/src/components/fullcalendar/CalendarViewWithStateManagement.tsx b/src/components/fullcalendar/CalendarViewWithStateManagement.tsx index 80840a1..77644cd 100644 --- a/src/components/fullcalendar/CalendarViewWithStateManagement.tsx +++ b/src/components/fullcalendar/CalendarViewWithStateManagement.tsx @@ -174,8 +174,10 @@ export const CalendarViewWithStateManagement = ({ calendarAR }: { calendarAR: nu if (event.deleted == "1" || event.deleted == "TRUE") { continue } + // console.log(event.type, event.calendar_events_id) if (event.type != "VTODO" && event.type != "VTIMEZONE") { const data = getParsedEvent(allEvents[i].events[j].data) + // console.log("Parsed Event", data.summary, event.calendar_id, data) if (varNotEmpty(data) == false) { continue } diff --git a/src/components/tasks/TaskEditorSupport/TaskEditorWithStateManagement.tsx b/src/components/tasks/TaskEditorSupport/TaskEditorWithStateManagement.tsx index 2906ff0..5fd271e 100644 --- a/src/components/tasks/TaskEditorSupport/TaskEditorWithStateManagement.tsx +++ b/src/components/tasks/TaskEditorSupport/TaskEditorWithStateManagement.tsx @@ -33,6 +33,7 @@ import { Datepicker } from "@/components/common/Datepicker/Datepicker" import { CalendarPicker } from "@/components/common/Calendarpicker" import { PRIMARY_COLOUR } from "@/config/style" import { moveEventModalInput, showMoveEventModal } from "stateStore/MoveEventStore" +import next from "next/types" const i18next = getI18nObject() export const TaskEditorWithStateManagement = ({ input, onChange, showDeleteDailog, onServerResponse, closeEditor }: { input: TaskEditorInputType, onChange: Function, showDeleteDailog: Function, onServerResponse: Function, closeEditor: Function }) => { @@ -75,6 +76,7 @@ export const TaskEditorWithStateManagement = ({ input, onChange, showDeleteDailo const [category, setCategory] = useState([]) const [calendarDDLDisabled, setCalendarDDLDisabled] = useState(false) const [showMoveEventOption, setShowMoveEventOption]= useState(false) + const [recurrenceObj, setRecurrenceObj] = useState({}) const changeDoneStatus = (isDone: boolean) => { if (isDone) { const completedDate = getISO8601Date(moment().toISOString()) @@ -131,7 +133,7 @@ export const TaskEditorWithStateManagement = ({ input, onChange, showDeleteDailo // console.log("this.state.calendar_id at DDL", this.state.calendar_id) } - const checkInputForNewTask = async () => { + const checkInputForNewTask = async (isRecurring?: boolean) => { if (input) { if (!input.id) { //Task is New. @@ -189,7 +191,10 @@ export const TaskEditorWithStateManagement = ({ input, onChange, showDeleteDailo //Process done info . if (input.taskDone) { setTaskDone(true) - changeDoneStatus(true) + // console.log("isRepeatingTask", isRepeatingTask) + if(!isRecurring){ + changeDoneStatus(true) + } } @@ -253,7 +258,11 @@ export const TaskEditorWithStateManagement = ({ input, onChange, showDeleteDailo } //Check and set repeating task parameters. setRrule(rruleToObject(parsedData["rrule"])) + const isRecurring = parsedData["rrule"] ? true : false if (parsedData["rrule"]) { + const parsedRecurrenceObj = new RecurrenceHelper(parsedData) + // console.log(parsedRecurrenceObj) + setRecurrenceObj(parsedRecurrenceObj) setIsRepeatingTask(true) } if (parsedData["priority"]) setPriority(parsedData["priority"]) @@ -266,7 +275,7 @@ export const TaskEditorWithStateManagement = ({ input, onChange, showDeleteDailo } // console.log(parsedData) // getLabels(parsedData["category"]) - checkInputForNewTask() + checkInputForNewTask(isRecurring) } } @@ -294,17 +303,43 @@ export const TaskEditorWithStateManagement = ({ input, onChange, showDeleteDailo * Probably to set done for the new recurrenceid. * {TODO}: Figure it out */ - let recurrenceObj = new RecurrenceHelper(parsedDataFromDexie) recurrences = _.cloneDeep(recurrenceObj.newRecurrence) - if (Object.keys(recurrenceObj.newObj).length > 0 && recurrences) { - const nextupKey = recurrenceObj.getNextUpKey() - recurrences[nextupKey] = recurrenceObj.newObj[nextupKey] + try{ + + if (Object.keys(recurrenceObj.newObj).length > 0 && recurrences) { + const nextupKey = recurrenceObj.getNextUpKey() + if(!nextupKey){ + toast.error("NextUpKey is empty!") + return + } + recurrences[nextupKey] = recurrenceObj.newObj[nextupKey] + const completedDate = getISO8601Date(moment().toISOString()) + /** + * If done, set next repeating instance as completed. + */ + if(taskDone){ + recurrences[nextupKey]["completed"] = completedDate + recurrences[nextupKey]["completion"] = "100" + recurrences[nextupKey]["status"] = "COMPLETED" + + }else{ + recurrences[nextupKey]["completed"] = "" + recurrences[nextupKey]["completion"] = "" + recurrences[nextupKey]["status"] = "" + } + + + if (varNotEmpty(recurrences[nextupKey]["recurrenceid"]) == false || (varNotEmpty(recurrences[nextupKey]["recurrenceid"]) && recurrences[nextupKey]["recurrenceid"] == "")) { + recurrences[nextupKey]["recurrenceid"] = getISO8601Date(nextupKey) + } - if (varNotEmpty(recurrences[nextupKey]["recurrenceid"]) == false || (varNotEmpty(recurrences[nextupKey]["recurrenceid"]) && recurrences[nextupKey]["recurrenceid"] == "")) { - recurrences[nextupKey]["recurrenceid"] = getISO8601Date(nextupKey) - } + } + }catch(e){ + console.warn("Recurrence problem: "+summary, e, ) } + + } if (!summary) { @@ -316,12 +351,9 @@ export const TaskEditorWithStateManagement = ({ input, onChange, showDeleteDailo //dueDateToSave = fixDueDate(dueDate) dueDateToSave = moment(moment(dueDate).format(dateFullFormat)).toISOString() } - console.log("due date to save", dueDate, taskStart) + // console.log("due date to save", dueDate, taskStart) const valid = await checkifValid() if (valid) { - if (taskDone) { - - } setSubmitting(true) const todoData = { due: dueDate, start: taskStart, summary: summary, created: parsedDataFromDexie.created, completion: completion, completed: completed, status: status, uid: uid, categories: category, priority: priority, relatedto: relatedto, lastmodified: "", dtstamp: parsedDataFromDexie.dtstamp, description: description, rrule: rrule, recurrences: recurrences } const finalTodoData = await generateNewTaskObject(todoData, parsedDataFromDexie, unParsedData) @@ -438,6 +470,11 @@ export const TaskEditorWithStateManagement = ({ input, onChange, showDeleteDailo } } + + if(isRepeatingTask){ + //Check if the task can even be saved. + + } return true } @@ -517,7 +554,9 @@ export const TaskEditorWithStateManagement = ({ input, onChange, showDeleteDailo const taskDoneChanged = (e) => { setTaskDone(e.target.checked) - changeDoneStatus(e.target.checked) + if(!isRepeatingTask){ + changeDoneStatus(e.target.checked) + } } const statusValueChanged = (e) => { @@ -594,9 +633,8 @@ export const TaskEditorWithStateManagement = ({ input, onChange, showDeleteDailo let repeatInfoMessage: JSX.Element = <> let dueDateFixed = "" if (isRepeatingTask) { - const repeatingInfo = new RecurrenceHelper(parsedDataFromDexie) - dueDateFixed = moment(repeatingInfo.getNextDueDate()).format(dateFullFormat) - repeatInfoMessage = ({i18next.t("REPEAT_TASK_MESSAGE") + moment(new Date(repeatingInfo.getNextDueDate())).format(dateFormat)}) + dueDateFixed = moment(recurrenceObj.getNextDueDate()).format(dateFullFormat) + repeatInfoMessage = ({i18next.t("REPEAT_TASK_MESSAGE") + moment(recurrenceObj.getNextDueDate()).format(dateFormat)}) } diff --git a/src/config/constants.js b/src/config/constants.js index 57e99ac..a0ad4e5 100644 --- a/src/config/constants.js +++ b/src/config/constants.js @@ -1,4 +1,4 @@ -export const VERSION_NUMBER = "0.5.0" +export const VERSION_NUMBER = "0.5.1" /* * SYSTEM_DEFAULT_LABEL_PREFIX: Default prefix applied to all system generated labels like * "My Day" diff --git a/src/helpers/api/cal/caldav.js b/src/helpers/api/cal/caldav.js index 258b159..8485c71 100644 --- a/src/helpers/api/cal/caldav.js +++ b/src/helpers/api/cal/caldav.js @@ -178,8 +178,10 @@ export function checkifObjectisVTODO(data) try{ const parsedData = ical.parseICS(data); for (let k in parsedData) { - // console.log("parse Success") - return parsedData[k].type + // console.log("parse Success",k, parsedData[k]) + if(parsedData[k].type=="VTODO" || parsedData[k].type=="VEVENT") { + return parsedData[k].type + } } }catch(e){ @@ -191,9 +193,9 @@ export function checkifObjectisVTODO(data) if(type=="") { const parsedData = parseICSWithICALJS(data, "VTODO"); - // console.log("parse Success", parsedData) + console.log("parse Success", parsedData) - if(varNotEmpty(parsedData) && parsedData!={}) + if(varNotEmpty(parsedData) && ("summary" in parsedData) && parsedData!={}) { return "VTODO" }else{ diff --git a/src/helpers/frontend/calendar.js b/src/helpers/frontend/calendar.js index 5e7f71e..a7f9ea5 100644 --- a/src/helpers/frontend/calendar.js +++ b/src/helpers/frontend/calendar.js @@ -236,7 +236,10 @@ export function returnEventType(data) try{ const parsedData = ical.parseICS(data); for (let k in parsedData) { - return parsedData[k].type + + if(parsedData[k].type=="VTODO" || parsedData[k].type=="VEVENT") { + return parsedData[k].type + } } } diff --git a/src/helpers/frontend/events.js b/src/helpers/frontend/events.js index b183f65..6cf9b31 100644 --- a/src/helpers/frontend/events.js +++ b/src/helpers/frontend/events.js @@ -255,6 +255,7 @@ export function getParsedEvent(dataInput) { for(const key in data) { + // console.log("data[key]", data[key]) if(data[key].type=="VEVENT") { return data[key] diff --git a/src/pages/api/v2/calendars/events/fetch.ts b/src/pages/api/v2/calendars/events/fetch.ts index db3615f..01b569a 100644 --- a/src/pages/api/v2/calendars/events/fetch.ts +++ b/src/pages/api/v2/calendars/events/fetch.ts @@ -40,12 +40,12 @@ export default async function handler(req, res) { }); if(calendarObjects && isValidResultArray(calendarObjects)){ for(const i in calendarObjects){ - var type = checkifObjectisVTODO(calendarObjects[i]) - // console.log("type", type) + const type = checkifObjectisVTODO(calendarObjects[i].data) calendarObjects[i]["type"]=type } } - res.status(200).json({ version:2, success: true, data: { message: calendarObjects} }) + // console.log("calendarObjects", calendarObjects) + return res.status(200).json({ version:2, success: true, data: { message: calendarObjects} }) }else{ return res.status(401).json({ success: false, data: { message: 'ERROR_GENERIC'} }) @@ -53,7 +53,7 @@ export default async function handler(req, res) { } }else{ - res.status(401).json({ success: false, data: { message: 'USER_DOESNT_HAVE_ACCESS'} }) + return res.status(401).json({ success: false, data: { message: 'USER_DOESNT_HAVE_ACCESS'} }) }