Skip to content

feat(calendar): create generic useCalendarList hook#39934

Open
VedantGupta-DTU wants to merge 1 commit intoRocketChat:developfrom
VedantGupta-DTU:feat/generic-useCalendarList-hook
Open

feat(calendar): create generic useCalendarList hook#39934
VedantGupta-DTU wants to merge 1 commit intoRocketChat:developfrom
VedantGupta-DTU:feat/generic-useCalendarList-hook

Conversation

@VedantGupta-DTU
Copy link
Copy Markdown

@VedantGupta-DTU VedantGupta-DTU commented Mar 28, 2026

Description

This PR extracts a generic useCalendarList hook from the Outlook-specific implementation, allowing any calendar integration (Google, CalDAV, Exchange, etc.) to reuse the same fundamental data-fetching logic.

Previously, useOutlookCalendarList was tightly coupled to Outlook views, despite the underlying /v1/calendar-events.list API endpoint being completely provider-agnostic.

By creating a generic useCalendarList base hook, we are establishing the architectural foundation required for the upcoming GSoC initiative to support multiple distinct calendar sources seamlessly.

Key Changes:

  • New Base Hook: Created apps/meteor/client/views/calendar/hooks/useCalendarList.ts containing the generic fetching logic.
  • Universal Cache Keys: Updated the React Query cache key from ['outlook', 'calendar', 'list'] to a provider-agnostic ['calendar', 'list', date]. This ensures that cache invalidations will work universally across all future integrated calendar sources.
  • Backward Compatibility: The original useOutlookCalendarList hooks have been refactored to act as thin, @deprecated delegates that simply call the new generic hook. This guarantees zero breaking changes to existing Outlook components (e.g., OutlookEventsList).
  • Sync Invalidation: Updated useMutationOutlookCalendarSync to correctly invalidate the new generic ['calendar', 'list'] cache key upon a successful background sync.

Related Issue

Aligns with the GSoC objective of creating modular, multi-source calendar support.

How to test

  1. Navigate to the Outlook Calendar view within the app UI.
  2. Ensure your Outlook calendar is authenticated and synced.
  3. Verify that calendar events for today continue to load and render correctly.
  4. Trigger a manual sync and verify the list updates correctly without errors (confirming the new cache invalidation keys work).

Summary by CodeRabbit

  • Refactor
    • Consolidated calendar event fetching logic to improve consistency across calendar integrations.
    • Updated Outlook calendar functionality to utilize shared calendar utilities; legacy Outlook-specific calendar hooks are now deprecated.

- Created apps/meteor/client/views/calendar/hooks/useCalendarList.ts
  with provider-agnostic useCalendarList(date) and useCalendarListForToday()
  hooks that call /v1/calendar-events.list endpoint directly
- Refactored useOutlookCalendarList to delegate to the generic hook
- Marked Outlook-specific wrappers as @deprecated
- Updated query keys from [outlook, calendar, list] to [calendar, list]
  so cache invalidation works across all calendar sources
- Aligns with GSoC goal of supporting multiple calendar integrations
@VedantGupta-DTU VedantGupta-DTU requested a review from a team as a code owner March 28, 2026 19:56
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Mar 28, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 28, 2026

⚠️ No Changeset found

Latest commit: d709dd5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

Walkthrough

A new shared calendar list hook module is created to centralize calendar event fetching logic. The Outlook-specific calendar hooks are refactored to delegate to the new shared hooks and marked as deprecated. Query cache invalidation key is harmonized across implementations.

Changes

Cohort / File(s) Summary
New Shared Calendar Hooks
apps/meteor/client/views/calendar/hooks/useCalendarList.ts
New module exporting useCalendarList(date) hook that fetches calendar events via useEndpoint and React Query, and useCalendarListForToday() convenience wrapper for current date.
Outlook-Specific Calendar Hooks
apps/meteor/client/views/outlookCalendar/hooks/useOutlookCalendarList.ts
Refactored hooks to delegate to shared useCalendarList hooks with @deprecated markers. Query invalidation key changed from ['outlook','calendar','list'] to ['calendar','list'].

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

type: feature

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: creating a generic, provider-agnostic useCalendarList hook extracted from the Outlook-specific implementation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@VedantGupta-DTU VedantGupta-DTU changed the title refractor : Extract generic useCalendarList hook (decouple from Outlook) feat: Extract generic useCalendarList hook (decouple from Outlook) Mar 28, 2026
@VedantGupta-DTU VedantGupta-DTU changed the title feat: Extract generic useCalendarList hook (decouple from Outlook) Refactor: Create generic useCalendarList hook for provider-agnostic calendar events Mar 28, 2026
@VedantGupta-DTU VedantGupta-DTU changed the title Refactor: Create generic useCalendarList hook for provider-agnostic calendar events feat(calendar): create generic useCalendarList hook Mar 28, 2026
@coderabbitai coderabbitai bot added the type: feature Pull requests that introduces new feature label Mar 28, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/meteor/client/views/calendar/hooks/useCalendarList.ts`:
- Around line 29-31: The hook useCalendarListForToday creates an unstable query
key by calling new Date() on every render; update it to memoize the Date (or a
date-only value) so the key remains stable across renders and only changes when
the calendar day changes. Modify useCalendarListForToday to compute a stable
"today" value (e.g., using React's useMemo to derive a Date representing the
current day or a YYYY-MM-DD string) and pass that memoized value into
useCalendarList instead of calling new Date() directly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c20d9cff-5e04-475a-8da2-f4b82e1d7764

📥 Commits

Reviewing files that changed from the base of the PR and between 4235cd9 and d709dd5.

📒 Files selected for processing (2)
  • apps/meteor/client/views/calendar/hooks/useCalendarList.ts
  • apps/meteor/client/views/outlookCalendar/hooks/useOutlookCalendarList.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/views/calendar/hooks/useCalendarList.ts
  • apps/meteor/client/views/outlookCalendar/hooks/useOutlookCalendarList.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: smirk-dev
Repo: RocketChat/Rocket.Chat PR: 39625
File: apps/meteor/app/api/server/v1/push.ts:85-97
Timestamp: 2026-03-14T14:58:58.834Z
Learning: In RocketChat/Rocket.Chat, the `push.token` POST/DELETE endpoints in `apps/meteor/app/api/server/v1/push.ts` were already migrated to the chained router API pattern on `develop` prior to PR `#39625`. `cleanTokenResult` (which strips `authToken` and returns `PushTokenResult`) and `isPushTokenPOSTProps`/`isPushTokenDELETEProps` validators already exist on `develop`. PR `#39625` only migrates `push.get` and `push.info` to the chained pattern. Do not flag `cleanTokenResult` or `PushTokenResult` as newly introduced behavior-breaking changes when reviewing this PR.
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/views/calendar/hooks/useCalendarList.ts
  • apps/meteor/client/views/outlookCalendar/hooks/useOutlookCalendarList.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/client/views/calendar/hooks/useCalendarList.ts
  • apps/meteor/client/views/outlookCalendar/hooks/useOutlookCalendarList.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/client/views/calendar/hooks/useCalendarList.ts
  • apps/meteor/client/views/outlookCalendar/hooks/useOutlookCalendarList.ts
🔇 Additional comments (3)
apps/meteor/client/views/calendar/hooks/useCalendarList.ts (1)

13-24: LGTM!

The generic hook implementation correctly uses the date parameter in both the query key and request, ensuring proper cache isolation per date.

apps/meteor/client/views/outlookCalendar/hooks/useOutlookCalendarList.ts (2)

8-22: LGTM!

The deprecated wrappers correctly delegate to the shared hooks while maintaining backward compatibility. The @deprecated annotations with migration guidance are appropriate.


36-38: LGTM!

The cache invalidation key change from ['outlook', 'calendar', 'list'] to ['calendar', 'list'] correctly aligns with the new provider-agnostic query key structure. The partial key match will invalidate all date-specific calendar queries, which is the intended behavior for refreshing the unified calendar view after sync.

Comment on lines +29 to +31
export const useCalendarListForToday = () => {
return useCalendarList(new Date());
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Unstable query key due to new Date() called on every render.

new Date() generates a different timestamp (including milliseconds) on each render, producing a different toISOString() value for the query key. This causes React Query to treat every render as a new query, leading to cache misses and potential excessive API calls.

Memoize the date to ensure stability across renders:

🐛 Proposed fix using useMemo
+import { useMemo } from 'react';
+
+const getStartOfDay = (date: Date) => {
+	const start = new Date(date);
+	start.setHours(0, 0, 0, 0);
+	return start;
+};
+
 export const useCalendarListForToday = () => {
-	return useCalendarList(new Date());
+	const today = useMemo(() => getStartOfDay(new Date()), []);
+	return useCalendarList(today);
 };

Alternatively, if the date should update when the calendar day changes (e.g., app open past midnight), consider a more sophisticated approach that only changes when the calendar day itself changes.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const useCalendarListForToday = () => {
return useCalendarList(new Date());
};
import { useMemo } from 'react';
const getStartOfDay = (date: Date) => {
const start = new Date(date);
start.setHours(0, 0, 0, 0);
return start;
};
export const useCalendarListForToday = () => {
const today = useMemo(() => getStartOfDay(new Date()), []);
return useCalendarList(today);
};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/client/views/calendar/hooks/useCalendarList.ts` around lines 29 -
31, The hook useCalendarListForToday creates an unstable query key by calling
new Date() on every render; update it to memoize the Date (or a date-only value)
so the key remains stable across renders and only changes when the calendar day
changes. Modify useCalendarListForToday to compute a stable "today" value (e.g.,
using React's useMemo to derive a Date representing the current day or a
YYYY-MM-DD string) and pass that memoized value into useCalendarList instead of
calling new Date() directly.

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

Labels

community type: feature Pull requests that introduces new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant