Skip to content

Conversation

@himynameismoose
Copy link
Collaborator

@himynameismoose himynameismoose commented Aug 31, 2025

Description

Issue #628: Added a button to the Calendar UI for users to subscribe to by adding the Together calendar to their personal calendar.

Dependencies added:
"ics": "^3.8.1"

Type of change

Please select everything applicable. Please, do not delete any lines.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • This change requires an update to testing

Issue

Checklist:

  • This PR is up to date with the main branch, and merge conflicts have been resolved
  • I have executed npm run test and npm run test:e2e and all tests have passed successfully or I have included details within my PR on the failure.
Screenshot 2025-08-31 at 11 14 09 AM Screenshot 2025-08-31 at 11 19 36 AM
  • I have executed npm run lint and resolved any outstanding errors. Most issues can be solved by executing npm run format
Screenshot 2025-08-31 at 11 40 08 AM
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings


module.exports = (app) => {
app.get("/calendar.ics", async (req, res) => {
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly sure how testing goes in this project, but I think it'd be good to write a test to make sure the ICS file is generated appropriately

Glad to help out on approach if you'd like!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, and I agree that writing a test for this is important.

I'll add a server-side test that will make a GET request to the /calendar.ics endpoint and verify that the response status is 200, as well as that the Content-Type header is set to "text/calendar".

Would this be a good starting ground?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Once you get that working, you can also check things like the filename and that the appropriate events are included in the ICS file!

It seems ics is for generating ics files and not parsing them, so you may need to include a dev dependency to validate or consider a library that does both

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've attempted to write tests for my calendar.test.js. I ran npm test and all tests passed. However, I've had to make some changes to some other files under the test directory, along with my calendar.js route file. I am a bit wary of this result since there are errors generating in the console even though the tests all pass. Could I have a moment of your time to look through my new changes before I even consider committing?

@himynameismoose himynameismoose force-pushed the feature/issue-628 branch 2 times, most recently from bd645bf to be2e602 Compare August 31, 2025 21:05
const ics = require("ics");
const Event = require("../models/Event");

const createDateArray = (date) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have date-fns available we can use it, similar to what they used in the docs with moment (source).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made changes to import the format function from date-fns and will be included in my next commit.

// use createDateArray helper function
start: createDateArray(startDate),
end: createDateArray(endDate),
url: `https://together.rocks/events/${event._id}`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL /events/:id does not work at the moment. Should we just send back the users to the /calendar page in the mean time?

Copy link
Collaborator

@DevinCLane DevinCLane Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, hopefully we will get this behavior with #618

Copy link
Collaborator Author

@himynameismoose himynameismoose Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made changes to the url to send users to /calendar and will be included in my next commit.

app.get("/calendar.ics", async (req, res) => {
try {
// fetch events from mongodb
const eventsFromDB = await Event.find().lean();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an user perspective, does it make sense to include all the events from the database?

We can proceed with this as the first iteration, but it's worth discussing for a future improvement.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this include past events as well? maybe we at least filter for events after the current date

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i did not take this into consideration! thanks for the suggestion. i'll put it on the back-burner for now and prioritize the .ics creation.

// use createDateArray helper function
start: createDateArray(startDate),
end: createDateArray(endDate),
url: `https://together.rocks/events/${event._id}`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non blocker, but on the long run we need to think about together.rocks being hardcoded (tests, preview PR, change of domain, etc), same for the other <a> link in the client.

const eventsFromDB = await Event.find().lean();
// format events for the ics library
const icsEvents = eventsFromDB.map((event) => {
const startDate = event.startAt;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not destructure the whole object?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have refactored the map function to use object destructuring. i will include these changes in my next commit

@DevinCLane
Copy link
Collaborator

super good overall and thank you for the contribution @himynameismoose, welcome in!

@himynameismoose himynameismoose changed the title Feature/issue 628 Users can subscribe to the calendar Sep 22, 2025
@himynameismoose
Copy link
Collaborator Author

srpt3.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Users can subscribe to the calendar

4 participants