-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bba8e36
commit 50eb658
Showing
7 changed files
with
170 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,5 +29,8 @@ VALUES | |
('8Sy7xBkGiGQv4ZKphcQfY8PxAqw1', 'Narayan', 'Sharma', '[email protected]', '', ''), | ||
('iL7PnjS4axQffmlPceobjUUZ9DF2', 'Caitlin', 'Flynn', '[email protected]', '', ''), | ||
('5JgN2PQxCRM9VoCiiFPlQPNqkL32', 'Linwood', 'Blaisdell', '[email protected]', '', '') | ||
('9rIMSUo6qNf8ToTABkCfNqnByRv1', 'Haley', 'Martin', '[email protected]', '', '') | ||
|
||
|
||
-- End Care-Wallet Team | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import React, { useState } from 'react'; | ||
import { Alert } from 'react-native'; | ||
import _ from 'lodash'; | ||
import { | ||
CalendarProvider, | ||
CalendarUtils, | ||
DateData, | ||
ExpandableCalendar, | ||
TimelineEventProps, | ||
TimelineList, | ||
TimelineProps, | ||
} from 'react-native-calendars'; | ||
import { getDate, timelineEvents } from './timelineEvents'; | ||
|
||
|
||
const INITIAL_TIME = { hour: 9, minutes: 0 }; | ||
const EVENTS: TimelineEventProps[] = timelineEvents; | ||
|
||
const TimelineCalendarScreen: React.FC = () => { | ||
const [currentDate, setCurrentDate] = useState(getDate()); | ||
const [eventsByDate, setEventsByDate] = useState(_.groupBy(EVENTS, (e) => CalendarUtils.getCalendarDateString(e.start))); | ||
Check failure on line 21 in client/screens/Calendar3.0.tsx GitHub Actions / Lint (20.x, 1.21.x)
|
||
|
||
const marked = { | ||
[`${getDate(-1)}`]: { marked: true }, | ||
[`${getDate()}`]: { marked: true }, | ||
[`${getDate(1)}`]: { marked: true }, | ||
[`${getDate(2)}`]: { marked: true }, | ||
[`${getDate(4)}`]: { marked: true }, | ||
}; | ||
|
||
const onDateChanged = (date: string, source: string) => { | ||
console.log('TimelineCalendarScreen onDateChanged: ', date, source); | ||
setCurrentDate(date); | ||
}; | ||
|
||
const onMonthChange = (month: DateData, updateSource: any) => { | ||
console.log('TimelineCalendarScreen onMonthChange: ', month, updateSource); | ||
}; | ||
|
||
const createNewEvent: TimelineProps['onBackgroundLongPress'] = ( | ||
timeString, | ||
timeObject | ||
) => { | ||
const hourString = `${(timeObject.hour + 1).toString().padStart(2, '0')}`; | ||
const minutesString = `${timeObject.minutes.toString().padStart(2, '0')}`; | ||
|
||
const newEvent = { | ||
id: 'draft', | ||
start: `${timeString}`, | ||
end: `${timeObject.date} ${hourString}:${minutesString}:00`, | ||
title: 'New Event', | ||
color: 'white', | ||
}; | ||
|
||
if (timeObject.date) { | ||
if (eventsByDate[timeObject.date]) { | ||
setEventsByDate((prevEvents) => ({ | ||
...prevEvents, | ||
[timeObject.date as string]: [...prevEvents[timeObject.date as string], newEvent], | ||
})); | ||
} else { | ||
setEventsByDate((prevEvents) => ({ | ||
...prevEvents, | ||
[timeObject.date as string]: [newEvent], | ||
})); | ||
} | ||
} | ||
}; | ||
|
||
const approveNewEvent: TimelineProps['onBackgroundLongPressOut'] = ( | ||
_timeString, | ||
timeObject | ||
) => { | ||
Alert.prompt('New Event', 'Enter event title', [ | ||
{ | ||
text: 'Cancel', | ||
onPress: () => { | ||
if (timeObject.date) { | ||
setEventsByDate((prevEvents) => ({ | ||
...prevEvents, | ||
[timeObject.date as string]: _.filter( | ||
prevEvents[timeObject.date as string], | ||
(e) => e.id !== 'draft' | ||
), | ||
})); | ||
} | ||
}, | ||
}, | ||
{ | ||
text: 'Create', | ||
onPress: (eventTitle) => { | ||
if (timeObject.date) { | ||
const draftEvent = _.find(eventsByDate[timeObject.date], { | ||
id: 'draft', | ||
}); | ||
if (draftEvent) { | ||
draftEvent.id = undefined; | ||
draftEvent.title = eventTitle ?? 'New Event'; | ||
draftEvent.color = 'lightgreen'; | ||
setEventsByDate((prevEvents) => ({ | ||
...prevEvents, | ||
[timeObject.date as string]: [...prevEvents[timeObject.date as string]], | ||
})); | ||
} | ||
} | ||
}, | ||
}, | ||
]); | ||
}; | ||
|
||
const timelineProps: Partial<TimelineProps> = { | ||
format24h: false, | ||
onBackgroundLongPress: createNewEvent, | ||
onBackgroundLongPressOut: approveNewEvent, | ||
unavailableHours: [ | ||
{ start: 0, end: 6 }, | ||
{ start: 22, end: 24 }, | ||
], | ||
onEventPress: (e) => expandEvent(e), | ||
overlapEventsSpacing: 8, | ||
rightEdgeSpacing: 24, | ||
}; | ||
|
||
return ( | ||
<CalendarProvider | ||
date={currentDate} | ||
onDateChanged={onDateChanged} | ||
onMonthChange={onMonthChange} | ||
showTodayButton | ||
disabledOpacity={0.6} | ||
> | ||
<ExpandableCalendar firstDay={1} markedDates={marked} /> | ||
<TimelineList | ||
events={eventsByDate} | ||
timelineProps={timelineProps} | ||
showNowIndicator | ||
scrollToFirst | ||
initialTime={INITIAL_TIME} | ||
/> | ||
</CalendarProvider> | ||
); | ||
}; | ||
|
||
function expandEvent(e: TimelineEventProps): void { | ||
console.log('expand event', e.title); | ||
} | ||
|
||
export default TimelineCalendarScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"devDependencies": { | ||
"@types/node": "^20.11.25" | ||
} | ||
} |