Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(async () => {
const { status } = await Calendar.requestPermissionsAsync();
if (status === 'granted') {
const calendars = await Calendar.getCalendarsAsync();
console.log({ calendars });
}
})();
}, []);
cal => cal.accessLevel === Calendar.CalendarAccessLevel.OWNER
).source.name,
? this.state.calendars.find(cal => cal.accessLevel === Calendar.CalendarAccessLevel.OWNER)
.ownerAccount
_addCalendar = async () => {
const newCalendar = {
title: 'cool new calendar',
entityType: Calendar.EntityTypes.EVENT,
color: '#c0ff33',
sourceId:
Platform.OS === 'ios'
? this.state.calendars.find(cal => cal.source && cal.source.name === 'Default').source.id
: undefined,
source:
Platform.OS === 'android'
? {
name: this.state.calendars.find(
cal => cal.accessLevel === Calendar.CalendarAccessLevel.OWNER
).source.name,
isLocalAccount: true,
}
: undefined,
name: 'coolNewCalendar',
accessLevel: Calendar.CalendarAccessLevel.OWNER,
> = props => {
const { calendar } = props;
const calendarTypeName =
calendar.entityType === Calendar.EntityTypes.REMINDER ? 'Reminders' : 'Events';
return (
_findCalendars = async () => {
const calendarGranted = await this._askForCalendarPermissions();
const reminderGranted = await this._askForReminderPermissions();
if (calendarGranted && reminderGranted) {
const eventCalendars = (await Calendar.getCalendarsAsync('event')) as unknown as any[];
const reminderCalendars =
(Platform.OS === 'ios' ? await Calendar.getCalendarsAsync('reminder') : []) as any[];
this.setState({ calendars: [...eventCalendars, ...reminderCalendars] });
}
}
_findCalendars = async () => {
const calendarGranted = await this._askForCalendarPermissions();
const reminderGranted = await this._askForReminderPermissions();
if (calendarGranted && reminderGranted) {
const eventCalendars = (await Calendar.getCalendarsAsync('event')) as unknown as any[];
const reminderCalendars =
(Platform.OS === 'ios' ? await Calendar.getCalendarsAsync('reminder') : []) as any[];
this.setState({ calendars: [...eventCalendars, ...reminderCalendars] });
}
}
name: this.state.calendars.find(
cal => cal.accessLevel === Calendar.CalendarAccessLevel.OWNER
).source.name,
isLocalAccount: true,
}
: undefined,
name: 'coolNewCalendar',
accessLevel: Calendar.CalendarAccessLevel.OWNER,
ownerAccount:
Platform.OS === 'android'
? this.state.calendars.find(cal => cal.accessLevel === Calendar.CalendarAccessLevel.OWNER)
.ownerAccount
: undefined,
};
try {
await Calendar.createCalendarAsync(newCalendar);
Alert.alert('Calendar saved successfully');
this._findCalendars();
} catch (e) {
Alert.alert('Calendar not saved successfully', e.message);
}
}
} = {
title: 'Celebrate Expo',
location: '420 Florence St',
startDate: new Date(),
endDate: timeInOneHour,
notes: 'It\'s cool',
timeZone: 'America/Los_Angeles',
};
if (recurring) {
newEvent.recurrenceRule = {
occurrence: 5,
frequency: 'daily',
};
}
try {
await Calendar.createEventAsync(calendar.id, newEvent as any);
Alert.alert('Event saved successfully');
this._findEvents(calendar.id);
} catch (e) {
Alert.alert('Event not saved successfully', e.message);
}
}
const { calendar } = this.props.navigation.state.params!;
if (!calendar.allowsModifications) {
Alert.alert('This calendar does not allow modifications');
return;
}
const timeInOneHour = new Date();
timeInOneHour.setHours(timeInOneHour.getHours() + 1);
const newReminder = {
title: 'do something cool w/ expo',
location: '420 Florence St',
startDate: new Date(),
dueDate: timeInOneHour,
notes: 'where do these notes show up',
};
try {
await Calendar.createReminderAsync(calendar.id!, newReminder);
Alert.alert('Reminder saved successfully');
this._findReminders(calendar.id!);
} catch (e) {
Alert.alert('Reminder not saved successfully', e.message);
}
}