react-weekly-planning 1.0.32 → 1.0.34
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/components/CalendarForday.js +9 -9
- package/components/CalendarForday.tsx +36 -36
- package/lib/utils.js +0 -18
- package/lib/utils.ts +4 -19
- package/package.json +1 -8
- package/style.css +23 -0
- package/__tests__/page.test.js +0 -106
- package/__tests__/page.test.tsx +0 -129
- package/definition.txt +0 -319
- package/docs/global.html +0 -4983
- package/docs/index.html +0 -475
- package/docs/index.ts.html +0 -551
- package/docs/scripts/app.min.js +0 -1
- package/docs/scripts/linenumber.js +0 -26
- package/docs/scripts/search.js +0 -39
- package/docs/styles/app.min.css +0 -1
- package/docs/styles/iframe.css +0 -13
- package/docs/styles/prettify-jsdoc.css +0 -111
- package/docs/styles/prettify-tomorrow.css +0 -132
- package/docs/styles/reset.css +0 -44
- package/myJsDoc.js +0 -0
- package/out/index.html +0 -129
- package/out/scripts/app.min.js +0 -1
- package/out/scripts/linenumber.js +0 -26
- package/out/scripts/search.js +0 -39
- package/out/styles/app.min.css +0 -1
- package/out/styles/iframe.css +0 -13
- package/out/styles/prettify-jsdoc.css +0 -111
- package/out/styles/prettify-tomorrow.css +0 -132
- package/out/styles/reset.css +0 -44
|
@@ -16,15 +16,15 @@ function CalendarForDay(props) {
|
|
|
16
16
|
const currentDailyHours = dailyHours[props.dayOffset || 0];
|
|
17
17
|
return (_jsxs("div", { className: ` CalendarTableForDay ${props.className}`, style: Object.assign({}, props.style), children: [currentDay && (_jsx(DayContainer, { style: props.dayStyle, className: props.dayClassName, dayIndex: props.dayOffset || 0, dayRender: props.dayRender, day: currentDay.day, dayOfTheMonth: currentDay.dayOfTheMonth, dayMonth: currentDay.dayMonth, dayYear: currentDay.dayYear })), _jsx("div", { className: `CalendarTableForDayTasksContainer`, children: currentDailyHours &&
|
|
18
18
|
props.groups.map((group, i) => {
|
|
19
|
-
return (_jsxs("div", { style: Object.assign({ width: "100%", height: "auto",
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
return (_jsxs("div", { style: Object.assign({ width: "100%", height: "auto", padding: "5px", borderBottom: "1.5px solid #0f52737e", borderRight: "0.74px solid rgba(198, 219, 225, 0.68)", borderLeft: "0.74px solid rgba(198, 219, 225, 0.68)" }, props.rowsStyle), className: `CalendarTableForDayRow ${props.rowsClassName}`, children: [_jsx("div", { style: Object.assign({ width: "auto", height: "auto" }, props.groupsColsStyle), className: props.groupsColsClassName, children: _jsx(GroupContainer, { style: props.groupContainerStyle, className: props.groupContainerClassName, groupRender: props.groupRender, currentGroup: group, handleClickGroup: props.handleClickGroup }) }), _jsxs("div", { className: "CalendarTableForDayGroupTasks", children: [props.tasks.map((task, taskKey) => {
|
|
20
|
+
if (task.dayIndex === (props.dayOffset || 0) &&
|
|
21
|
+
task.groupId === group.id &&
|
|
22
|
+
compareWeekOffset(props.date, props.weekOffset || 0, task.taskDate, props.timeZone)) {
|
|
23
|
+
return (_jsx(TaskContainer, { handleDragTask: props.handleDragTask, taskRender: props.taskRender, handleDragTaskEnd: props.handleDragTaskEnd, style: props.taskContainerStyle, className: `${props.taskContainerClassName}`, currentTask: task, handleClickTask: props.handleClickTask }, `${taskKey} task`));
|
|
24
|
+
}
|
|
25
|
+
else
|
|
26
|
+
return "";
|
|
27
|
+
}), _jsx(AddTask, { addTaskStyle: props.addTaskStyle, addTaskClassName: props.addTaskClassName, currentGroup: group, dayInfo: currentDailyHours, addTaskRender: props.addTaskRender, handleAddTask: props.handleAddTask })] })] }, i));
|
|
28
28
|
}) })] }));
|
|
29
29
|
}
|
|
30
30
|
export default memo(CalendarForDay, (prevProps, nextProps) => prevProps.tasks === nextProps.tasks &&
|
|
@@ -51,14 +51,13 @@ function CalendarForDay(props: CalendarTablePropsType) {
|
|
|
51
51
|
style={{
|
|
52
52
|
width: "100%",
|
|
53
53
|
height: "auto",
|
|
54
|
-
background: "#f2f8f8",
|
|
55
54
|
padding: "5px",
|
|
56
55
|
borderBottom: "1.5px solid #0f52737e",
|
|
57
56
|
borderRight: "0.74px solid rgba(198, 219, 225, 0.68)",
|
|
58
57
|
borderLeft: "0.74px solid rgba(198, 219, 225, 0.68)",
|
|
59
58
|
...props.rowsStyle,
|
|
60
59
|
}}
|
|
61
|
-
className={
|
|
60
|
+
className={`CalendarTableForDayRow ${props.rowsClassName}`}
|
|
62
61
|
>
|
|
63
62
|
<div
|
|
64
63
|
style={{
|
|
@@ -76,40 +75,41 @@ function CalendarForDay(props: CalendarTablePropsType) {
|
|
|
76
75
|
handleClickGroup={props.handleClickGroup}
|
|
77
76
|
/>
|
|
78
77
|
</div>
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
78
|
+
<div className="CalendarTableForDayGroupTasks">
|
|
79
|
+
{props.tasks.map((task, taskKey) => {
|
|
80
|
+
if (
|
|
81
|
+
task.dayIndex === (props.dayOffset || 0) &&
|
|
82
|
+
task.groupId === group.id &&
|
|
83
|
+
compareWeekOffset(
|
|
84
|
+
props.date,
|
|
85
|
+
props.weekOffset || 0,
|
|
86
|
+
task.taskDate,
|
|
87
|
+
props.timeZone
|
|
88
|
+
)
|
|
89
|
+
) {
|
|
90
|
+
return (
|
|
91
|
+
<TaskContainer
|
|
92
|
+
key={`${taskKey} task`}
|
|
93
|
+
handleDragTask={props.handleDragTask}
|
|
94
|
+
taskRender={props.taskRender}
|
|
95
|
+
handleDragTaskEnd={props.handleDragTaskEnd}
|
|
96
|
+
style={props.taskContainerStyle}
|
|
97
|
+
className={`${props.taskContainerClassName}`}
|
|
98
|
+
currentTask={task}
|
|
99
|
+
handleClickTask={props.handleClickTask}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
} else return "";
|
|
103
|
+
})}
|
|
104
|
+
<AddTask
|
|
105
|
+
addTaskStyle={props.addTaskStyle}
|
|
106
|
+
addTaskClassName={props.addTaskClassName}
|
|
107
|
+
currentGroup={group}
|
|
108
|
+
dayInfo={currentDailyHours}
|
|
109
|
+
addTaskRender={props.addTaskRender}
|
|
110
|
+
handleAddTask={props.handleAddTask}
|
|
111
|
+
/>
|
|
112
|
+
</div>
|
|
113
113
|
</div>
|
|
114
114
|
);
|
|
115
115
|
})}
|
package/lib/utils.js
CHANGED
|
@@ -9,7 +9,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import moment from "moment";
|
|
13
12
|
import dayjs from "dayjs";
|
|
14
13
|
import { v4 as uuidv4 } from "uuid";
|
|
15
14
|
export const DAY_IN_MILLISECONDS = 86400000;
|
|
@@ -184,18 +183,6 @@ export function calculerEcartSemaine(dateSelectionnee, timeZone) {
|
|
|
184
183
|
* @param numeroSemaine - The week number.
|
|
185
184
|
* @returns The number of weeks since the origin date.
|
|
186
185
|
*/
|
|
187
|
-
function semainesDepuisOrigine(annee, numeroSemaine) {
|
|
188
|
-
const dateActuelle = new Date();
|
|
189
|
-
const dateOrigine = new Date(dateActuelle.getFullYear() - 2, 0, 1);
|
|
190
|
-
const anneeOrigine = dateOrigine.getFullYear();
|
|
191
|
-
const numeroSemaineOrigine = getWeekNumber(dateOrigine);
|
|
192
|
-
let nombreSemaines = 0;
|
|
193
|
-
for (let i = anneeOrigine; i < annee; i++) {
|
|
194
|
-
nombreSemaines += moment().year(i).isoWeeksInYear();
|
|
195
|
-
}
|
|
196
|
-
nombreSemaines += numeroSemaine - numeroSemaineOrigine;
|
|
197
|
-
return nombreSemaines;
|
|
198
|
-
}
|
|
199
186
|
export function getSessionStorageRecordForDragAndDrop(tasks, positionDay, dropGroupId) {
|
|
200
187
|
const dragtaskId = window.sessionStorage.getItem("calendardragtaskId");
|
|
201
188
|
const dragtaskStart = window.sessionStorage.getItem("calendardragtaskStart");
|
|
@@ -229,10 +216,7 @@ export function compareWeekOffset(calendarDate, weekOffset, taskDate, timeZone)
|
|
|
229
216
|
// if (taskDate.getDay() === 0 && calculerEcartSemaine(taskDate) === -7) {
|
|
230
217
|
// return true;
|
|
231
218
|
// }
|
|
232
|
-
console.log(weekOffset, "WEEKOFFSET", calculerEcartSemaine(taskDate, timeZone) + 7);
|
|
233
|
-
console.log(calendarDate, "CALENDAR DATE");
|
|
234
219
|
const localTaskDate = getArbitraryDateInTimeZone(taskDate, timeZone);
|
|
235
|
-
console.log(localTaskDate.getDay(), "TASK DATE", localTaskDate);
|
|
236
220
|
// if (calendarDate)
|
|
237
221
|
// return (calculerEcartSemaine(calendarDate) === calculerEcartSemaine(taskDate));
|
|
238
222
|
const ecartTask = calculerEcartSemaine(taskDate, timeZone) + (localTaskDate.getDay() === 0 ? 7 : 0);
|
|
@@ -299,7 +283,6 @@ export const getSavedTasks = () => {
|
|
|
299
283
|
const tasksTable = JSON.parse(taskSavedString);
|
|
300
284
|
const savedTasks = tasksTable.map((task) => {
|
|
301
285
|
const { taskDate, taskExpiryDate } = task, rest = __rest(task, ["taskDate", "taskExpiryDate"]);
|
|
302
|
-
console.log("SAVED", taskDate);
|
|
303
286
|
if (taskExpiryDate) {
|
|
304
287
|
return Object.assign({ taskDate: new Date(taskDate), taskExpiryDate: new Date(taskExpiryDate) }, rest);
|
|
305
288
|
}
|
|
@@ -430,7 +413,6 @@ export function recurringTasks(allTasks, task, recurrenceType, occurrences, time
|
|
|
430
413
|
else if (recurrenceType === "monthly") {
|
|
431
414
|
monthly();
|
|
432
415
|
}
|
|
433
|
-
console.log(tasks);
|
|
434
416
|
// Return the list of generated tasks
|
|
435
417
|
return tasks;
|
|
436
418
|
}
|
package/lib/utils.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import moment from "moment";
|
|
2
1
|
import dayjs from "dayjs";
|
|
3
2
|
import { v4 as uuidv4 } from "uuid";
|
|
4
3
|
import {
|
|
@@ -210,20 +209,7 @@ export function calculerEcartSemaine(dateSelectionnee: Date, timeZone?: TimeZone
|
|
|
210
209
|
* @param numeroSemaine - The week number.
|
|
211
210
|
* @returns The number of weeks since the origin date.
|
|
212
211
|
*/
|
|
213
|
-
function semainesDepuisOrigine(annee: number, numeroSemaine: number): number {
|
|
214
|
-
const dateActuelle = new Date();
|
|
215
|
-
const dateOrigine = new Date(dateActuelle.getFullYear() - 2, 0, 1);
|
|
216
|
-
const anneeOrigine = dateOrigine.getFullYear();
|
|
217
|
-
const numeroSemaineOrigine = getWeekNumber(dateOrigine);
|
|
218
|
-
|
|
219
|
-
let nombreSemaines = 0;
|
|
220
|
-
for (let i = anneeOrigine; i < annee; i++) {
|
|
221
|
-
nombreSemaines += moment().year(i).isoWeeksInYear();
|
|
222
|
-
}
|
|
223
|
-
nombreSemaines += numeroSemaine - numeroSemaineOrigine;
|
|
224
212
|
|
|
225
|
-
return nombreSemaines;
|
|
226
|
-
}
|
|
227
213
|
|
|
228
214
|
export function getSessionStorageRecordForDragAndDrop(
|
|
229
215
|
tasks: TasksType,
|
|
@@ -280,10 +266,9 @@ export function compareWeekOffset(
|
|
|
280
266
|
// }
|
|
281
267
|
|
|
282
268
|
|
|
283
|
-
|
|
284
|
-
console.log(calendarDate, "CALENDAR DATE");
|
|
269
|
+
|
|
285
270
|
const localTaskDate = getArbitraryDateInTimeZone(taskDate, timeZone);
|
|
286
|
-
|
|
271
|
+
|
|
287
272
|
|
|
288
273
|
// if (calendarDate)
|
|
289
274
|
// return (calculerEcartSemaine(calendarDate) === calculerEcartSemaine(taskDate));
|
|
@@ -380,7 +365,7 @@ export const getSavedTasks = () => {
|
|
|
380
365
|
const savedTasks: TasksType | any = tasksTable.map((task) => {
|
|
381
366
|
const { taskDate, taskExpiryDate, ...rest } = task;
|
|
382
367
|
|
|
383
|
-
|
|
368
|
+
|
|
384
369
|
|
|
385
370
|
if (taskExpiryDate) {
|
|
386
371
|
return {
|
|
@@ -578,7 +563,7 @@ export function recurringTasks(
|
|
|
578
563
|
monthly();
|
|
579
564
|
}
|
|
580
565
|
|
|
581
|
-
|
|
566
|
+
|
|
582
567
|
|
|
583
568
|
// Return the list of generated tasks
|
|
584
569
|
return tasks;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-weekly-planning",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest --env=jsdom",
|
|
@@ -41,13 +41,8 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@babel/types": "^7.29.0",
|
|
43
43
|
"@types/babel__generator": "^7.27.0",
|
|
44
|
-
"axios": "^1.13.6",
|
|
45
44
|
"dayjs": "^1.11.19",
|
|
46
|
-
"ical": "^0.8.0",
|
|
47
|
-
"ics-to-json": "^2.0.2",
|
|
48
|
-
"moment": "^2.30.1",
|
|
49
45
|
"react-window": "^2.2.7",
|
|
50
|
-
"sass": "^1.97.3",
|
|
51
46
|
"ts-node": "^10.9.2",
|
|
52
47
|
"uuid": "^13.0.0"
|
|
53
48
|
},
|
|
@@ -60,12 +55,10 @@
|
|
|
60
55
|
"@testing-library/jest-dom": "^6.9.1",
|
|
61
56
|
"@testing-library/react": "^16.3.2",
|
|
62
57
|
"@types/babel__core": "^7.20.5",
|
|
63
|
-
"@types/ical": "^0.8.3",
|
|
64
58
|
"@types/jest": "^30.0.0",
|
|
65
59
|
"@types/react": "^19.2.14",
|
|
66
60
|
"@types/react-window": "^2.0.0",
|
|
67
61
|
"babel-jest": "^30.2.0",
|
|
68
|
-
"docdash": "^2.0.2",
|
|
69
62
|
"jest": "^30.2.0",
|
|
70
63
|
"jest-environment-jsdom": "^30.2.0",
|
|
71
64
|
"react": "^19.2.4",
|
package/style.css
CHANGED
|
@@ -98,3 +98,26 @@
|
|
|
98
98
|
padding: 10px;
|
|
99
99
|
position: relative;
|
|
100
100
|
}
|
|
101
|
+
|
|
102
|
+
.CalendarTableForDayRow {
|
|
103
|
+
display: flex !important;
|
|
104
|
+
flex-direction: row !important;
|
|
105
|
+
gap: 15px;
|
|
106
|
+
align-items: flex-start;
|
|
107
|
+
padding: 15px !important;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.CalendarTableForDayGroupTasks {
|
|
111
|
+
flex: 1;
|
|
112
|
+
display: grid;
|
|
113
|
+
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
|
114
|
+
gap: 10px;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.CalendarTableForDayGroupTasks .taskContainer,
|
|
118
|
+
.CalendarTableForDayGroupTasks .addPlanStyle {
|
|
119
|
+
margin-bottom: 0px;
|
|
120
|
+
height: 100%;
|
|
121
|
+
min-height: 80px;
|
|
122
|
+
}
|
|
123
|
+
|
package/__tests__/page.test.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import "@testing-library/jest-dom";
|
|
11
|
-
import ical from "ical";
|
|
12
|
-
export function parseICSToTasks(icsData, group) {
|
|
13
|
-
var _a;
|
|
14
|
-
const events = ical.parseICS(icsData);
|
|
15
|
-
const tasks = [];
|
|
16
|
-
for (const key in events) {
|
|
17
|
-
const event = events[key];
|
|
18
|
-
if (event.type === "VEVENT") {
|
|
19
|
-
const taskStart = event.start
|
|
20
|
-
? new Date(event.start).getTime()
|
|
21
|
-
: new Date().getTime();
|
|
22
|
-
const taskEnd = event.end
|
|
23
|
-
? new Date(event.end).getTime()
|
|
24
|
-
: new Date().getTime();
|
|
25
|
-
const taskDate = event.start ? new Date(event.start) : new Date();
|
|
26
|
-
const taskSummary = event.summary || "";
|
|
27
|
-
const taskLocation = event.location || "";
|
|
28
|
-
const taskTimezone = "";
|
|
29
|
-
const taskCreatedAt = event.created
|
|
30
|
-
? new Date(event.created)
|
|
31
|
-
: new Date();
|
|
32
|
-
const taskExpiryDate = ((_a = event.rrule) === null || _a === void 0 ? void 0 : _a.options.until)
|
|
33
|
-
? new Date(event.rrule.options.until)
|
|
34
|
-
: new Date();
|
|
35
|
-
const task = {
|
|
36
|
-
taskStart,
|
|
37
|
-
taskEnd,
|
|
38
|
-
taskDate,
|
|
39
|
-
taskSummary,
|
|
40
|
-
taskLocation,
|
|
41
|
-
taskTimzone: taskTimezone,
|
|
42
|
-
groupId: group,
|
|
43
|
-
dayIndex: taskDate.getDay() || 0,
|
|
44
|
-
taskId: event.uid || "",
|
|
45
|
-
taskCreatedAt,
|
|
46
|
-
taskExpiryDate,
|
|
47
|
-
};
|
|
48
|
-
tasks.push(task);
|
|
49
|
-
if (!event.start)
|
|
50
|
-
return [];
|
|
51
|
-
// Gestion des occurrences récurrentes
|
|
52
|
-
if (event.rrule) {
|
|
53
|
-
const occurrences = event.rrule.between(event.start, taskExpiryDate || new Date());
|
|
54
|
-
occurrences.forEach((occurrence) => {
|
|
55
|
-
tasks.push(Object.assign(Object.assign({}, task), { taskStart: occurrence.getTime(), taskEnd: occurrence.getTime() + (taskEnd - taskStart), taskDate: new Date(occurrence.getTime()), dayIndex: new Date(occurrence.getTime()).getDay() }));
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return tasks;
|
|
61
|
-
}
|
|
62
|
-
import axios from "axios";
|
|
63
|
-
// Get ICS text however you like, example below
|
|
64
|
-
// Make sure you have the right CORS settings if needed
|
|
65
|
-
const convert = (fileLocation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
-
try {
|
|
67
|
-
const task = fileLocation.map((link) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
-
const icsRes = yield axios.get(link);
|
|
69
|
-
const icstext = yield icsRes.data;
|
|
70
|
-
const data = parseICSToTasks(icstext, "morel");
|
|
71
|
-
return data;
|
|
72
|
-
}));
|
|
73
|
-
console.log(task);
|
|
74
|
-
return "success";
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
return "error";
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
export function convertTasksToIcsFormat(tasks) {
|
|
81
|
-
const ics = tasks.reduce((previousIcs, task) => {
|
|
82
|
-
previousIcs += `
|
|
83
|
-
|
|
84
|
-
BEGIN:VCALENDAR
|
|
85
|
-
VERSION:1.0
|
|
86
|
-
BEGIN:VEVENT
|
|
87
|
-
DTSTART:${task.taskStart}
|
|
88
|
-
DTEND:${task.taskEnd}
|
|
89
|
-
LOCATION:
|
|
90
|
-
DESCRIPTION:Purpose: Provide example of this file type Document file type: ICS Version: 1.0 Created by http://www.online-convert.com More example files: http://www.online-convert.com/file-type License: http://creativecommons.org/licenses Feel free to use & share the file according to the license above.
|
|
91
|
-
SUMMARY:ICS test file
|
|
92
|
-
PRIORITY:3
|
|
93
|
-
END:VEVENT
|
|
94
|
-
END:VCALENDAR
|
|
95
|
-
|
|
96
|
-
`;
|
|
97
|
-
return previousIcs;
|
|
98
|
-
}, "");
|
|
99
|
-
return ics;
|
|
100
|
-
}
|
|
101
|
-
test("the fetch fails with an error", () => {
|
|
102
|
-
return convert([
|
|
103
|
-
"https://firebasestorage.googleapis.com/v0/b/ashtonv2.appspot.com/o/example.ics?alt=media&token=679cab97-cde2-4074-b96f-b63c10f1b7e2",
|
|
104
|
-
"https://firebasestorage.googleapis.com/v0/b/ashtonv2.appspot.com/o/example.ics?alt=media&token=679cab97-cde2-4074-b96f-b63c10f1b7e2",
|
|
105
|
-
]).catch((error) => expect(error).toMatch("error"));
|
|
106
|
-
});
|
package/__tests__/page.test.tsx
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { render } from "@testing-library/react";
|
|
2
|
-
import Calendar from "..";
|
|
3
|
-
import "@testing-library/jest-dom";
|
|
4
|
-
import { TaskFeildsType } from "../definitions";
|
|
5
|
-
import { icsToJson } from "ics-to-json";
|
|
6
|
-
|
|
7
|
-
import ical from "ical";
|
|
8
|
-
|
|
9
|
-
export function parseICSToTasks(
|
|
10
|
-
icsData: string,
|
|
11
|
-
group: string
|
|
12
|
-
): TaskFeildsType[] {
|
|
13
|
-
const events = ical.parseICS(icsData);
|
|
14
|
-
const tasks: TaskFeildsType[] = [];
|
|
15
|
-
|
|
16
|
-
for (const key in events) {
|
|
17
|
-
const event = events[key];
|
|
18
|
-
|
|
19
|
-
if (event.type === "VEVENT") {
|
|
20
|
-
const taskStart = event.start
|
|
21
|
-
? new Date(event.start).getTime()
|
|
22
|
-
: new Date().getTime();
|
|
23
|
-
const taskEnd = event.end
|
|
24
|
-
? new Date(event.end).getTime()
|
|
25
|
-
: new Date().getTime();
|
|
26
|
-
const taskDate = event.start ? new Date(event.start) : new Date();
|
|
27
|
-
const taskSummary = event.summary || "";
|
|
28
|
-
const taskLocation = event.location || "";
|
|
29
|
-
const taskTimezone = "";
|
|
30
|
-
const taskCreatedAt = event.created
|
|
31
|
-
? new Date(event.created)
|
|
32
|
-
: new Date();
|
|
33
|
-
const taskExpiryDate = event.rrule?.options.until
|
|
34
|
-
? new Date(event.rrule.options.until)
|
|
35
|
-
: new Date();
|
|
36
|
-
|
|
37
|
-
const task: TaskFeildsType[][number] = {
|
|
38
|
-
taskStart,
|
|
39
|
-
taskEnd,
|
|
40
|
-
taskDate,
|
|
41
|
-
taskSummary,
|
|
42
|
-
taskLocation,
|
|
43
|
-
taskTimzone: taskTimezone,
|
|
44
|
-
groupId: group,
|
|
45
|
-
dayIndex: taskDate.getDay() || 0,
|
|
46
|
-
taskId: event.uid || "",
|
|
47
|
-
taskCreatedAt,
|
|
48
|
-
taskExpiryDate,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
tasks.push(task);
|
|
52
|
-
|
|
53
|
-
if (!event.start) return [];
|
|
54
|
-
|
|
55
|
-
// Gestion des occurrences récurrentes
|
|
56
|
-
if (event.rrule) {
|
|
57
|
-
const occurrences = event.rrule.between(
|
|
58
|
-
event.start,
|
|
59
|
-
taskExpiryDate || new Date()
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
occurrences.forEach((occurrence) => {
|
|
63
|
-
tasks.push({
|
|
64
|
-
...task,
|
|
65
|
-
taskStart: occurrence.getTime(),
|
|
66
|
-
taskEnd: occurrence.getTime() + (taskEnd - taskStart),
|
|
67
|
-
taskDate: new Date(occurrence.getTime()),
|
|
68
|
-
dayIndex: new Date(occurrence.getTime()).getDay(),
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return tasks;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
import axios from "axios";
|
|
79
|
-
// Get ICS text however you like, example below
|
|
80
|
-
// Make sure you have the right CORS settings if needed
|
|
81
|
-
const convert = async (fileLocation: string[]) => {
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
const task = fileLocation.map(async (link) => {
|
|
85
|
-
const icsRes = await axios.get(link);
|
|
86
|
-
const icstext:string = await icsRes.data;
|
|
87
|
-
const data = parseICSToTasks(icstext, "morel");
|
|
88
|
-
return data;
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
console.log(task);
|
|
92
|
-
return "success";
|
|
93
|
-
} catch (error) {
|
|
94
|
-
return "error";
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
export function convertTasksToIcsFormat(tasks: TaskFeildsType[]) {
|
|
100
|
-
const ics = tasks.reduce((previousIcs: string, task: TaskFeildsType) => {
|
|
101
|
-
previousIcs += `
|
|
102
|
-
|
|
103
|
-
BEGIN:VCALENDAR
|
|
104
|
-
VERSION:1.0
|
|
105
|
-
BEGIN:VEVENT
|
|
106
|
-
DTSTART:${task.taskStart}
|
|
107
|
-
DTEND:${task.taskEnd}
|
|
108
|
-
LOCATION:
|
|
109
|
-
DESCRIPTION:Purpose: Provide example of this file type Document file type: ICS Version: 1.0 Created by http://www.online-convert.com More example files: http://www.online-convert.com/file-type License: http://creativecommons.org/licenses Feel free to use & share the file according to the license above.
|
|
110
|
-
SUMMARY:ICS test file
|
|
111
|
-
PRIORITY:3
|
|
112
|
-
END:VEVENT
|
|
113
|
-
END:VCALENDAR
|
|
114
|
-
|
|
115
|
-
`;
|
|
116
|
-
|
|
117
|
-
return previousIcs;
|
|
118
|
-
}, "");
|
|
119
|
-
|
|
120
|
-
return ics;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
test("the fetch fails with an error", () => {
|
|
125
|
-
return convert([
|
|
126
|
-
"https://firebasestorage.googleapis.com/v0/b/ashtonv2.appspot.com/o/example.ics?alt=media&token=679cab97-cde2-4074-b96f-b63c10f1b7e2",
|
|
127
|
-
"https://firebasestorage.googleapis.com/v0/b/ashtonv2.appspot.com/o/example.ics?alt=media&token=679cab97-cde2-4074-b96f-b63c10f1b7e2",
|
|
128
|
-
]).catch((error) => expect(error).toMatch("error"));
|
|
129
|
-
});
|