-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React cal poc kl #85
Merged
Merged
React cal poc kl #85
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
87b033e
calender test
79ea581
current work 9/27
a5920d1
cal-dates-working
034ef56
proof of concept handoff
mmcbride2929 85e5590
Replace displayedEvent, setDisplayedEvent with computed value, displa…
KVinyl cdb6db5
Modify weekend text color to be white when selected or has event
KVinyl 9684663
Rename custom-tile to event-tile
KVinyl ed8a98e
Move calendar and displayed events in flex row and modify calendar he…
KVinyl 5ca8203
Add vertical scrollbar if multiple events in a day
KVinyl 932d212
Fix merge conflicts
KVinyl 344f921
Remove console.log and console.error statements
KVinyl 5544cb7
Fix vulnerabilities without breaking changes with npm audit
KVinyl fa4305e
Add unique key to rendered Event array children
KVinyl 6197477
Fix Event.propTypes shape
KVinyl 6fd930b
Refactor getEventData by adding initialSelectedDate helper function
KVinyl 424a2a4
Fix event prop value in Event test and update Event and Events snapshots
KVinyl dd2e133
Modify initialSelectedDate function from linear search to binary search
KVinyl b533cdb
Add hover styling to calendar active tile
KVinyl f5c0595
Change formattedEventDates in Calendar from array to set
KVinyl 1a9ca18
Change active tile hover color to same color in active tile
KVinyl fdc7edc
Move initialSelectDate function to different useEffect hook and add e…
KVinyl d968ed2
Remove redundant changeDate function
KVinyl 0462d69
Add locale and minDetail props to Calendar
KVinyl d51040f
Add loaded state variable
KVinyl c72dee0
Replace with eventDateTimeSet with eventsByDateString and modify disp…
KVinyl bafe9f7
Refactor and memoize tileClassName function
KVinyl e7b5a83
Add useEvents hook
KVinyl 08fe94e
Add useCalendar hook
KVinyl 3426411
Specify event-info width and overflow-wrap
KVinyl 095c0ed
Fix events conditional rendering condition
KVinyl 089b696
Minor code formatting
KVinyl dd7ab07
Add nearestFutureEventDate helper function
KVinyl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,21 +1,26 @@ | ||
import PropTypes from "prop-types"; | ||
import PropTypes from 'prop-types'; | ||
|
||
function Event({ event }) { | ||
// add id to event | ||
// const href = `/coding-${id + 1}.jpg` | ||
const formattedDateTime = new Intl.DateTimeFormat('en-US', { | ||
dateStyle: 'medium', | ||
timeStyle: 'short', | ||
}).format(event.dtstart.value); | ||
|
||
function Event({ event, id }) { | ||
const href = `/coding-${id + 1}.jpg` | ||
const formattedDateTime = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'short' }).format(event.time); | ||
/* | ||
We replace the "narrow non-breaking space" that appears before the AM/PM in some environments | ||
with a regular space to help prevent snapshot test failures. | ||
fwiw, it appears that this is a somewhat recent change in Node: https://www.reddit.com/r/webdev/comments/1054ve6/psa_node_1813_changed_datetime_formatting/ | ||
- [email protected], 2023 May 22 | ||
*/ | ||
const replacedNonBreakingSpace = formattedDateTime.replace(/\u202f/g, ' '); | ||
|
||
return ( | ||
<div className="event"> | ||
<img src={href} alt='people coding' className="event-img" /> | ||
<div className="info"> | ||
<h5>{event.name}</h5> | ||
{/* <img src={href} alt='people coding' className="event-img" /> */} | ||
<div className="event-info"> | ||
<h5>{event.summary.value}</h5> | ||
<table> | ||
<tbody> | ||
<tr> | ||
|
@@ -24,25 +29,34 @@ function Event({ event, id }) { | |
</tr> | ||
<tr> | ||
<th>location:</th> | ||
<td>{event.location}</td> | ||
{event.location && <td>{event.location.value}</td>} | ||
</tr> | ||
</tbody> | ||
</table> | ||
<p>{event.description}</p> | ||
<p>{event.description.value}</p> | ||
<div className="meet-up-register"> | ||
<a | ||
target="_blank" | ||
rel="noreferrer" | ||
href="https://www.meetup.com/register/" | ||
> | ||
Join Meetup.com | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
); | ||
} | ||
|
||
Event.propTypes = { | ||
event: PropTypes.shape({ | ||
name: PropTypes.string.isRequired, | ||
description: PropTypes.string.isRequired, | ||
time: PropTypes.objectOf(Date), | ||
location : PropTypes.string.isRequired, | ||
id : PropTypes.string.isRequired, | ||
summary: PropTypes.objectOf(PropTypes.string.isRequired), | ||
description: PropTypes.objectOf(PropTypes.string.isRequired), | ||
dtstart: PropTypes.objectOf(Date), | ||
location: PropTypes.objectOf(PropTypes.string.isRequired), | ||
uid: PropTypes.objectOf(PropTypes.string.isRequired), | ||
url: PropTypes.objectOf(PropTypes.string.isRequired), | ||
}).isRequired, | ||
id: PropTypes.number.isRequired, | ||
}; | ||
|
||
export default Event | ||
export default Event; |
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,86 @@ | ||
import { useState, useEffect, useMemo, useCallback } from 'react'; | ||
|
||
const useCalendar = (events) => { | ||
const [selectedDate, setSelectedDate] = useState(new Date()); | ||
|
||
const dateOnly = (date) => | ||
new Date(date.getFullYear(), date.getMonth(), date.getDate()); | ||
|
||
const eventsByDateString = useMemo(() => { | ||
// Key: date string of date object | ||
// Value: Array of event objects | ||
const eventsDict = {}; | ||
events.forEach((event) => { | ||
const dateString = event.dtstart.value.toDateString(); | ||
if (!eventsDict[dateString]) { | ||
eventsDict[dateString] = []; | ||
} | ||
eventsDict[dateString].push(event); | ||
}); | ||
return eventsDict; | ||
}, [events]); | ||
|
||
const displayedEvents = useMemo( | ||
() => eventsByDateString[selectedDate.toDateString()] ?? [], | ||
[eventsByDateString, selectedDate] | ||
); | ||
|
||
useEffect(() => { | ||
const nearestFutureEventDate = (currentDate) => { | ||
// Binary search for nearest future date with an event | ||
// when there's no event today. | ||
// Assumes events is sorted chronologically. | ||
|
||
let left = 0; | ||
let right = events.length - 1; | ||
while (left < right) { | ||
const mid = Math.floor((left + right) / 2); | ||
const midDate = dateOnly(events[mid].dtstart.value); | ||
|
||
if (midDate.getTime() > currentDate.getTime()) { | ||
right = mid; | ||
} else { | ||
left = mid + 1; | ||
} | ||
} | ||
return dateOnly(events[left].dtstart.value); | ||
}; | ||
|
||
const initialSelectedDate = () => { | ||
// Returns today's date if there is an event. | ||
// If not, returns the nearest future date with an event. | ||
// If no future events, returns the last date with an event. | ||
|
||
const currentDate = dateOnly(new Date()); | ||
|
||
if (events.length === 0) { | ||
return currentDate; | ||
} | ||
// Check if today's date has an event | ||
if (eventsByDateString[currentDate.toDateString()]) { | ||
return currentDate; | ||
} | ||
|
||
// Check if today's date is after the last event date | ||
const lastEventDate = dateOnly(events[events.length - 1].dtstart.value); | ||
if (lastEventDate.getTime() < currentDate.getTime()) { | ||
return lastEventDate; | ||
} | ||
|
||
return nearestFutureEventDate(currentDate); | ||
}; | ||
setSelectedDate(initialSelectedDate()); | ||
}, [events, eventsByDateString]); | ||
|
||
const tileClassName = useCallback( | ||
({ date, view }) => | ||
view === 'month' && eventsByDateString[date.toDateString()] | ||
? 'event-tile' | ||
: '', | ||
[eventsByDateString] | ||
); | ||
|
||
return { selectedDate, setSelectedDate, displayedEvents, tileClassName }; | ||
}; | ||
|
||
export default useCalendar; |
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,38 @@ | ||
import { useState, useEffect } from 'react'; | ||
import ical from 'cal-parser'; | ||
|
||
const useEvents = () => { | ||
const [events, setEvents] = useState([]); | ||
|
||
const fetchData = async () => { | ||
try { | ||
const response = await fetch( | ||
'https://docs.google.com/document/d/1OcnWWt1qHaJWE-8v_FPtNO8DKviRQ7DMaqylupuvPXE/export?format=txt' | ||
); | ||
|
||
const content = await response.text(); | ||
return content; | ||
} catch (error) { | ||
return null; | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
const eventsData = async () => { | ||
try { | ||
const fetchedData = await fetchData(); | ||
const parsedData = ical.parseString(fetchedData); | ||
return parsedData.events; | ||
} catch (error) { | ||
return []; | ||
} | ||
}; | ||
eventsData().then((data) => { | ||
setEvents(data); | ||
}); | ||
}, []); | ||
|
||
return { events }; | ||
}; | ||
|
||
export default useEvents; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will create another backlog item to make this value configurable. It's outside the scope of this backlog item.