react-weekly-planning 1.0.24 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,7 +11,9 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
11
11
 
12
12
  ![Planning Screenshot](https://raw.githubusercontent.com/Yvesmorel/react-pweekly-planning/main/assets/planning-screenshot.webp)
13
13
 
14
+ [See the demo](https://react-weekly-planning-demo.vercel.app)
14
15
 
16
+ [Demo repository](https://github.com/Yvesmorel/react-weekly-planning-demo.git)
15
17
 
16
18
  #### `weekOffset`
17
19
 
@@ -68,6 +70,30 @@ It is possible to use either Weekoffset or Date, or even both simultaneously.
68
70
  <Calendar tasks={tasks} ... />
69
71
  ```
70
72
 
73
+ - **Supplementary property** : If you want the tasks to be saved up to a date of your choice you can define the `taskExpiryDate` property. It's an idea of [Patrick Aimé](https://www.linkedin.com/in/patrick-aime?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=android_app).
74
+
75
+ - **Example**:Here's how to create a task that will expire in a day.
76
+ ```jsx
77
+ const tasks = [
78
+ { taskId: '1', taskStart:'Time in milliseconde', taskEnd:'Time in milliseconde', task: 'Task 1', taskDate: new Date(), groupId: '1', dayIndex: 0,taskExpiryDate:new Date(Date.now() + 86400000) ... }
79
+ ];
80
+
81
+ <Calendar tasks={tasks} ... />
82
+ ```
83
+
84
+ `taskExpiryDate` is used with `getSavedTasks()` To obtain the saved tasks.
85
+
86
+ **Example**:
87
+ ```jsx
88
+ import {getSavedTasks} from "react-weekly-planning";
89
+ const [tasks,setTasks]=useState([])
90
+
91
+ useEffect(()=>{
92
+ setTasks(getSavedTasks())
93
+ },[])
94
+
95
+ <Calendar tasks={tasks} ... />
96
+ ```
71
97
  ---
72
98
  ---
73
99
 
package/index.js CHANGED
@@ -217,7 +217,7 @@ export const checkDuplicates = (tasks, taskStart, taskEnd, groupId) => {
217
217
  taskStart <= task.taskEnd)).filter((task) => task.groupId === groupId);
218
218
  return findDuplicates.length > 0;
219
219
  };
220
- export const getTasksSaved = () => {
220
+ export const getSavedTasks = () => {
221
221
  const taskSavedString = window.localStorage.getItem("CalendarTaskSaved");
222
222
  if (!taskSavedString) {
223
223
  return [];
package/index.tsx CHANGED
@@ -582,30 +582,24 @@ export const checkDuplicates = (
582
582
  return findDuplicates.length > 0;
583
583
  };
584
584
 
585
- export const getTasksSaved = () => {
585
+ export const getSavedTasks = () => {
586
586
  const taskSavedString = window.localStorage.getItem("CalendarTaskSaved");
587
587
  if (!taskSavedString) {
588
588
  return [];
589
589
  }
590
590
  const tasksTable: TasksType = JSON.parse(taskSavedString);
591
- const validTasks = tasksTable
592
- .filter((task) => {
593
- if (task?.taskExpiryDate) {
594
- const taskDate = new Date(task?.taskExpiryDate);
595
- return taskDate.getTime() >= Date.now();
596
- }
597
- })
598
- .map((task) => {
599
- const { taskDate, taskExpiryDate, ...rest } = task;
600
- if (taskExpiryDate) {
601
- return {
602
- taskDate: new Date(taskDate),
603
- taskExpiryDate: new Date(taskExpiryDate),
604
- ...rest,
605
- };
606
- }
607
- });
608
- return validTasks;
591
+
592
+ const savedTasks: TasksType | any = tasksTable.map((task) => {
593
+ const { taskDate, taskExpiryDate, ...rest } = task;
594
+ if (taskExpiryDate) {
595
+ return {
596
+ taskDate: new Date(taskDate),
597
+ taskExpiryDate: new Date(taskExpiryDate),
598
+ ...rest,
599
+ };
600
+ }
601
+ });
602
+ return savedTasks;
609
603
  };
610
604
 
611
605
  export const deleteTaskSaved = (taskId: string) => {
package/lib/utils.js CHANGED
@@ -468,14 +468,22 @@ const sumHoursByGroups = (groupId, tasks, weekOffset, calendarDate) => {
468
468
  function saveTasksToLocalStorage(tasks) {
469
469
  if (typeof window !== "undefined") {
470
470
  window.localStorage.setItem("Calendar", "je marche");
471
- console.log(tasks);
472
471
  const tasksSavedString = window.localStorage.getItem("CalendarTaskSaved");
473
472
  const tasksString = JSON.stringify(tasks);
474
473
  if (tasksSavedString === tasksString)
475
474
  return;
476
475
  if (tasksString === "[]")
477
476
  return;
478
- const backup = [...tasks.filter((task) => task.taskExpiryDate)];
477
+ const backup = [
478
+ ...tasks.filter((task) => {
479
+ {
480
+ if (task === null || task === void 0 ? void 0 : task.taskExpiryDate) {
481
+ const taskDate = new Date(task === null || task === void 0 ? void 0 : task.taskExpiryDate);
482
+ return taskDate.getTime() >= Date.now();
483
+ }
484
+ }
485
+ }),
486
+ ];
479
487
  window.localStorage.setItem("CalendarTaskSaved", JSON.stringify(backup));
480
488
  }
481
489
  }
package/lib/utils.ts CHANGED
@@ -600,16 +600,24 @@ const sumHoursByGroups = (
600
600
  };
601
601
 
602
602
  function saveTasksToLocalStorage(tasks: TasksType) {
603
- if (typeof window !== "undefined") {
604
- window.localStorage.setItem("Calendar","je marche");
605
- console.log(tasks);
606
- const tasksSavedString = window.localStorage.getItem("CalendarTaskSaved");
607
- const tasksString = JSON.stringify(tasks);
608
- if (tasksSavedString === tasksString) return;
609
- if (tasksString === "[]") return;
610
- const backup = [...tasks.filter((task) => task.taskExpiryDate)];
611
- window.localStorage.setItem("CalendarTaskSaved", JSON.stringify(backup));
612
- }
603
+ if (typeof window !== "undefined") {
604
+ window.localStorage.setItem("Calendar", "je marche");
605
+ const tasksSavedString = window.localStorage.getItem("CalendarTaskSaved");
606
+ const tasksString = JSON.stringify(tasks);
607
+ if (tasksSavedString === tasksString) return;
608
+ if (tasksString === "[]") return;
609
+ const backup = [
610
+ ...tasks.filter((task) => {
611
+ {
612
+ if (task?.taskExpiryDate) {
613
+ const taskDate = new Date(task?.taskExpiryDate);
614
+ return taskDate.getTime() >= Date.now();
615
+ }
616
+ }
617
+ }),
618
+ ];
619
+ window.localStorage.setItem("CalendarTaskSaved", JSON.stringify(backup));
620
+ }
613
621
  }
614
622
 
615
623
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-weekly-planning",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "jest",