Skip to content

Conversation

@pujitm
Copy link
Member

@pujitm pujitm commented Nov 20, 2024

fixes a bug where infinite scroll wouldn't trigger after it stopped, even when changing filters.

Summary by CodeRabbit

  • New Features

    • Enhanced loading functionality for notifications, allowing for better management of loading states.
    • Introduced a mechanism to prevent loading more notifications when none are available.
  • Bug Fixes

    • Improved error handling during notification fetching, with logging for better visibility.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

The changes in the List.vue component enhance the loading functionality for notifications. A new reactive reference, canLoadMore, is introduced to manage the loading state based on the number of notifications fetched. The onLoadMore function is updated to prevent further loading attempts when no new notifications are available. Additionally, watchers are added to reset the loading state on prop changes and to log errors during the fetching process. These updates improve the component's responsiveness to state changes and error handling.

Changes

File Change Summary
web/components/Notifications/List.vue - Added const canLoadMore = ref(true) for loading state management.
- Introduced watcher to reset canLoadMore on prop changes.
- Added watcher to log errors from useQuery.
- Updated onLoadMore to set canLoadMore to false if no new notifications are fetched.

Poem

In the meadow where notifications bloom,
A rabbit hops, dispelling the gloom.
With canLoadMore, we dance and play,
Fetching new tidings, come what may!
Errors logged, we leap with glee,
For every change brings joy to me! 🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pujitm pujitm requested review from elibosley and mdatelle November 20, 2024 17:21
@github-actions
Copy link
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL: https://preview.dl.unraid.net/unraid-api/pr/966/dynamix.unraid.net.staging.plg

Copy link
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: 0

🧹 Outside diff range and nitpick comments (4)
web/components/Notifications/List.vue (4)

27-29: Consider making the watcher more specific to filter changes

The current watcher resets canLoadMore on any prop change, including pageSize. Consider watching only the filter-related props to avoid unnecessary resets.

-watch(props, () => {
+watch([() => props.type, () => props.importance], () => {
   canLoadMore.value = true;
 });

Line range hint 38-40: Enhance error handling for better user experience

While error logging is implemented, the UI doesn't reflect error states. Consider showing an error message to users when loading fails.

+const showError = ref(false);
+
 watch(error, (newVal) => {
   console.log('[getNotifications] error:', newVal);
+  if (newVal) {
+    showError.value = true;
+    canLoadMore.value = false;
+  }
 });

And in the template:

   <div
     v-if="notifications?.length > 0"
     v-infinite-scroll="[onLoadMore, { canLoadMore: () => canLoadMore }]"
     class="divide-y divide-gray-200 overflow-y-auto pl-7 pr-4 h-full"
   >
+    <div v-if="showError" class="text-red-600 p-2 text-center">
+      Failed to load more notifications. Please try again later.
+    </div>
     <NotificationsItem

Line range hint 52-64: Add loading state to prevent duplicate requests

The current implementation might trigger multiple simultaneous requests if the user scrolls quickly while a request is in progress.

+const isLoading = ref(false);
+
 async function onLoadMore() {
+  if (isLoading.value) return;
   console.log('[getNotifications] onLoadMore');
+  isLoading.value = true;
+  try {
     const incoming = await fetchMore({
       variables: {
         filter: {
           offset: notifications.value.length,
           limit: props.pageSize,
           type: props.type,
           importance: props.importance,
         },
       },
     });
     const incomingCount = incoming?.data.notifications.list.length ?? 0;
     if (incomingCount === 0 || incomingCount < props.pageSize) {
       canLoadMore.value = false;
     }
+  } finally {
+    isLoading.value = false;
+  }
 }

Line range hint 76-77: Add loading indicator for better user feedback

Consider adding a loading indicator to show when more notifications are being fetched.

   <div
     v-if="notifications?.length > 0"
     v-infinite-scroll="[onLoadMore, { canLoadMore: () => canLoadMore }]"
     class="divide-y divide-gray-200 overflow-y-auto pl-7 pr-4 h-full"
   >
     <NotificationsItem
       v-for="notification in notifications"
       :key="notification.id"
       v-bind="notification"
     />
+    <div v-if="isLoading" class="py-2 text-center text-gray-500">
+      Loading more notifications...
+    </div>
   </div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e9f2fc4 and 62afba6.

📒 Files selected for processing (1)
  • web/components/Notifications/List.vue (1 hunks)
🔇 Additional comments (1)
web/components/Notifications/List.vue (1)

24-26: LGTM: Well-documented state management

The new canLoadMore ref is appropriately named and documented, clearly indicating its purpose in controlling the infinite scroll behavior.

@pujitm pujitm merged commit da6de2c into main Nov 21, 2024
9 checks passed
@pujitm pujitm deleted the fix/notif-scroll branch November 21, 2024 13:55
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.

3 participants