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

feat(web): starred-cases #1794

Merged
merged 8 commits into from
Dec 17, 2024
Merged

feat(web): starred-cases #1794

merged 8 commits into from
Dec 17, 2024

Conversation

Harman-singh-waraich
Copy link
Contributor

@Harman-singh-waraich Harman-singh-waraich commented Dec 16, 2024

PR-Codex overview

This PR introduces a new feature for managing starred cases, allowing users to favorite and unfavorite cases, view their favorite cases, and clear all favorites. It also updates the relevant components to integrate this functionality.

Detailed summary

  • Added useStarredCases hook for managing starred cases with local storage.
  • Created CaseStarButton component for favoriting individual cases.
  • Introduced FavoriteCases component to display starred cases.
  • Updated Dashboard and CaseDetails to include FavoriteCases and CaseStarButton.
  • Styled components for better layout and interaction.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features
    • Introduced a CaseStarButton component for starring cases.
    • Added a FavoriteCases component to display a list of favorite cases on the dashboard.
  • Bug Fixes
    • Improved header layout in the CaseDetails component for better alignment and spacing.
  • Chores
    • Updated import statements for better organization in the Dashboard component.

Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Walkthrough

This pull request introduces new components and hooks for managing starred cases in the web application. It includes the CaseStarButton, which allows users to star individual cases, and the FavoriteCases component, which displays a list of starred cases with pagination on the dashboard. Additionally, the custom hook useStarredCases is implemented to manage starred cases using local storage, ensuring persistence across sessions. These changes collectively enhance the user experience by enabling easy access to favorite cases.

Changes

File Change Summary
web/src/components/CaseStarButton.tsx New React component for starring/unstarring cases with dynamic styling and tooltip
web/src/components/FavoriteCases.tsx New component to display a list of starred cases with pagination
web/src/hooks/useStarredCases.tsx New custom hook to manage starred cases using local storage
web/src/pages/Cases/CaseDetails/index.tsx Added CaseStarButton to case details header
web/src/pages/Dashboard/index.tsx Integrated FavoriteCases component into dashboard

Suggested labels

Type: Enhancement :sparkles:, Package: Web, Type: UX

Suggested reviewers

  • Harman-singh-waraich

Poem

🌟 A star for each case so bright,
Marking favorites with delight!
Click and save, a simple art,
Bookmarking cases close to heart 🐰
Local storage keeps them tight!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 165bfdc and 1e74faa.

📒 Files selected for processing (1)
  • web/src/pages/Cases/CaseDetails/index.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Cases/CaseDetails/index.tsx

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 or @coderabbitai title 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: 4

🧹 Nitpick comments (4)
web/src/hooks/useStarredCases.tsx (1)

11-11: Optimize array creation for starred case IDs

starredCaseIds is recreated on every render. Consider memoizing it to prevent unnecessary array creations.

-const starredCaseIds = Array.from(starredCases.keys());
+const starredCaseIds = useMemo(() => Array.from(starredCases.keys()), [starredCases]);
web/src/pages/Cases/CaseDetails/index.tsx (1)

60-62: Consider adding loading state for CaseStarButton

The button appears immediately with the case ID, but the starred state might not be loaded yet. Consider adding a loading state to prevent UI flicker.

 <Header>
-  Case #{id} {id ? <CaseStarButton id={id} /> : null}
+  Case #{id} {id && !isLoading ? <CaseStarButton id={id} /> : null}
 </Header>
web/src/components/FavoriteCases.tsx (2)

48-54: Consider improving pagination implementation

A few suggestions to enhance the implementation:

  1. Consider making casesPerPage configurable through props or environment variables
  2. Add loading state management for initial data fetch to improve UX
 const FavoriteCases: React.FC = () => {
   const { starredCaseIds, clearAll } = useStarredCases();
+  const [isLoading, setIsLoading] = useState(true);
   const [currentPage, setCurrentPage] = useState(1);
-  const casesPerPage = 3;
+  const casesPerPage = Number(process.env.REACT_APP_CASES_PER_PAGE) || 3;
   const totalPages = Math.ceil(starredCaseIds.length / casesPerPage);

61-78: Simplify render logic and improve accessibility

The current implementation could be improved by:

  1. Simplifying the conditional rendering
  2. Adding proper aria labels for accessibility
-  return starredCaseIds.length > 0 && (isUndefined(disputes) || disputes.length > 0) ? (
+  if (starredCaseIds.length === 0) return null;
+
+  return (
     <Container>
-      <Title>Favorite Cases</Title>
-      <StyledLabel onClick={clearAll}>Clear all</StyledLabel>
+      <Title aria-label="Favorite Cases Section">Favorite Cases</Title>
+      <StyledLabel onClick={clearAll} aria-label="Clear all favorite cases">Clear all</StyledLabel>
       <DisputeContainer>
         {isUndefined(disputes)
           ? Array.from({ length: 3 }).map((_, index) => <SkeletonDisputeCard key={index} />)
           : disputes.map((dispute) => <DisputeView key={dispute.id} {...dispute} overrideIsList />)}
       </DisputeContainer>
       {totalPages > 1 ? (
         <StyledPagination
           currentPage={currentPage}
           numPages={totalPages}
           callback={(page: number) => setCurrentPage(page)}
+          aria-label="Navigate favorite cases pages"
         />
       ) : null}
     </Container>
-  ) : null;
+  );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 21696d9 and 3aff981.

⛔ Files ignored due to path filters (1)
  • web/src/assets/svgs/icons/star.svg is excluded by !**/*.svg
📒 Files selected for processing (5)
  • web/src/components/CaseStarButton.tsx (1 hunks)
  • web/src/components/FavoriteCases.tsx (1 hunks)
  • web/src/hooks/useStarredCases.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/index.tsx (3 hunks)
  • web/src/pages/Dashboard/index.tsx (2 hunks)
🔇 Additional comments (4)
web/src/hooks/useStarredCases.tsx (1)

8-8: 🛠️ Refactor suggestion

Consider adding type safety for localStorage data

The initial load from localStorage doesn't validate the data structure. Consider adding type checking to ensure the loaded data matches the expected format.

type StarredCase = [string, boolean];

const [localStarredCases, setLocalStarredCases] = useLocalStorage<StarredCase[]>(
  "starredCases",
  Array.from(initialValue)
);
web/src/components/FavoriteCases.tsx (1)

16-46: Well-structured styled components implementation!

Good use of:

  • Theme variables for consistent styling
  • Responsive grid layout with proper gap handling
  • Responsive sizing utilities
web/src/pages/Dashboard/index.tsx (2)

15-20: Clean import organization!

The imports are well-organized and properly grouped.


98-98: Verify FavoriteCases component placement

The FavoriteCases component is rendered outside the isConnected check, meaning it will be visible even when the user's wallet is not connected. Is this the intended behavior? Consider moving it inside the connected state check if favorite cases should only be visible to connected users.

web/src/hooks/useStarredCases.tsx Outdated Show resolved Hide resolved
web/src/components/CaseStarButton.tsx Outdated Show resolved Hide resolved
web/src/components/CaseStarButton.tsx Outdated Show resolved Hide resolved
web/src/components/FavoriteCases.tsx Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 16, 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: 1

🧹 Nitpick comments (1)
web/src/components/CaseStarButton.tsx (1)

11-34: Enhance button interactivity and accessibility

The current styling implementation could be improved in several ways:

  1. The hover state removes background but doesn't provide clear visual feedback
  2. Missing focus styles for keyboard navigation
  3. Asymmetric padding might affect visual alignment

Consider applying these improvements:

 const StyledButton = styled(Button)<{ starred: boolean }>`
   background: none;
-  padding: 0 0 2px 0;
+  padding: 4px;
   
   .button-svg {
     width: 24px;
     height: 24px;
     margin: 0;
     fill: none;
     
     path {
       stroke: ${({ theme }) => theme.secondaryPurple};
     }
     ${({ starred }) =>
       starred &&
       css`
         fill: ${({ theme }) => theme.secondaryPurple};
       `};
   }
 
   :hover {
     background: none;
+    opacity: 0.8;
+    transform: scale(1.1);
   }
+
+  :focus-visible {
+    outline: 2px solid ${({ theme }) => theme.secondaryPurple};
+    outline-offset: 2px;
+  }
 `;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3aff981 and 4bf05d1.

📒 Files selected for processing (1)
  • web/src/components/CaseStarButton.tsx (1 hunks)
🔇 Additional comments (3)
web/src/components/CaseStarButton.tsx (3)

1-9: LGTM! Imports are well-organized.

The imports are logically grouped and all dependencies are properly utilized in the component.


58-58: LGTM! Export statement is correct.

The default export follows React conventions.


36-56: Verify component integration in CaseDetails view

Let's ensure the component is properly integrated and there are no duplicate star button implementations.

✅ Verification successful

Let me gather more information about the CaseDetails component to verify the proper integration.


Component is properly integrated

The verification shows that:

  • CaseStarButton is correctly imported in CaseDetails
  • It's properly used within the header section with the required id prop
  • There are no duplicate star button implementations in the codebase
  • The integration pattern follows React best practices
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for CaseStarButton usage and potential duplicate implementations
echo "Checking CaseStarButton usage:"
rg -l "CaseStarButton"

echo "\nChecking for potential duplicate star button implementations:"
rg -i "star.*button|favorite.*button"

echo "\nChecking for proper import in CaseDetails:"
ast-grep --pattern 'import { $$ } from "$_"
  const CaseDetails = () => {
    $$$
    return (
      $$$
      <CaseStarButton $$ />
      $$$
    )
  }'

Length of output: 979


Script:

#!/bin/bash
# Check the CaseDetails component implementation
echo "Checking CaseDetails implementation:"
rg -A 5 -B 5 "CaseStarButton" web/src/pages/Cases/CaseDetails/index.tsx

echo "\nVerifying CaseStarButton import:"
rg "^import.*CaseStarButton" web/src/pages/Cases/CaseDetails/index.tsx

Length of output: 985

web/src/components/CaseStarButton.tsx Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 16, 2024
Copy link

netlify bot commented Dec 16, 2024

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 1e74faa
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/6761643cec3d660008b05a38
😎 Deploy Preview https://deploy-preview-1794--kleros-v2-testnet.netlify.app
📱 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.

Copy link

netlify bot commented Dec 16, 2024

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit 1e74faa
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/6761643cb39f210008035774
😎 Deploy Preview https://deploy-preview-1794--kleros-v2-university.netlify.app
📱 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.

Copy link

netlify bot commented Dec 16, 2024

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 1e74faa
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/6761643c2eb8640008e98dab
😎 Deploy Preview https://deploy-preview-1794--kleros-v2-neo.netlify.app
📱 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.

Copy link

netlify bot commented Dec 16, 2024

Deploy Preview for kleros-v2-testnet-devtools failed. Why did it fail? →

Name Link
🔨 Latest commit 1e74faa
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/6761643c8125a300089b6f12

Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link

codeclimate bot commented Dec 17, 2024

Code Climate has analyzed commit 1e74faa and detected 6 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2
Duplication 4

View more on Code Climate.

Copy link

sonarcloud bot commented Dec 17, 2024

@alcercu alcercu added this pull request to the merge queue Dec 17, 2024
Merged via the queue into dev with commit 4849f30 Dec 17, 2024
21 of 28 checks passed
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