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 bookmark #4347

Merged
merged 22 commits into from
Jun 26, 2024
Merged

Add bookmark #4347

merged 22 commits into from
Jun 26, 2024

Conversation

MohammadPCh
Copy link
Collaborator

@MohammadPCh MohammadPCh commented Jun 26, 2024

Summary by CodeRabbit

  • New Features

    • Added "Bookmarked Projects" label for easier project management.
  • Bug Fixes

    • Removed "Liked Projects" feature to streamline user experience.
  • Updates

    • Adjusted sharing options to enhance social media integration.
    • Updated @giveth/ui-design-system to version 1.11.33.
  • UI Improvements

    • Replaced heart icons with bookmark icons in project-related components.
    • Simplified badge display to always show a share icon.
    • Updated labels and tooltips to align with new bookmark functionality.
  • Backend Adjustments

    • Removed totalReactions field from various GraphQL queries for improved performance.

Copy link

vercel bot commented Jun 26, 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 Jun 26, 2024 9:49am

Copy link
Contributor

coderabbitai bot commented Jun 26, 2024

Walkthrough

Overall changes focus on replacing the "liked projects" feature with "bookmarked projects" and involve updating labels, GraphQL queries, and components accordingly. This transition affects the user interface by modifying icons, labels, and functionality related to project interactions, such as bookmarking instead of liking. Additionally, there are updates to the package dependencies and minor adjustments to project action components, aligning the application more consistently with the new bookmarking functionality.

Changes

File/Directory Summary of Changes
lang/ca.json, lang/en.json, lang/es.json Added label for "Bookmarked Projects", removed "Liked Projects", adjusted sharing options
package.json Updated @giveth/ui-design-system from 1.11.31 to 1.11.33
src/apollo/gql/gqlHomePage.ts, src/apollo/gql/gqlProjects.ts, src/apollo/types/types.ts Removed totalReactions field from queries and IProject interface
src/components/DonateSocialBox.tsx, src/components/badges/ShareLikeBadge.tsx Removed type prop logic, updated badge display to always share
src/components/project-card/ProjectCard.tsx, .../ProjectCardBadgeButtons.tsx Renamed and updated badge buttons, removed like/unlike functionality
src/components/views/project/projectActionCard/ProjectPublicActions.tsx Swapped heart icons for bookmark icons, updated like to bookmark actions
src/components/views/projects/sort/ProjectsSortSelect.tsx Removed MOST_LIKED sorting option and icon
src/components/views/userProfile/ProfileContributes.tsx Updated label to "Bookmarked Projects"
src/components/views/userProfile/projectsTab/ProfileProjectsTab.tsx, .../ProjectItem.tsx Removed changeOrder function and heart icon import
src/components/views/verification/projectContact/ProjectContactIndex.tsx Removed type='share' prop from ShareLikeBadge
src/features/user/user.slice.ts Removed incrementLikedProjectsCount and decrementLikedProjectsCount functions
src/lib/reaction.ts Renamed likeProject to bookmarkProject, unlikeProject to unBookmarkProject

Poem

In code we trust, a shift we make,
From hearts to bookmarks, a change we take.
Reactions gone, new stories told,
Bookmarked projects, new and bold.
Bugs we've banished, features new,
🎉 Here's to updates, and to you!

— 🐰 A Rabbit Dev


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 884743d and efd01d2.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (19)
  • lang/ca.json (3 hunks)
  • lang/en.json (3 hunks)
  • lang/es.json (3 hunks)
  • package.json (1 hunks)
  • src/apollo/gql/gqlHomePage.ts (1 hunks)
  • src/apollo/gql/gqlProjects.ts (5 hunks)
  • src/apollo/types/types.ts (1 hunks)
  • src/components/DonateSocialBox.tsx (1 hunks)
  • src/components/badges/ShareLikeBadge.tsx (1 hunks)
  • src/components/project-card/ProjectCard.tsx (1 hunks)
  • src/components/project-card/ProjectCardBadgeButtons.tsx (4 hunks)
  • src/components/views/project/projectActionCard/ProjectPublicActions.tsx (6 hunks)
  • src/components/views/projects/sort/ProjectsSortSelect.tsx (2 hunks)
  • src/components/views/userProfile/ProfileContributes.tsx (1 hunks)
  • src/components/views/userProfile/projectsTab/ProfileProjectsTab.tsx (1 hunks)
  • src/components/views/userProfile/projectsTab/ProjectItem.tsx (2 hunks)
  • src/components/views/verification/projectContact/ProjectContactIndex.tsx (1 hunks)
  • src/features/user/user.slice.ts (2 hunks)
  • src/lib/reaction.ts (2 hunks)
Files not reviewed due to errors (1)
  • src/components/project-card/ProjectCardBadgeButtons.tsx (no review received)
Files skipped from review due to trivial changes (7)
  • lang/ca.json
  • lang/es.json
  • package.json
  • src/apollo/gql/gqlProjects.ts
  • src/components/views/projects/sort/ProjectsSortSelect.tsx
  • src/components/views/userProfile/ProfileContributes.tsx
  • src/features/user/user.slice.ts
Additional comments not posted (14)
src/components/badges/ShareLikeBadge.tsx (1)

18-33: Simplified Badge Component Review.

The refactoring of ShareLikeBadge to always display a share icon and label is in line with the PR's objectives. The prop destructuring and conditional rendering logic are correctly implemented.

src/apollo/gql/gqlHomePage.ts (1)

Line range hint 1-46: GraphQL Query Review for Homepage Data.

The GraphQL query FETCH_HOMEPAGE_DATA appears to be correctly updated, removing all instances of totalReactions. This aligns well with the PR's goal of removing reaction-related fields.

src/components/DonateSocialBox.tsx (1)

Line range hint 1-50: Review of DonateSocialBox Component Integration.

The DonateSocialBox component integrates the updated ShareLikeBadge correctly. It handles modal visibility and provides links for learning more about donating, which are appropriate given the context.

src/components/views/userProfile/projectsTab/ProfileProjectsTab.tsx (2)

Line range hint 1-1: Ensure proper import ordering and grouping.

Imports should be grouped and ordered: external libraries, internal modules, styles, and types. This enhances readability and maintainability.


Line range hint 22-22: Consider using a more descriptive variable name.

The variable itemPerPage could be renamed to itemsPerPage to better reflect that it represents multiple items.

src/components/views/userProfile/projectsTab/ProjectItem.tsx (2)

1-1: Ensure consistent import ordering.

Imports should be grouped and ordered: external libraries, internal modules, styles, and types. This enhances readability and maintainability.


Line range hint 22-22: Consider adding type annotations for state hooks.

For state hooks like useState, adding type annotations can improve type safety and code readability.

src/components/views/verification/projectContact/ProjectContactIndex.tsx (2)

Line range hint 1-1: Optimize import statements.

Imports should be grouped and ordered: external libraries, internal modules, styles, and types. This enhances readability and maintainability.


Line range hint 20-20: Use a more descriptive variable name for BtnContainer.

The name BtnContainer is too generic. Consider renaming it to ButtonContainer for better readability and maintainability.

src/apollo/types/types.ts (1)

Line range hint 1-1: Review import statements for consistency.

Ensure that all necessary types are imported and used correctly throughout the file to maintain type safety and consistency.

src/components/project-card/ProjectCard.tsx (2)

22-22: Updated import path reflects component renaming.

The import path change from ProjectCardLikeAndShareButtons to ProjectCardBadgeButtons aligns with the PR's goal of transitioning from "like" functionality to "bookmark". This is consistent with the renaming of the component to better reflect its new functionality.


Line range hint 22-329: Comprehensive Component Review: ProjectCard.

The ProjectCard component appears well-structured and follows best practices for React functional components. It utilizes hooks effectively for state management and routing, and styled-components for dynamic styling based on props and state.

  1. State Management and Hooks: The use of useState and useRouter is appropriate for handling component state and routing. The component's state management logic, particularly for handling hover states and modal visibility, is clear and concise.

  2. Conditional Rendering: The component uses conditional rendering effectively to manage different UI states based on the project's verification status and whether the round has started.

  3. Internationalization and Styling: The use of react-intl for internationalization ensures that the component can support multiple languages. The styled-components are used effectively to adjust styles based on the component's state and props.

Overall, the component is well-implemented with attention to performance, maintainability, and user experience.

lang/en.json (2)

206-206: Addition of "label.bookmarked_projects" is appropriate.

The addition of the key "label.bookmarked_projects" with the value "Bookmarked Projects" aligns with the PR objectives to transition from "liked" projects to "bookmarked" projects. The key and value are correctly formatted and follow the consistent naming convention used throughout the file.


873-873: Reordering of "label.share_on_linkedin" is handled correctly.

The key "label.share_on_linkedin" has been moved to appear before "label.share_on_farcaster", aligning with the PR objectives to adjust the position of sharing options. This change is correctly implemented and reflects a potential change in UI priorities.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 1

Outside diff range and nitpick comments (6)
src/lib/reaction.ts (2)

Line range hint 8-14: Ensure correct mutation is used for bookmarking.

The function bookmarkProject uses LIKE_PROJECT_MUTATION which seems incorrect based on the PR's objective to transition from likes to bookmarks. This might be an oversight.

- mutation: LIKE_PROJECT_MUTATION,
+ mutation: BOOKMARK_PROJECT_MUTATION, // Assuming a new mutation for bookmarking is defined

Line range hint 21-27: Ensure correct mutation is used for unbookmarking.

Similar to the bookmarkProject function, unBookmarkProject uses UNLIKE_PROJECT_MUTATION. This should be updated to reflect the new bookmarking functionality.

- mutation: UNLIKE_PROJECT_MUTATION,
+ mutation: UNBOOKMARK_PROJECT_MUTATION, // Assuming a new mutation for unbookmarking is defined
src/components/views/userProfile/projectsTab/ProfileProjectsTab.tsx (1)

[!TIP]
Codebase Verification

Add error handling in fetchUserProjects function

The fetchUserProjects function in both ProfileProjectsTab.tsx and ProfileLikedTab.tsx currently fetches data and updates the state but does not handle errors explicitly. To improve user experience, consider adding error handling to provide feedback to the user in case of a failure.

  • ProfileProjectsTab.tsx
  • ProfileLikedTab.tsx
Analysis chain

Line range hint 46-46: Verify the error handling in asynchronous data fetching.

The function fetchUserProjects fetches data but only logs errors without handling them in the UI. Consider adding error handling to improve user experience.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify error handling in data fetching.
# Expect: Error handling logic or UI feedback mechanisms.
rg --type tsx "fetchUserProjects"

Length of output: 61



Script:

#!/bin/bash
# Description: Verify error handling in data fetching.
# Expect: Error handling logic or UI feedback mechanisms.
rg --glob "*.tsx" "fetchUserProjects"

Length of output: 423



Script:

#!/bin/bash
# Extract the implementation of fetchUserProjects in ProfileProjectsTab.tsx
ast-grep --lang tsx --pattern 'const fetchUserProjects = async () => { $$$ }' src/components/views/userProfile/projectsTab/ProfileProjectsTab.tsx

# Extract the implementation of fetchUserProjects in ProfileLikedTab.tsx
ast-grep --lang tsx --pattern 'const fetchUserProjects = async () => { $$$ }' src/components/views/userProfile/ProfileLikedTab.tsx

Length of output: 3970

src/components/views/userProfile/projectsTab/ProjectItem.tsx (1)

Line range hint 20-20: Use destructuring for props for cleaner code.

Consider destructuring project and setProjects directly in the function parameters to clean up the code.

- const ProjectItem = ({ project, setProjects }: IProjectItem) => {
+ const ProjectItem = ({ project, setProjects }: { project: IProject; setProjects: Dispatch<SetStateAction<IProject[]>> }) => {
src/components/views/verification/projectContact/ProjectContactIndex.tsx (1)

Line range hint 22-22: Add error handling for asynchronous operations.

The function sendReq performs asynchronous operations but lacks proper error handling. Consider adding error handling to improve robustness and user experience.

+ try {
    const { data } = await client.mutate({
        mutation: UPDATE_PROJECT_VERIFICATION,
        variables: {
            projectVerificationUpdateInput: {
                projectVerificationId: Number(verificationData?.id),
                step: EVerificationSteps.PROJECT_CONTACTS,
                projectContacts: createSocials(),
            },
        },
    });
    setVerificationData(data.updateProjectVerificationForm);
    setStep(5);
+ } catch (error) {
+     console.error('Failed to update project verification:', error);
+     // Add UI error handling here
+ }
src/apollo/types/types.ts (1)

Line range hint 20-20: Consider refining the IProject interface.

The IProject interface is extensive. Consider breaking it into smaller, more manageable interfaces to improve maintainability and readability.

+ interface IProjectBasicInfo {
+     id: string;
+     title?: string;
+     slug: string;
+     image?: string;
+ }
+ 
+ interface IProjectDetails extends IProjectBasicInfo {
+     description?: string;
+     creationDate?: string;
+     // other fields
+ }
+ 
+ export interface IProject extends IProjectDetails {
+     // additional fields
+ }

Comment on lines +86 to +89
const newReaction = await bookmarkProject(projectId);
setReaction(newReaction);
if (newReaction) {
setTotalReactions(
_totalReactions => (_totalReactions || 0) + 1,
);
dispatch(incrementLikedProjectsCount());
}
} else if (reaction?.userId === user?.id) {
const successful = await unlikeProject(reaction.id);
const successful = await unBookmarkProject(reaction.id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for asynchronous operations.

The likeUnlikeProject function performs asynchronous operations but does not properly handle potential errors in the UI. Consider adding more robust error handling.

+ try {
    if (!reaction) {
        const newReaction = await bookmarkProject(projectId);
        setReaction(newReaction);
    } else if (reaction?.userId === user?.id) {
        const successful = await unBookmarkProject(reaction.id);
        if (successful) {
            setReaction(undefined);
        }
    }
+ } catch (error) {
+     console.error('Failed to update project reaction:', error);
+     // Add UI error handling here
+ }
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
const newReaction = await bookmarkProject(projectId);
setReaction(newReaction);
if (newReaction) {
setTotalReactions(
_totalReactions => (_totalReactions || 0) + 1,
);
dispatch(incrementLikedProjectsCount());
}
} else if (reaction?.userId === user?.id) {
const successful = await unlikeProject(reaction.id);
const successful = await unBookmarkProject(reaction.id);
try {
if (!reaction) {
const newReaction = await bookmarkProject(projectId);
setReaction(newReaction);
} else if (reaction?.userId === user?.id) {
const successful = await unBookmarkProject(reaction.id);
if (successful) {
setReaction(undefined);
}
}
} catch (error) {
console.error('Failed to update project reaction:', error);
// Add UI error handling here
}

Copy link
Collaborator

@kkatusic kkatusic left a comment

Choose a reason for hiding this comment

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

LGTM :)

@MohammadPCh MohammadPCh merged commit 9d512ac into develop Jun 26, 2024
3 checks passed
@MohammadPCh MohammadPCh deleted the add-bookmark branch June 26, 2024 10:54
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.

2 participants