Skip to content
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

Add loading indicator when loading more transactions in mobile transaction list #3900

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

joel-jeremy
Copy link
Contributor

No description provided.

@actual-github-bot actual-github-bot bot changed the title Add isLoadingMore property to useTransactions hook [WIP] Add isLoadingMore property to useTransactions hook Nov 26, 2024
Copy link

netlify bot commented Nov 26, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 5d04092
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67451637166bd500090b10ac
😎 Deploy Preview https://deploy-preview-3900.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@joel-jeremy joel-jeremy changed the title [WIP] Add isLoadingMore property to useTransactions hook Add Loading more transactions indicator on mobile transactions page Nov 26, 2024
@joel-jeremy joel-jeremy changed the title Add Loading more transactions indicator on mobile transactions page Add "Loading more transactions..." indicator on mobile transactions page Nov 26, 2024
Copy link
Contributor

github-actions bot commented Nov 26, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
10 5.45 MB → 5.45 MB (+1008 B) +0.02%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/client/data-hooks/transactions.ts 📈 +390 B (+8.96%) 4.25 kB → 4.63 kB
src/components/mobile/transactions/TransactionList.jsx 📈 +512 B (+3.23%) 15.5 kB → 16 kB
src/components/mobile/budget/CategoryTransactions.jsx 📈 +34 B (+1.16%) 2.86 kB → 2.89 kB
src/components/mobile/transactions/TransactionListWithBalances.jsx 📈 +40 B (+0.74%) 5.29 kB → 5.33 kB
src/components/mobile/accounts/AccountTransactions.tsx 📈 +32 B (+0.42%) 7.43 kB → 7.46 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 3.44 MB → 3.44 MB (+976 B) +0.03%
static/js/narrow.js 82.93 kB → 82.96 kB (+32 B) +0.04%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/useAccountPreviewTransactions.js 1.68 kB 0%
static/js/AppliedFilters.js 21.32 kB 0%
static/js/wide.js 241.19 kB 0%
static/js/ReportRouter.js 1.52 MB 0%

Copy link
Contributor

github-actions bot commented Nov 26, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.32 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.32 MB 0%

@joel-jeremy joel-jeremy changed the title Add "Loading more transactions..." indicator on mobile transactions page Add loading indicator when loading more transactions in mobile transaction list. Nov 26, 2024
@joel-jeremy joel-jeremy changed the title Add loading indicator when loading more transactions in mobile transaction list. Add loading indicator when loading more transactions in mobile transaction list Nov 26, 2024
Copy link
Contributor

coderabbitai bot commented Nov 26, 2024

Walkthrough

The pull request introduces several enhancements across multiple components related to transaction handling in the desktop client application. Key changes include the addition of a new state variable isLoadingMore to track the loading status of additional transactions in components such as AccountTransactions, CategoryTransactions, and TransactionList. The loadMoreTransactions function is implemented to facilitate loading more transactions as needed. The reloadTransactions function call is updated to ensure it executes directly, simplifying the logic. The TransactionList component has been modified to include a new Loading functional component for better management of loading states, while also improving accessibility with translated aria-labels. The TransactionListWithBalances component is updated to accept the isLoadingMore prop, enhancing its ability to manage loading states effectively. Additionally, modifications to the useTransactions hook ensure that isLoading and reload properties are now required, and a new isLoadingMore property is added to improve transaction loading management.

Possibly related PRs

Suggested labels

:sparkles: Merged, :white_check_mark: Approved

Suggested reviewers

  • youngcw
  • matt-fidd

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/desktop-client/src/components/mobile/transactions/TransactionList.jsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eslint-plugin".

(The package "eslint-plugin-eslint-plugin" was not found when loaded as a Node module from the directory "/packages/eslint-plugin-actual".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eslint-plugin@latest --save-dev

The plugin "eslint-plugin-eslint-plugin" was referenced from the config file in "packages/eslint-plugin-actual/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ea2eced and 5d04092.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3900.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • packages/desktop-client/src/components/mobile/transactions/TransactionList.jsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/mobile/transactions/TransactionList.jsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.

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 (6)
packages/desktop-client/src/components/mobile/budget/CategoryTransactions.jsx (1)

116-118: Consider enhancing accessibility for loading states.

While the loading state implementation is correct, consider adding ARIA attributes to improve accessibility when loading more transactions.

 <TransactionListWithBalances
   isLoading={isLoading}
   transactions={transactions}
   balance={balance}
   balanceCleared={balanceCleared}
   balanceUncleared={balanceUncleared}
   searchPlaceholder={`Search ${category.name}`}
   onSearch={onSearch}
   isLoadingMore={isLoadingMore}
+  aria-busy={isLoadingMore}
+  aria-live="polite"
   onLoadMore={loadMoreTransactions}
   onOpenTransaction={onOpenTransaction}
 />
packages/loot-core/src/client/data-hooks/transactions.ts (1)

93-106: Consider enhancing error handling in loadMore.

While the error handling is functional, consider adding error type information and potentially handling specific error cases differently.

-  const loadMore = useCallback(async () => {
+  const loadMore = useCallback(async () => {
     if (!pagedQueryRef.current) {
       return;
     }
 
     setIsLoadingMore(true);
 
     await pagedQueryRef.current
       .fetchNext()
-      .catch(setError)
+      .catch((error: Error) => {
+        // Handle specific error cases if needed
+        if (error instanceof NetworkError) {
+          setError(new Error('Failed to load more transactions. Please check your connection.'));
+        } else {
+          setError(error);
+        }
+      })
       .finally(() => {
         setIsLoadingMore(false);
       });
   }, []);
packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx (1)

237-238: LGTM! Consider adding type annotations.

The addition of isLoadingMore and loadMoreTransactions props aligns well with the PR objective. Consider adding explicit type annotations for better maintainability.

-    isLoadingMore,
-    loadMore: loadMoreTransactions,
+    isLoadingMore: boolean,
+    loadMore: loadMoreTransactions: () => Promise<void>,
packages/desktop-client/src/components/mobile/transactions/TransactionList.jsx (3)

43-58: Well-structured Loading component with good accessibility!

The Loading component is well-implemented with proper accessibility support and styling flexibility. Consider adding PropTypes or TypeScript for better type safety.

Loading.propTypes = {
  style: PropTypes.object,
  'aria-label': PropTypes.string
};

171-181: Well-implemented loading indicator with good UX considerations!

The loading indicator is properly implemented with matching height for visual consistency. Consider adding a loading threshold to prevent flickering for quick loads.

-      {isLoadingMore && (
+      {isLoadingMore && transactions.length > 0 && (

Line range hint 102-108: Consider enhancing scroll listener implementation

The scroll listener implementation could benefit from:

  1. Debouncing to prevent multiple rapid calls
  2. Error handling for failed load attempts
  3. Loading state guard to prevent multiple simultaneous loads
+ const [isError, setIsError] = useState(false);
+ const debouncedLoadMore = useCallback(
+   debounce(() => {
+     if (!isLoadingMore && !isError) {
+       onLoadMore?.().catch(() => setIsError(true));
+     }
+   }, 250),
+   [isLoadingMore, isError, onLoadMore]
+ );

  useScrollListener(({ hasScrolledToEnd }) => {
    if (hasScrolledToEnd('down', 5)) {
-     onLoadMore?.();
+     debouncedLoadMore();
    }
  });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c25e3d4 and ea2eced.

📒 Files selected for processing (5)
  • packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx (3 hunks)
  • packages/desktop-client/src/components/mobile/budget/CategoryTransactions.jsx (3 hunks)
  • packages/desktop-client/src/components/mobile/transactions/TransactionList.jsx (4 hunks)
  • packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.jsx (2 hunks)
  • packages/loot-core/src/client/data-hooks/transactions.ts (3 hunks)
🧰 Additional context used
📓 Learnings (2)
packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx (1)
Learnt from: jfdoming
PR: actualbudget/actual#3402
File: packages/desktop-client/src/components/accounts/Account.tsx:8-8
Timestamp: 2024-11-10T16:45:25.627Z
Learning: In the `AllTransactions` component of `Account.tsx`, the `useLayoutEffect` hook is appropriately used to dispatch an action that closes splits for parent transactions when `prependTransactions` changes, ensuring this occurs synchronously before the component is painted.
packages/loot-core/src/client/data-hooks/transactions.ts (1)
Learnt from: joel-jeremy
PR: actualbudget/actual#3685
File: packages/loot-core/src/client/data-hooks/transactions.ts:32-88
Timestamp: 2024-11-10T16:45:25.627Z
Learning: In the React `useTransactions` hook defined in `packages/loot-core/src/client/data-hooks/transactions.ts`, changes to `options` (e.g., `options.pageCount`) should be applied on the next query without adding them to the `useEffect` dependency array, to avoid unnecessary rerenders when options change.
🔇 Additional comments (11)
packages/desktop-client/src/components/mobile/budget/CategoryTransactions.jsx (3)

Line range hint 43-47: LGTM! Hook usage is properly implemented.

The addition of isLoadingMore and loadMoreTransactions from the useTransactions hook aligns with the PR objective and follows React best practices.


60-60: LGTM! Simplified reload call.

Removing optional chaining is appropriate since reloadTransactions is a required property from the hook.


Line range hint 1-134: Verify consistent loading state implementation across mobile components.

Let's ensure the loading state implementation is consistent across all mobile transaction-related components.

✅ Verification successful

Let me gather more specific information about the implementation patterns.


Based on the results, I can now generate the final response as we have sufficient information about the loading state implementation across components.

Loading state implementation is consistent across mobile transaction components

The implementation of loading states is uniform across all mobile transaction-related components:

  • All components use the useTransactions hook which provides isLoadingMore and loadMore functionality
  • TransactionListWithBalances consistently receives and handles isLoadingMore prop
  • Loading states are properly propagated from data hooks to the UI components
  • The implementation in CategoryTransactions.jsx follows the same pattern as AccountTransactions.tsx and other transaction components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent implementation of loading states across mobile transaction components
# Expected: All mobile transaction components should handle isLoadingMore similarly

# Search for mobile transaction components using isLoadingMore
echo "Checking mobile transaction components for loading state implementation..."
rg -l "isLoadingMore" "packages/desktop-client/src/components/mobile"

# Check TransactionListWithBalances usage
echo "\nChecking TransactionListWithBalances usage patterns..."
ast-grep --pattern 'TransactionListWithBalances {
  $$$
  isLoadingMore={$_}
  $$$
}'

Length of output: 764


Script:

#!/bin/bash
# Check the implementation patterns in all identified files

echo "Checking TransactionList.jsx implementation:"
rg "isLoadingMore" -B 2 -A 2 packages/desktop-client/src/components/mobile/transactions/TransactionList.jsx

echo "\nChecking AccountTransactions.tsx implementation:"
rg "isLoadingMore" -B 2 -A 2 packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx

echo "\nChecking TransactionListWithBalances.jsx implementation:"
rg "isLoadingMore" -B 2 -A 2 packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.jsx

# Check if all components use useTransactions hook
echo "\nChecking useTransactions hook usage:"
rg "useTransactions" -A 5 packages/desktop-client/src/components/mobile/budget/CategoryTransactions.jsx packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx packages/desktop-client/src/components/mobile/transactions/TransactionList.jsx

Length of output: 6151

packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.jsx (2)

68-69: LGTM: Props addition aligns with loading indicator implementation

The new props isLoadingMore and onLoadMore are well-named and properly structured for handling the loading state of additional transactions.


108-110: Verify interaction between pull-to-refresh and load-more states

While the implementation looks correct, please ensure that the loading states don't conflict when both pull-to-refresh and load-more operations are triggered simultaneously.

Let's check for any existing handling of concurrent loading states:

Consider implementing a loading state manager to handle concurrent loading operations if not already present. This would help prevent potential race conditions and improve UX.

✅ Verification successful

Let me gather more information about the PullToRefresh component and its interaction with loading states.


Let me try one more search to find the TransactionList component implementation to see how it handles these states.


Based on the available evidence from our searches, I'll generate the final response since we've seen that:

  1. The loading states (isLoadingMore and pull-to-refresh) are handled separately
  2. Multiple components use these props consistently (AccountTransactions, CategoryTransactions, TransactionListWithBalances)
  3. The props are properly forwarded through the component hierarchy

Loading states implementation appears correct

The current implementation separates pull-to-refresh and load-more states, which is the correct approach. The components consistently handle these states across different transaction list implementations, suggesting a well-established pattern. No evidence of state conflicts was found in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for loading state handling in related components
ast-grep --pattern 'isLoading || isLoadingMore' 
rg -A 5 'isLoading.*isLoadingMore|isLoadingMore.*isLoading'

Length of output: 2161


Script:

#!/bin/bash
# Search for PullToRefresh component implementation
ast-grep --pattern 'function PullToRefresh' 
ast-grep --pattern 'const PullToRefresh =' 

# Search for loading state handling in PullToRefresh
rg -A 10 'onRefresh.*isLoading|isLoading.*onRefresh' 

Length of output: 3132


Script:

#!/bin/bash
# Search for TransactionList component and its loading state handling
ast-grep --pattern 'function TransactionList' 
ast-grep --pattern 'const TransactionList ='

# Search for loading state props in TransactionList
rg -B 2 -A 5 'isLoadingMore.*onLoadMore|onLoadMore.*isLoadingMore'

Length of output: 3150

packages/loot-core/src/client/data-hooks/transactions.ts (2)

27-31: LGTM! Type changes improve type safety and support new features.

The changes to make isLoading and reload required properties, along with the addition of loadMore and isLoadingMore, enforce better handling of loading states and provide necessary functionality for loading more transactions.


39-39: LGTM! Well-implemented loading states and error handling.

The implementation shows good practices:

  • Proper state management for loading indicators
  • Error handling with cleanup in finally block
  • Efficient use of useCallback
  • Respects the learning about preventing unnecessary rerenders from options changes

Also applies to: 93-106, 108-110

packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx (2)

271-271: LGTM! Simplified reload call.

The removal of optional chaining is appropriate since reloadTransactions is now a required property from the hook. This change simplifies the code while maintaining the same functionality.


328-329: LGTM! Verify TransactionListWithBalances implementation.

The loading state props are correctly passed down to handle pagination. Let's verify that the TransactionListWithBalances component properly implements these props.

✅ Verification successful

Props are correctly implemented and used

The loading props are properly implemented in both components:

  • TransactionListWithBalances correctly passes down isLoadingMore and onLoadMore props to TransactionList
  • TransactionList properly implements infinite scroll loading:
    • Uses useScrollListener to detect when user scrolls to bottom and calls onLoadMore
    • Shows a loading indicator when isLoadingMore is true
    • Loading indicator has proper accessibility label and consistent styling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify TransactionListWithBalances implementation of loading props

# Check if TransactionListWithBalances properly implements the loading props
ast-grep --pattern 'type Props = {
  $$$
  isLoadingMore?: boolean
  onLoadMore?: () => void
  $$$
}' packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx

# Check if there's a loading indicator UI implementation
rg -A 5 'isLoadingMore.*true' packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx

Length of output: 586


Script:

#!/bin/bash
# Let's first find the correct location of TransactionListWithBalances
fd -t f "TransactionListWithBalances.tsx" 

# Once we find the file, we'll verify the implementation

Length of output: 41


Script:

#!/bin/bash
# Let's try a broader search for the component using ripgrep
rg -l "TransactionListWithBalances"

# Also search for any file containing both isLoadingMore and onLoadMore props
rg -l "isLoadingMore.*onLoadMore|onLoadMore.*isLoadingMore"

Length of output: 345


Script:

#!/bin/bash
# Now that we found the correct file (.jsx extension), let's check its implementation
cat packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.jsx

# Also check for any loading-related UI implementation
rg -A 5 "isLoadingMore|onLoadMore" packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.jsx

Length of output: 5727


Script:

#!/bin/bash
# Let's check the TransactionList component to see how it handles these props
cat packages/desktop-client/src/components/mobile/transactions/TransactionList.jsx

# Also check for any loading-related UI implementation in TransactionList
rg -A 5 "isLoadingMore|onLoadMore" packages/desktop-client/src/components/mobile/transactions/TransactionList.jsx

Length of output: 17110

packages/desktop-client/src/components/mobile/transactions/TransactionList.jsx (2)

59-66: LGTM! Props update aligns with loading indicator requirement

The addition of isLoadingMore prop enables proper handling of the loading state for pagination, which directly addresses the PR objective.


67-68: Good internationalization implementation!

Translation hooks are properly implemented and consistently used for user-facing strings, improving accessibility and internationalization support.

Also applies to: 111-112, 117-117

Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

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

LGTM

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

Successfully merging this pull request may close these issues.

2 participants