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

WIP: Improve back option #4506

Merged
merged 32 commits into from
Oct 20, 2024
Merged

WIP: Improve back option #4506

merged 32 commits into from
Oct 20, 2024

Conversation

kkatusic
Copy link
Collaborator

@kkatusic kkatusic commented Jul 30, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a unique ID property for the CardBody component to enhance accessibility and styling.
    • Implemented an infinite scrolling feature in the ProjectsIndex for dynamic loading of project data.
    • Added support for connecting with the Safe wallet, enhancing wallet connectivity options.
  • Improvements

    • Enhanced pagination handling and loading state management through the use of React Query's useInfiniteQuery hook.
    • Improved responsiveness of the ProjectGIVbackToast component for better layout on larger screens.
  • Bug Fixes

    • Streamlined UI updates during data fetching by leveraging built-in flags for better user experience.
    • Adjusted tab activation logic in the DonationCard component for Endaoment projects to improve user experience.

Copy link

vercel bot commented Jul 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
giveth-dapps-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 8, 2024 9:40am

Copy link
Contributor

coderabbitai bot commented Jul 30, 2024

Walkthrough

The changes involve updates to dependency versions in package.json, enhancements to the ProjectCard component by adding an id attribute, and significant refactoring of the ProjectsIndex component to utilize useInfiniteQuery for improved data fetching and pagination. Additionally, logic modifications in the DonationCard component and styling adjustments in ProjectGIVbackToast are included. A new wallet connector, safe, is also added to wagmiConfigs.ts, broadening wallet connection options.

Changes

Files Change Summary
package.json Updated versions of @web3modal/wagmi from ^5.0.7 to ^5.1.7 and wagmi from ^2.11.3 to ^2.12.10.
src/components/project-card/ProjectCard.tsx Added an id property to CardBody, dynamically generated from the slug variable for better DOM identification.
src/components/views/projects/ProjectsIndex.tsx Transitioned to useInfiniteQuery for fetching projects, introduced Page interface, and updated pagination handling with better state management and loading indicators.
src/components/views/projects/constants.ts Added a new constant LAST_PROJECT_CLICKED for session storage purposes.
src/components/views/projects/services.ts Introduced a new service file for fetching project data with defined interfaces and an asynchronous fetch function.
src/components/views/donate/DonationCard.tsx Introduced isEndaomentProject boolean to modify tab activation logic based on project type.
src/components/views/project/ProjectGIVbackToast.tsx Adjusted ButtonWrapper width to 100% for responsiveness and updated media query breakpoint for layout changes.
src/wagmiConfigs.ts Added a new wallet connector, safe, to enhance wallet connection options with specific allowed domains.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ProjectsIndex
    participant API

    User->>ProjectsIndex: Scroll to bottom
    ProjectsIndex->>API: fetchProjects(pageParam)
    API-->>ProjectsIndex: Return new project data
    ProjectsIndex->>User: Display new projects
Loading

🐇 In the meadow, hopping with glee,
New IDs and queries, oh what a spree!
Projects flow in, a stream so divine,
With each little card, how they brightly shine!
So let’s cheer for the code, both nifty and bright,
A leap into progress, oh what a delight! 🌼✨

Possibly related PRs

  • Upgrades web3modal #4401: This PR updates the version of @web3modal/wagmi in package.json, which is directly related to the version updates made in the main PR for the same dependency.
  • Hotfix - fix stellar doante card UI #4734: This PR also updates the versions of @web3modal/wagmi and wagmi in package.json, matching the changes made in the main PR.
  • Fix/givbacks verification form #4769: This PR updates the version of @giveth/ui-design-system in package.json, which is relevant as it shows ongoing updates to dependencies alongside the changes in the main PR.
  • quadratic funding toast on donate success page #4820: This PR includes updates to the eligibility messaging related to GIVbacks, which may connect to the overall functionality impacted by the dependency updates in the main PR.

Suggested reviewers

  • Meriem-BM
  • kkatusic

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.

@kkatusic kkatusic changed the title Improve back option WIP: Improve back option Jul 30, 2024
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: 2

src/components/views/projects/ProjectsIndex.tsx Outdated Show resolved Hide resolved
src/components/views/projects/ProjectsIndex.tsx Outdated Show resolved Hide resolved
@kkatusic
Copy link
Collaborator Author

@MohammadPCh just don't forget this :)

@alireza-sharifpour
Copy link
Member

Thanks @kkatusic!
I checked it but I noticed something.

I filtered the QF projects but the number of total
Screenshot 2024-09-04 at 4 38 23 PM
projects didn't change, can you take a look?

@kkatusic kkatusic self-assigned this Sep 9, 2024
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 (1)
src/components/views/donate/DonationCard.tsx (1)

97-103: Approve commenting out the code for now, but track the feature refinement separately.

Commenting out the useEffect logic that sets the default tab based on project type is a good temporary measure while the feature is being polished. It prevents unintended behavior for Endaoment projects.

However, to ensure this feature is reintroduced properly, consider creating a separate issue or task to track its refinement and re-enablement. This will help maintain visibility on the intended behavior without cluttering the current code.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 89ba8a4 and a341c98.

Files ignored due to path filters (2)
  • public/images/banners/qf-round/giv-palooza.svg is excluded by !**/*.svg
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (5)
  • package.json (2 hunks)
  • src/components/project-card/ProjectCard.tsx (1 hunks)
  • src/components/views/donate/DonationCard.tsx (2 hunks)
  • src/components/views/project/ProjectGIVbackToast.tsx (2 hunks)
  • src/wagmiConfigs.ts (2 hunks)
Files skipped from review due to trivial changes (2)
  • package.json
  • src/components/project-card/ProjectCard.tsx
Additional comments not posted (4)
src/wagmiConfigs.ts (1)

31-33: LGTM!

The addition of the safe connector with the allowedDomains property is a great enhancement to the wallet connectivity options. It improves user experience and security by allowing users to connect through the Safe wallet, while restricting connections to the Safe application hosted at app.safe.global.

src/components/views/donate/DonationCard.tsx (1)

56-56: LGTM!

The isEndaomentProject variable is a clear and concise way to determine if the project is an Endaoment project based on the organization label. The naming is intuitive and the logic is straightforward.

src/components/views/project/ProjectGIVbackToast.tsx (2)

330-330: LGTM!

Changing the width from a fixed value to 100% is a good practice for improving responsiveness. This allows the button wrapper to adapt to the width of its parent container, enhancing the layout across different screen sizes.


357-357: Verify the layout on larger screens.

Updating the media query breakpoint from tablet to laptopL is a design decision that aims to improve the user interface on larger devices. This change implies that the flex-direction will change from column to row at a larger screen size compared to the previous breakpoint.

Please ensure that the new breakpoint aligns with the intended design and provides an optimal user experience across different screen sizes. Verify the layout on larger screens to confirm that the change achieves the desired outcome.

@kkatusic
Copy link
Collaborator Author

Thanks @kkatusic! I checked it but I noticed something.

I filtered the QF projects but the number of total Screenshot 2024-09-04 at 4 38 23 PM projects didn't change, can you take a look?

Found some time again to check this, when you @alireza-sharifpour found time please can you review it again? thx

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 (1)
src/components/views/projects/ProjectsIndex.tsx (1)

150-172: Remove console logs before merging.

The code segment looks good overall, but there are a couple of console logs that should be removed before merging to production:

console.log('lastPage', lastPage);
console.log('someData', someData);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a341c98 and e2b9ae3.

Files selected for processing (1)
  • src/components/views/projects/ProjectsIndex.tsx (10 hunks)
Additional comments not posted (5)
src/components/views/projects/ProjectsIndex.tsx (5)

Line range hint 1-12:


Line range hint 25-46:


58-65: LGTM!

The Page interface is a good addition to provide a structured type for the data returned by the fetchProjects function. It improves type safety and code readability.


68-81: LGTM!

The code segment properly initializes the necessary state variables and hooks for the component. The use of useQueryClient and the initialization of totalPages and totalCount based on the _totalCount prop are appropriate.


99-138: LGTM!

The fetchProjects function is well-structured and handles the data fetching logic effectively. It constructs the necessary variables for the GraphQL query, updates the relevant state variables with the fetched data, and returns an object that follows the Page interface. The use of useCallback for memoization is a good optimization.

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)
src/components/project-card/ProjectCard.tsx (4)

Line range hint 130-131: Consider optimizing the useEffect dependency

The useEffect hook now depends on the entire props object, which might cause unnecessary re-calculations when unrelated props change. Consider specifying only the relevant props in the dependency array to optimize performance.

For example, if only certain props affect the recurring donation calculations, you could destructure them:

const { id, activeStartedRound } = props;
useEffect(() => {
  // ... calculation logic
}, [id, activeStartedRound]);

Could you clarify which specific prop changes should trigger this recalculation? This will help in determining the most appropriate dependencies for the effect.


Line range hint 301-301: Address TODO: Add recurring donation amount

There's a TODO comment indicating that the recurring donation amount should be added to the total donation amount for active rounds. This functionality seems to be missing, which could lead to inaccurate donation totals being displayed.

Could you provide an update on the status of this feature? If it's still pending, consider creating a separate issue to track this enhancement and ensure it's not overlooked.

Would you like me to create a GitHub issue for tracking this TODO item?


Line range hint 130-131: Consider moving data fetching logic to a custom hook

The component is directly fetching recurring donations data using the Apollo client. To improve separation of concerns and potentially optimize performance, consider moving this data fetching logic to a custom hook.

For example:

const useRecurringDonations = (projectId, startDate, endDate) => {
  const [recurringDonations, setRecurringDonations] = useState([]);
  
  useEffect(() => {
    const fetchData = async () => {
      // Fetch logic here
    };
    fetchData();
  }, [projectId, startDate, endDate]);

  return recurringDonations;
};

This approach would make the component more focused on rendering and improve testability. It also allows for easier reuse of this data fetching logic in other components if needed.


Line range hint 1-686: Consider refactoring for improved maintainability

The ProjectCard component is quite large and handles multiple responsibilities, including data fetching, complex rendering logic, and styling. To improve maintainability and testability, consider the following refactoring suggestions:

  1. Break down the component into smaller, more focused sub-components. For example, you could create separate components for the card header, body, and footer.

  2. Move styled components to a separate file (e.g., ProjectCard.styles.ts) to improve organization and reduce the size of the main component file.

  3. Consider using a custom hook for managing the component's state and side effects, separating the logic from the rendering.

  4. If possible, move some of the complex calculations (e.g., for donations and matching) to utility functions that can be easily tested in isolation.

These changes would make the code more modular, easier to understand, and simpler to maintain and test.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e2b9ae3 and 2049285.

📒 Files selected for processing (1)
  • src/components/project-card/ProjectCard.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
src/components/project-card/ProjectCard.tsx (1)

181-181: LGTM: Adding id attribute improves accessibility and targeting

The addition of the id attribute to the CardBody component is a good practice. It enhances accessibility and makes it easier to target specific project cards for styling or scripting purposes. Using the project's slug in the id ensures uniqueness across different cards.

Copy link
Collaborator

@MohammadPCh MohammadPCh left a comment

Choose a reason for hiding this comment

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

@kkatusic Thanks, this is great! My suggestion would be to update the fetchProjects function to return the appropriate data in a way that allows the returned object to be used as state. That way, we won’t need to set separate states like setTotalPages, setTotalCount, and setFilteredProjects. Once that's done, we could move this function to the service file for better organization.

@kkatusic
Copy link
Collaborator Author

kkatusic commented Oct 7, 2024

thx @MohammadPCh , changes have been made, please check again ;)

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: 3

🧹 Outside diff range and nitpick comments (1)
src/components/views/projects/ProjectsIndex.tsx (1)

238-248: Safeguard against null references in scrolling logic

When scrolling to the last clicked project, if document.getElementById(lastProjectClicked) returns null, accessing offsetTop will result in undefined, which may cause unexpected scrolling behavior.

Add a check to ensure the element exists before attempting to scroll:

if (lastProjectClicked) {
    const element = document.getElementById(lastProjectClicked);
+   if (element) {
        window.scrollTo({
            top: element.offsetTop,
            behavior: 'smooth',
        });
+   }
    localStorage.removeItem('lastProjectClicked');
}

This prevents potential errors if the element is not found in the DOM.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2049285 and 1986731.

📒 Files selected for processing (1)
  • src/components/views/projects/ProjectsIndex.tsx (8 hunks)
🧰 Additional context used

src/components/views/projects/ProjectsIndex.tsx Outdated Show resolved Hide resolved
src/components/views/projects/ProjectsIndex.tsx Outdated Show resolved Hide resolved
src/components/views/projects/ProjectsIndex.tsx Outdated Show resolved Hide resolved
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: 6

🧹 Outside diff range and nitpick comments (1)
src/components/views/projects/ProjectsIndex.tsx (1)

267-270: Improve accessibility by using interactive elements

Using a div with an onClick handler may not be accessible to all users. Consider using a clickable element like a <button> or an <a> tag to enhance accessibility.

Apply this diff to replace the div with an a tag:

-	<div
+	<a
		key={project.id}
		id={project.slug}
		onClick={() =>
			handleProjectClick(project.slug)
		}
+		href="#"
	>
		<ProjectCard
			project={project}
			order={idx}
		/>
-	</div>
+	</a>

Remember to prevent the default action if using an anchor tag:

	onClick={(e) => {
+		e.preventDefault();
		handleProjectClick(project.slug);
	}}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1986731 and 6a22ca9.

📒 Files selected for processing (3)
  • src/components/views/projects/ProjectsIndex.tsx (6 hunks)
  • src/components/views/projects/constants.ts (1 hunks)
  • src/components/views/projects/services.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/components/views/projects/constants.ts
🧰 Additional context used

src/components/views/projects/services.ts Show resolved Hide resolved
src/components/views/projects/services.ts Show resolved Hide resolved
src/components/views/projects/services.ts Show resolved Hide resolved
src/components/views/projects/services.ts Show resolved Hide resolved
Copy link
Collaborator

@MohammadPCh MohammadPCh left a comment

Choose a reason for hiding this comment

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

Thanks @kkatusic LGTM

@MohammadPCh MohammadPCh merged commit 783616a into develop Oct 20, 2024
3 checks passed
@MohammadPCh MohammadPCh deleted the improve_back_option branch October 20, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: QA
Development

Successfully merging this pull request may close these issues.

3 participants