Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

add a reminder for ics files #44

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function AddToCalendar(WrappedButton, WrappedDropdown) {
dropdownProps: _propTypes.default.shape(),
event: _propTypes.default.shape({
description: _propTypes.default.string,
altdescription: _propTypes.default.string,
duration: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
endDatetime: _propTypes.default.string.isRequired,
location: _propTypes.default.string,
Expand Down
23 changes: 18 additions & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ exports.escapeICSDescription = escapeICSDescription;

var googleShareUrl = function googleShareUrl(_ref) {
var description = _ref.description,
altdescription = _ref.altdescription,
endDatetime = _ref.endDatetime,
location = _ref.location,
startDatetime = _ref.startDatetime,
timezone = _ref.timezone,
title = _ref.title;
return "https://calendar.google.com/calendar/render?action=TEMPLATE&dates=".concat(startDatetime, "/").concat(endDatetime).concat(timezone && "&ctz=".concat(timezone), "&location=").concat(location, "&text=").concat(title, "&details=").concat(description);
return "https://calendar.google.com/calendar/render?action=TEMPLATE&dates=".concat(startDatetime, "/").concat(endDatetime).concat(timezone && "&ctz=".concat(timezone), "&location=").concat(location, "&text=").concat(title, "&details=").concat(altdescription);
};
/**
* Takes an event object and returns a Yahoo Calendar Event URL
Expand Down Expand Up @@ -107,13 +108,16 @@ var yahooShareUrl = function yahooShareUrl(_ref2) {
* @param {string} event.location
* @param {string} event.startDatetime
* @param {string} event.title
* @param {string} event.reminder
* @returns {array} ICS Content
*/


var buildShareFile = function buildShareFile(_ref3) {
var _ref3$description = _ref3.description,
description = _ref3$description === void 0 ? '' : _ref3$description,
_ref3$altdescription = _ref3.altdescription,
altdescription = _ref3$altdescription === void 0 ? '' : _ref3$altdescription,
_ref3$ctz = _ref3.ctz,
ctz = _ref3$ctz === void 0 ? '' : _ref3$ctz,
endDatetime = _ref3.endDatetime,
Expand All @@ -123,10 +127,12 @@ var buildShareFile = function buildShareFile(_ref3) {
_ref3$timezone = _ref3.timezone,
timezone = _ref3$timezone === void 0 ? '' : _ref3$timezone,
_ref3$title = _ref3.title,
title = _ref3$title === void 0 ? '' : _ref3$title;
title = _ref3$title === void 0 ? '' : _ref3$title,
_ref3$reminder = _ref3.reminder,
reminder = _ref3$reminder === void 0 ? '' : _ref3$reminder;
var content = ['BEGIN:VCALENDAR', 'VERSION:2.0', 'BEGIN:VEVENT', "URL:".concat(document.URL), 'METHOD:PUBLISH', // TODO: Will need to parse the date without Z for ics
// This means I'll probably have to require a date lib - luxon most likely or datefns
timezone === '' ? "DTSTART:".concat(startDatetime) : "DTSTART;TZID=".concat(timezone, ":").concat(startDatetime), timezone === '' ? "DTEND:".concat(endDatetime) : "DTEND;TZID=".concat(timezone, ":").concat(endDatetime), "SUMMARY:".concat(title), "DESCRIPTION:".concat(escapeICSDescription(description)), "LOCATION:".concat(location), 'END:VEVENT', 'END:VCALENDAR'].join('\n');
timezone === '' ? "DTSTART:".concat(startDatetime) : "DTSTART;TZID=".concat(timezone, ":").concat(startDatetime), timezone === '' ? "DTEND:".concat(endDatetime) : "DTEND;TZID=".concat(timezone, ":").concat(endDatetime), "SUMMARY:".concat(title), "DESCRIPTION:".concat(escapeICSDescription(description)), "X-ALT-DESC;FMTTYPE=text/html:".concat(escapeICSDescription(altdescription)), "LOCATION:".concat(location), reminder === '' ? 'END:VEVENT' : "BEGIN:VALARM\nTRIGGER:-PT".concat(reminder, "\nACTION:DISPLAY\nEND:VALARM\nEND:VEVENT"), 'END:VCALENDAR'].join('\n');
return isMobile() ? encodeURI("data:text/calendar;charset=utf8,".concat(content)) : content;
};
/**
Expand All @@ -138,13 +144,16 @@ var buildShareFile = function buildShareFile(_ref3) {
* @param {string} event.location
* @param {string} event.startDatetime
* @param {string} event.title
* @param {string} event.reminder
* @param {enum} type One of SHARE_SITES from ./enums
*/


var buildShareUrl = function buildShareUrl(_ref4, type) {
var _ref4$description = _ref4.description,
description = _ref4$description === void 0 ? '' : _ref4$description,
_ref4$altdescription = _ref4.altdescription,
altdescription = _ref4$altdescription === void 0 ? '' : _ref4$altdescription,
duration = _ref4.duration,
endDatetime = _ref4.endDatetime,
_ref4$location = _ref4.location,
Expand All @@ -153,16 +162,20 @@ var buildShareUrl = function buildShareUrl(_ref4, type) {
_ref4$timezone = _ref4.timezone,
timezone = _ref4$timezone === void 0 ? '' : _ref4$timezone,
_ref4$title = _ref4.title,
title = _ref4$title === void 0 ? '' : _ref4$title;
title = _ref4$title === void 0 ? '' : _ref4$title,
_ref4$reminder = _ref4.reminder,
reminder = _ref4$reminder === void 0 ? '' : _ref4$reminder;
var encodeURI = type !== _enums.SHARE_SITES.ICAL && type !== _enums.SHARE_SITES.OUTLOOK;
var data = {
description: encodeURI ? encodeURIComponent(description) : description,
altdescription: encodeURI ? encodeURIComponent(altdescription) : altdescription,
duration: formatDuration(duration),
endDatetime: formatDate(endDatetime),
location: encodeURI ? encodeURIComponent(location) : location,
startDatetime: formatDate(startDatetime),
timezone: timezone,
title: encodeURI ? encodeURIComponent(title) : title
title: encodeURI ? encodeURIComponent(title) : title,
reminder: reminder
};

switch (type) {
Expand Down
Binary file added react-add-to-calendar-hoc-1.0.10.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions src/lib/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function AddToCalendar(WrappedButton, WrappedDropdown) {
dropdownProps: PropTypes.shape(),
event: PropTypes.shape({
description: PropTypes.string,
altdescription : PropTypes.string,
duration: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
Expand Down
16 changes: 13 additions & 3 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const escapeICSDescription = description => description.replace(/(\r?\n|<
*/
const googleShareUrl = ({
description,
altdescription,
endDatetime,
location,
startDatetime,
Expand All @@ -54,7 +55,7 @@ const googleShareUrl = ({
}) =>
`https://calendar.google.com/calendar/render?action=TEMPLATE&dates=${
startDatetime
}/${endDatetime}${timezone && `&ctz=${timezone}`}&location=${location}&text=${title}&details=${description}`;
}/${endDatetime}${timezone && `&ctz=${timezone}`}&location=${location}&text=${title}&details=${altdescription}`;

/**
* Takes an event object and returns a Yahoo Calendar Event URL
Expand Down Expand Up @@ -83,16 +84,19 @@ const yahooShareUrl = ({
* @param {string} event.location
* @param {string} event.startDatetime
* @param {string} event.title
* @param {string} event.reminder
* @returns {array} ICS Content
*/
const buildShareFile = ({
description = '',
altdescription = '',
ctz = '',
endDatetime,
location = '',
startDatetime,
timezone = '',
title = '',
reminder = ''
}) => {
let content = [
'BEGIN:VCALENDAR',
Expand All @@ -106,8 +110,9 @@ const buildShareFile = ({
timezone === '' ? `DTEND:${endDatetime}` : `DTEND;TZID=${timezone}:${endDatetime}`,
`SUMMARY:${title}`,
`DESCRIPTION:${escapeICSDescription(description)}`,
`X-ALT-DESC;FMTTYPE=text/html:${escapeICSDescription(altdescription)}`,
`LOCATION:${location}`,
'END:VEVENT',
reminder === '' ? 'END:VEVENT' : `BEGIN:VALARM\nTRIGGER:-PT${reminder}\nACTION:DISPLAY\nEND:VALARM\nEND:VEVENT`,
'END:VCALENDAR',
].join('\n');

Expand All @@ -123,29 +128,34 @@ const buildShareFile = ({
* @param {string} event.location
* @param {string} event.startDatetime
* @param {string} event.title
* @param {string} event.reminder
* @param {enum} type One of SHARE_SITES from ./enums
*/
export const buildShareUrl = ({
description = '',
altdescription = '',
duration,
endDatetime,
location = '',
startDatetime,
timezone = '',
title = ''
title = '',
reminder = ''
},
type,
) => {
const encodeURI = type !== SHARE_SITES.ICAL && type !== SHARE_SITES.OUTLOOK;

const data = {
description: encodeURI ? encodeURIComponent(description) : description,
altdescription: encodeURI ? encodeURIComponent(altdescription) : altdescription,
duration: formatDuration(duration),
endDatetime: formatDate(endDatetime),
location: encodeURI ? encodeURIComponent(location) : location,
startDatetime: formatDate(startDatetime),
timezone,
title: encodeURI ? encodeURIComponent(title) : title,
reminder,
};

switch (type) {
Expand Down
7 changes: 7 additions & 0 deletions src/lib/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {

const testEvent = {
description: 'Description of event. Going to have a lot of fun doing things that we scheduled ahead of time.',
altdescription: '<div>Description of event with HTML</div>',
duration: '0200',
endDatetime: '20150126T020000+00:00',
location: 'NYC',
Expand All @@ -24,6 +25,7 @@ const expectedOutputs = {
google: 'https://calendar.google.com/calendar/render?action=TEMPLATE&dates=20150126T000000Z/20150126T020000Z&location=NYC&text=Super%20Fun%20Event&details=Description%20of%20event.%20Going%20to%20have%20a%20lot%20of%20fun%20doing%20things%20that%20we%20scheduled%20ahead%20of%20time.',
yahoo: 'https://calendar.yahoo.com/?v=60&view=d&type=20&title=Super%20Fun%20Event&st=20150126T000000Z&dur=0200&desc=Description%20of%20event.%20Going%20to%20have%20a%20lot%20of%20fun%20doing%20things%20that%20we%20scheduled%20ahead%20of%20time.&in_loc=NYC',
ics: 'BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nURL:http://localhost/\nMETHOD:PUBLISH\nDTSTART:20150126T000000Z\nDTEND:20150126T020000Z\nSUMMARY:Super Fun Event\nDESCRIPTION:Description of event. Going to have a lot of fun doing things that we scheduled ahead of time.\nLOCATION:NYC\nEND:VEVENT\nEND:VCALENDAR',
icsWithReminder: 'BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nURL:http://localhost/\nMETHOD:PUBLISH\nDTSTART:20150126T000000Z\nDTEND:20150126T020000Z\nSUMMARY:Super Fun Event\nDESCRIPTION:Description of event. Going to have a lot of fun doing things that we scheduled ahead of time.\nLOCATION:NYC\nBEGIN:VALARM\nTRIGGER:-PT30M\nACTION:DISPLAY\nEND:VALARM\nEND:VEVENT\nEND:VCALENDAR',
icsMobile: 'data:text/calendar;charset=utf8,BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nURL:http://localhost/\nMETHOD:PUBLISH\nDTSTART:20150126T000000Z\nDTEND:20150126T020000Z\nSUMMARY:Super Fun Event\nDESCRIPTION:Description of event. Going to have a lot of fun doing things that we scheduled ahead of time.\nLOCATION:NYC\nEND:VEVENT\nEND:VCALENDAR',
}

Expand Down Expand Up @@ -77,6 +79,11 @@ describe('buildShareUrl', () => {
expect(result).toEqual(expectedOutputs.ics);
});

it('returns a proper iCal content object with a reminder', () => {
const result = buildShareUrl({...testEvent, ...{reminder: '30M'}}, SHARE_SITES.ICAL);
expect(result).toEqual(expectedOutputs.icsWithReminder);
});

it('prepends a data URL when userAgent is mobile', () => {
navigator.__defineGetter__('userAgent', function () {
return "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1";
Expand Down