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: add the search bar in courts page #1821

Merged
merged 6 commits into from
Jan 8, 2025
Merged

Conversation

kemuru
Copy link
Contributor

@kemuru kemuru commented Jan 6, 2025

PR-Codex overview

This PR primarily introduces a new component, TopSearch, to the CourtDetails page and removes its previous usage in the Courts page. It also includes various style updates and refactors in the Answer component.

Detailed summary

  • Deleted TopSearch from Courts page.
  • Added TopSearch component in CourtDetails page.
  • Refactored Answer component to remove unnecessary styled components.
  • Introduced a new styled layout for TopSearch with various UI elements like DropdownCascader and Searchbar.
  • Implemented court filtering logic in TopSearch.

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

Summary by CodeRabbit

  • New Features

    • Introduced a new TopSearch component for searching and selecting courts.
    • Added a search bar with real-time filtering alongside the existing dropdown for court selection.
  • Improvements

    • Enhanced user interface for navigating and finding courts.
    • Improved layout and styling for the search feature, including responsive design adjustments.
    • Simplified the AnswerDisplay component for a more streamlined user experience.
    • Adjusted the layout of the JuryContainer for better flexibility.
  • Bug Fixes

    • Removed the TopSearch component from the Courts page to prevent UI conflicts.

Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

Walkthrough

The pull request enhances the TopSearch component in the Courts page by adding a search functionality alongside the existing dropdown for court selection. It introduces a search bar that allows users to filter court results dynamically. The implementation utilizes React hooks such as useState and useMemo to manage the search state and filter the court data. The updated component displays matching results in a styled card format, facilitating navigation to specific court pages. Additionally, the AnswerDisplay and FinalDecision components have been simplified, and the TopSearch component has been integrated into the CourtDetails page.

Changes

File Change Summary
web/src/pages/Courts/TopSearch.tsx - Added useState and Searchbar imports
- Introduced search state variable
- Created flattenCourts utility function
- Implemented filteredCourts using useMemo
- Added SearchBarContainer and SearchResultsContainer
- Enhanced component styling and search functionality
web/src/components/Verdict/Answer.tsx - Removed styled-components import
- Eliminated Container styled component
- Replaced AnswerDescription with AnswerTitleAndDescription
web/src/components/Verdict/FinalDecision.tsx - Modified JuryContainer styling: removed flex-direction and adjusted flex-wrap
web/src/pages/Courts/CourtDetails/TopSearch.tsx - Introduced new TopSearch component for searching and selecting courts
web/src/pages/Courts/CourtDetails/index.tsx - Imported and rendered TopSearch component
web/src/pages/Courts/index.tsx - Removed TopSearch component from the Courts page

Possibly related PRs

  • feat: add staked pnk per court chart, slightly modify skeleton size, … #1707: The main PR introduces a search functionality in the TopSearch component, which is related to the TopSearch component mentioned in this PR that also enhances court selection and searching capabilities.
  • feat: tweak in court stake display in dashboard #1732: This PR modifies the CourtCard and CourtName components, which are relevant to the TopSearch component as they deal with displaying court information and navigation, potentially impacting how courts are selected or displayed.
  • feat: UX improvements #1760: The introduction of the ScrollTop component in various places, including CourtDetails, may relate to the user experience improvements in the TopSearch component, enhancing navigation and usability.
  • refactor(web): charts-improvements #1780: This PR focuses on chart improvements, which may indirectly relate to the TopSearch component if the search functionality is used to filter or display data in charts.
  • feat(web): starred-cases #1794: The addition of the FavoriteCases component and the CaseStarButton may relate to the overall user interface improvements in the application, including the TopSearch component's enhancements.
  • chore: slight cosmetic adjustments #1811: The slight cosmetic adjustments across various components, including headers and charts, may relate to the overall user interface improvements that also affect the TopSearch component.
  • feat: public dashboards #1819: The introduction of the addressToQuery prop and the use of useSearchParams in multiple components may enhance the functionality of the TopSearch component by improving how search parameters are handled across the application.

Suggested labels

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

Suggested reviewers

  • alcercu

Poem

🐰 Searching courts with rabbit's might,
A dropdown dance, a search so bright!
Filtering data with playful glee,
Navigation smooth as can be 🔍
Kleros courts now easier to find,
A coding magic, rabbit-designed! 🚀


🪧 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.

@kemuru kemuru requested a review from alcercu January 6, 2025 18:54
Copy link

netlify bot commented Jan 6, 2025

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit 605b082
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/677e2eeb2c513b0008c99366
😎 Deploy Preview https://deploy-preview-1821--kleros-v2-testnet-devtools.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 Jan 6, 2025

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit 605b082
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/677e2eeb3e73c200084b7c98
😎 Deploy Preview https://deploy-preview-1821--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 Jan 6, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 605b082
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/677e2eeb03973b0008b5570a
😎 Deploy Preview https://deploy-preview-1821--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
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

🧹 Nitpick comments (3)
web/src/pages/Courts/TopSearch.tsx (3)

40-48: Accessibility consideration for search input
Consider adding an aria-label or descriptive label text to the <StyledSearchbar> to improve accessibility for screen readers, especially since the placeholder text alone may not be sufficient.

 <StyledSearchbar
-  dir="auto"
+  aria-label="Search through courts"
   dir="auto"
   ...
 />

70-72: Ensure robust safety checks in flattenCourts
flattenCourts is straightforward and concise. However, if future adjustments allow unexpected data shapes (e.g., missing children fields), explicitly checking for array-like structures before using flatMap might help prevent runtime errors.

 function flattenCourts(court) {
-  return court ? [court, ...(court.children || []).flatMap(flattenCourts)] : [];
+  if (!court) return [];
+  const childArray = Array.isArray(court.children) ? court.children : [];
+  return [court, ...childArray.flatMap(flattenCourts)];
 }

79-84: Efficient filtering approach
Using toLowerCase() to filter courts is fine for simple matching. If you intend to scale this further with more advanced searching (fuzziness, synonyms), consider a library or move logic to a dedicated utility.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9daf106 and 1ede3d4.

📒 Files selected for processing (1)
  • web/src/pages/Courts/TopSearch.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Copy labels from linked issues
  • GitHub Check: contracts-testing
  • GitHub Check: Copy labels from linked issues
  • GitHub Check: Analyze (javascript)
  • GitHub Check: dependency-review
  • GitHub Check: SonarCloud
🔇 Additional comments (6)
web/src/pages/Courts/TopSearch.tsx (6)

1-4: Well-structured imports and usage of React hooks
The consolidated import statements and the addition of React hooks (useState, useMemo) look consistent and streamlined. Keep it up!


Line range hint 8-19: Suggest verifying CSS fallback
The gap and flex-wrap styling are good improvements. However, for older browsers that may not support gap in flex containers, consider verifying if a fallback is needed, or confirm that your targeted browsers fully support this property.


29-39: Praise for component organization
Wrapping the search bar in a dedicated container (SearchBarContainer) keeps the layout modular and easy to maintain. Nicely done!


50-60: Check on overflow styling
The usage of overflow-y: auto in SearchResultsContainer is appropriate, but be mindful of horizontally long court names. If that scenario occurs, you may want to limit horizontal overflow or add text truncation for better readability.


62-69: Consistent styling and clickable cards
The StyledCard effectively indicates hover states and clickable functionality. This is a clear, intuitive user experience.


89-120: Clear UI flow with conditional rendering
The conditional rendering that shows the search results only when needed is user-friendly. Ensuring that the dropdown and the search bar both appear in the UI simultaneously provides flexibility for different user preferences. Nice work!

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 6, 2025
Copy link

netlify bot commented Jan 6, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 605b082
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/677e2eebefa8310008860757
😎 Deploy Preview https://deploy-preview-1821--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
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 (4)
web/src/pages/Courts/TopSearch.tsx (4)

46-54: Review hardcoded values in StyledSearchbar.

Consider replacing hardcoded values with theme variables or responsive units:

  • font-size: 16px
  • height: 45px
const StyledSearchbar = styled(Searchbar)`
  width: 100%;
  input {
-    font-size: 16px;
-    height: 45px;
+    font-size: ${({ theme }) => theme.fontSize.regular};
+    height: ${responsiveSize(45, 50)};
    padding-top: 0px;
    padding-bottom: 0px;
  }
`;

56-66: Coordinate z-index usage with other components.

The SearchResultsContainer uses z-index: 1. Consider:

  1. Documenting z-index layers in a shared constants file
  2. Ensuring this value doesn't conflict with other overlapping elements

76-78: Add TypeScript types and consider memoization for flattenCourts.

The recursive implementation is clean, but could benefit from:

  1. Type safety
  2. Memoization for large court hierarchies
- function flattenCourts(court) {
+ interface Court {
+   id: string;
+   name: string;
+   children?: Court[];
+ }
+ 
+ function flattenCourts(court: Court | undefined): Court[] {
  return court ? [court, ...(court.children || []).flatMap(flattenCourts)] : [];
}

85-90: Consider debouncing search input for performance.

For better performance with large datasets, consider debouncing the search input:

+ import { useDebounce } from 'use-debounce';

const TopSearch: React.FC = () => {
  const [search, setSearch] = useState("");
+ const [debouncedSearch] = useDebounce(search, 300);

  const filteredCourts = useMemo(
    () =>
      data?.court ? flattenCourts(data.court).filter((c) => c.name.toLowerCase().includes(search.toLowerCase())) : [],
-    [data, search]
+    [data, debouncedSearch]
  );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ede3d4 and dcfc337.

📒 Files selected for processing (1)
  • web/src/pages/Courts/TopSearch.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Copy labels from linked issues
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
  • GitHub Check: contracts-testing
  • GitHub Check: dependency-review
🔇 Additional comments (2)
web/src/pages/Courts/TopSearch.tsx (2)

1-14: LGTM! Import statements are well-organized.

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


35-44: Consider responsive design implications.

The SearchBarContainer uses flex-wrap which is good for responsiveness, but ensure the absolute positioning of its child SearchResultsContainer works well on all screen sizes.

web/src/pages/Courts/TopSearch.tsx Outdated Show resolved Hide resolved
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.

Functionality wise looks good, but I would modify the dropdown, adding the custom scrollbar instead of the default one, and using another kind of card maybe 🤔 also, maybe we could show the parent court (entire path might be too much)? I can see a situation where there are 2 courts with the same name, but different parent courts.
image

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 (3)
web/src/pages/Courts/CourtDetails/TopSearch.tsx (3)

93-100: Consider memoizing the flattenCourts function.

The flattenCourts function is called within a useMemo hook but isn't memoized itself. Since it performs recursive operations, memoizing it could improve performance for large court hierarchies.

-function flattenCourts(court, parent = null) {
+const flattenCourts = React.useCallback((court, parent = null) => {
   const current = {
     ...court,
     parentName: parent?.name ?? null,
   };
   const children = (court.children || []).flatMap((child) => flattenCourts(child, current));
   return [current, ...children];
-}
+}, []);

110-117: Optimize search filtering performance.

The current implementation filters courts on every keystroke. Consider debouncing the search input to reduce unnecessary computations.

+import { useDebounce } from 'react-use';

 const TopSearch: React.FC = () => {
   const [search, setSearch] = useState("");
+  const debouncedSearch = useDebounce(search, 300);

   const filteredCourts = useMemo(() => {
     if (!data?.court) return [];
-    const courts = flattenCourts(data.court).filter((c) => c.name.toLowerCase().includes(search.toLowerCase()));
+    const courts = flattenCourts(data.court).filter((c) => c.name.toLowerCase().includes(debouncedSearch.toLowerCase()));
     const selectedCourt = courts.find((c) => c.id === currentCourtId);
     if (!selectedCourt) return courts;

     return [selectedCourt, ...courts.filter((c) => c.id !== currentCourtId)];
-  }, [data, search, currentCourtId]);
+  }, [data, debouncedSearch, currentCourtId]);

128-135: Add aria-label for better accessibility.

The search input should have an aria-label for screen readers.

 <StyledSearchbar
   dir="auto"
   type="text"
   placeholder="Search"
+  aria-label="Search courts"
   value={search}
   onChange={(e) => setSearch(e.target.value)}
 />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dcfc337 and 94b3a69.

📒 Files selected for processing (5)
  • web/src/components/Verdict/Answer.tsx (2 hunks)
  • web/src/components/Verdict/FinalDecision.tsx (1 hunks)
  • web/src/pages/Courts/CourtDetails/TopSearch.tsx (1 hunks)
  • web/src/pages/Courts/CourtDetails/index.tsx (2 hunks)
  • web/src/pages/Courts/index.tsx (0 hunks)
💤 Files with no reviewable changes (1)
  • web/src/pages/Courts/index.tsx
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Copy labels from linked issues
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
  • GitHub Check: dependency-review
  • GitHub Check: contracts-testing
  • GitHub Check: Mend Security Check
🔇 Additional comments (3)
web/src/components/Verdict/Answer.tsx (1)

5-5: LGTM! Component structure simplified.

The changes effectively simplify the component by removing unnecessary wrappers and using AnswerTitleAndDescription directly, which improves code maintainability.

Also applies to: 20-22

web/src/pages/Courts/CourtDetails/index.tsx (1)

28-28: LGTM! TopSearch component integrated.

The TopSearch component is properly integrated into the CourtDetails page, enhancing the user experience with search functionality.

Also applies to: 117-117

web/src/components/Verdict/FinalDecision.tsx (1)

38-44: LGTM! Simplified flex layout.

The changes improve the flex layout by:

  • Removing unnecessary flex-direction property
  • Moving flex-wrap to a new line for better readability
  • Removing redundant flex property

Copy link

codeclimate bot commented Jan 8, 2025

Code Climate has analyzed commit 605b082 and detected 5 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2
Duplication 3

View more on Code Climate.

Copy link

sonarqubecloud bot commented Jan 8, 2025

coderabbitai[bot]
coderabbitai bot previously requested changes Jan 8, 2025
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

♻️ Duplicate comments (1)
web/src/pages/Courts/CourtDetails/TopSearch.tsx (1)

139-155: 🛠️ Refactor suggestion

Add keyboard navigation for search results.

The search results can only be navigated using a mouse. Consider adding keyboard navigation for better accessibility.

🧹 Nitpick comments (3)
web/src/pages/Courts/CourtDetails/TopSearch.tsx (3)

60-71: Consider z-index management.

The SearchResultsContainer uses a hardcoded z-index value. Consider using a z-index management system to prevent potential stacking context issues.

+const Z_INDICES = {
+  searchResults: 100,
+  // ... other z-indices
+};

 const SearchResultsContainer = styled(OverlayScrollbarsComponent)`
   position: absolute;
   margin-top: 45px;
   max-height: 400px;
   border: 1px solid ${({ theme }) => theme.stroke};
   width: 100%;
   flex-direction: column;
   border-radius: 4px;
   overflow-y: auto;
-  z-index: 1;
+  z-index: ${Z_INDICES.searchResults};
   background-color: ${({ theme }) => theme.whiteBackground};
 `;

96-104: Add TypeScript types for better type safety.

The flattenCourts function would benefit from explicit TypeScript interfaces.

+interface Court {
+  id: string;
+  name: string;
+  children?: Court[];
+}
+
+interface FlattenedCourt extends Court {
+  parentName: string | null;
+}

-function flattenCourts(court, parent = null) {
+function flattenCourts(court: Court, parent: Court | null = null): FlattenedCourt[] {
   const current = {
     ...court,
     parentName: parent?.name ?? null,
   };
   const children = (court.children || []).flatMap((child) => flattenCourts(child, current));
   return [current, ...children];
 }

111-120: Optimize search performance with debouncing.

The search filtering runs on every keystroke. Consider adding debounce to improve performance, especially with large datasets.

+import { useMemo, useState, useCallback } from "react";
+import debounce from "lodash/debounce";

 const TopSearch: React.FC = () => {
   // ... existing code ...
   const [search, setSearch] = useState("");
+  const [debouncedSearch, setDebouncedSearch] = useState("");
+
+  const debouncedSetSearch = useCallback(
+    debounce((value: string) => {
+      setDebouncedSearch(value);
+    }, 300),
+    []
+  );

   const filteredCourts = useMemo(() => {
     if (!data?.court) return [];
-    const courts = flattenCourts(data.court).filter((c) => c.name.toLowerCase().includes(search.toLowerCase()));
+    const courts = flattenCourts(data.court).filter((c) => 
+      c.name.toLowerCase().includes(debouncedSearch.toLowerCase())
+    );
     const selectedCourt = courts.find((c) => c.id === currentCourtId);
     if (!selectedCourt) return courts;

     return [selectedCourt, ...courts.filter((c) => c.id !== currentCourtId)];
-  }, [data, search, currentCourtId]);
+  }, [data, debouncedSearch, currentCourtId]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 94b3a69 and 605b082.

📒 Files selected for processing (1)
  • web/src/pages/Courts/CourtDetails/TopSearch.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Copy labels from linked issues
  • GitHub Check: SonarCloud
  • GitHub Check: dependency-review
  • GitHub Check: Analyze (javascript)
  • GitHub Check: contracts-testing
🔇 Additional comments (1)
web/src/pages/Courts/CourtDetails/TopSearch.tsx (1)

1-22: LGTM! Well-organized imports.

The imports are logically grouped and all dependencies are necessary for the component's functionality.

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

@alcercu alcercu enabled auto-merge January 8, 2025 08:05
@alcercu alcercu added this pull request to the merge queue Jan 8, 2025
Merged via the queue into dev with commit 763ce33 Jan 8, 2025
27 of 29 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