Merge pull request #93 from Protospace/google-calendar-support

Google calendar support
This commit is contained in:
Tanner Collin 2022-07-12 03:42:26 +00:00 committed by GitHub
commit 61c263151f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 10 deletions

View File

@ -450,19 +450,61 @@ export function ICalButtons(props) {
});
};
const addToGoogleCalendar = (e) => {
e.preventDefault();
// construct and set the dates format that google calendar links require
let starttime = moment(clazz.datetime);
let endtime = starttime.clone().add(1, 'hour');
const datestringfmt = 'YYYYMMDDTkkmmss';
let dates = `${starttime.format(datestringfmt)}/${endtime.format(datestringfmt)}`
// send user to google calendar
window.location = `https://www.google.com/calendar/render?action=TEMPLATE&text=${clazz.course_data.name}&dates=${dates}`;
};
const options = [
{ key: 'email', icon: 'mail outline', text: 'Email ICS Event', value: 'Email', action: handleEmail },
{ key: 'download', icon: 'download', text: 'Download ICS Event', value: 'Download', action: handleDownload },
{ key: 'google', icon: 'google', text: 'Add to Google Calendar', value: 'Google', action: addToGoogleCalendar },
];
// get default option from local storage or default to first item in options list
const calendarValue = localStorage.getItem('calendarPreference') || 'Email';
const defaultOption = options.find(x => x.value === calendarValue);
const [selectedOption, setOption] = useState(defaultOption);
const onChange = (e, data) => {
const newOption = options.find(x => x.value === data.value);
setOption(newOption);
// set the option as users preference
localStorage.setItem('calendarPreference', newOption.value);
};
return (
<>
<Button compact onClick={handleDownload}>
Download
</Button>
{success ?
<span>&nbsp;&nbsp;Sent!</span>
:
<Button compact loading={loading} onClick={handleEmail}>
Email
<Button.Group>
<Button
loading={loading}
onClick={selectedOption.action}
>
<Icon name={selectedOption.icon} />{selectedOption.value}
</Button>
<Dropdown
className='button icon'
floating
onChange={onChange}
options={options}
trigger={<></>}
selectOnBlur={false}
/>
</Button.Group>
}
{error && <span>Error.</span>}
</>
);
};

View File

@ -99,6 +99,12 @@ body {
padding-top: 1rem;
}
.ui.floating.dropdown.button.icon {
border-left: 1px;
border-left-color: #c0c1c2;
border-left-style: solid;
}
.attendance-row {
margin-top: 1rem;
}