diff --git a/lib/index.js b/lib/index.js index 3e04bd2..2003eaa 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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, diff --git a/lib/utils.js b/lib/utils.js index b26431b..fbaaa21 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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 @@ -107,6 +108,7 @@ 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 */ @@ -114,6 +116,8 @@ var yahooShareUrl = function yahooShareUrl(_ref2) { 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, @@ -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; }; /** @@ -138,6 +144,7 @@ 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 */ @@ -145,6 +152,8 @@ var buildShareFile = function buildShareFile(_ref3) { 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, @@ -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) { diff --git a/react-add-to-calendar-hoc-1.0.10.tgz b/react-add-to-calendar-hoc-1.0.10.tgz new file mode 100644 index 0000000..b7be7c1 Binary files /dev/null and b/react-add-to-calendar-hoc-1.0.10.tgz differ diff --git a/src/lib/index.jsx b/src/lib/index.jsx index c1dd7f0..a9a28b9 100644 --- a/src/lib/index.jsx +++ b/src/lib/index.jsx @@ -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, diff --git a/src/lib/utils.js b/src/lib/utils.js index 833dbf8..1d39dfe 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -46,6 +46,7 @@ export const escapeICSDescription = description => description.replace(/(\r?\n|< */ const googleShareUrl = ({ description, + altdescription, endDatetime, location, startDatetime, @@ -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 @@ -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', @@ -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'); @@ -123,16 +128,19 @@ 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, ) => { @@ -140,12 +148,14 @@ export const buildShareUrl = ({ 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) { diff --git a/src/lib/utils.test.js b/src/lib/utils.test.js index f534e4c..a6ddb84 100644 --- a/src/lib/utils.test.js +++ b/src/lib/utils.test.js @@ -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: '