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 search bar #130

Merged
merged 2 commits into from
Dec 11, 2024
Merged

feat : add search bar #130

merged 2 commits into from
Dec 11, 2024

Conversation

NelsonKCT
Copy link
Contributor

@NelsonKCT NelsonKCT commented Dec 3, 2024

Screenshot 2024-12-03 at 7 49 52 PM Screenshot 2024-12-03 at 7 50 10 PM Screenshot 2024-12-03 at 7 50 02 PM

Summary by CodeRabbit

  • New Features

    • Introduced a search functionality for filtering events based on user input.
    • Added a search input field with placeholder text and a clear button.
  • Bug Fixes

    • Improved error handling logic for data fetching.
  • Documentation

    • Enhanced code formatting for better readability.

Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

Walkthrough

The changes in the src/routes/events/index.tsx file enhance the event listing component by introducing a search feature. This includes updates to import statements, the addition of local state management for the search functionality, and modifications to the rendering logic to filter events based on user input. The loader function has been streamlined, and the overall code formatting has been improved for better readability. The user interface now allows users to search for events dynamically while keeping the existing layout intact.

Changes

File Path Change Summary
src/routes/events/index.tsx Updated import statements to include Search icon; added useState for search functionality; reformatted Event interface; streamlined loader function; introduced searchTerm and isFocused state variables; modified rendering logic to use filteredEvents; added search input field with placeholder and clear button; improved code formatting.

Poem

In a meadow where events abound,
A search feature now can be found.
With a term to type and a button to clear,
Finding fun is now oh-so-near!
Hops of joy for the updates made,
In our lively event parade! 🐇✨


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.

@1989ONCE 1989ONCE self-requested a review December 3, 2024 11:58
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 (3)
src/routes/events/index.tsx (3)

24-29: Consider implementing server-side pagination and search

The current implementation fetches all events at once, which could lead to performance issues as the dataset grows. Consider:

  1. Implementing pagination to limit the initial data load
  2. Moving the search functionality to the server-side to reduce client-side data processing

Example implementation:

const ITEMS_PER_PAGE = 20;

loader: async ({ search = '', page = 1 }) => {
  const { data, error } = await supabase
    .from('events')
    .select('*')
    .ilike('name', `%${search}%`)
    .range((page - 1) * ITEMS_PER_PAGE, page * ITEMS_PER_PAGE - 1);
  
  if (error) throw error;
  return { events: data };
}

Line range hint 79-90: Avoid duplicate event rendering

The same filtered events are being rendered twice in different sections ("最新揪人" and "最新活動"). Consider:

  1. Differentiating the events for each section
  2. Using separate filtered arrays based on event type or category
const recentInvites = filteredEvents.filter(event => event.type === 'invite');
const recentEvents = filteredEvents.filter(event => event.type === 'event');

134-136: Improve null date handling

Using current date as fallback for null start_time might be misleading. Consider showing a placeholder or "TBD" instead.

- const startTime = event.start_time
-   ? new Date(event.start_time)
-   : new Date();
+ const startTime = event.start_time
+   ? new Date(event.start_time)
+   : null;

// In the render section:
{startTime ? startTime.toLocaleString('zh-TW', {
  month: '2-digit',
  day: '2-digit',
  hour: '2-digit',
  minute: '2-digit',
}) : '時間未定'}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 51c298f and 79c6b62.

📒 Files selected for processing (1)
  • src/routes/events/index.tsx (5 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/routes/events/index.tsx

[error] 43-44: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (2)
src/routes/events/index.tsx (2)

2-3: LGTM! Clean imports and well-structured interface

The new imports support the search functionality, and the Event interface is properly typed with all necessary fields.

Also applies to: 9-18


51-73: LGTM! Well-implemented search bar UI

The search bar implementation includes good UX features:

  • Clear button when text is present
  • Placeholder text handling based on focus state
  • Proper positioning of search icon and placeholder

Comment on lines +41 to +45
const filteredEvents = events.filter(
(event) =>
event.name &&
event.name.toLowerCase().includes(searchTerm.toLowerCase())
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve event filtering logic

The current filtering logic has potential issues:

  1. Doesn't handle null event names properly
  2. Could use optional chaining as suggested by static analysis
- const filteredEvents = events.filter(
-   (event) =>
-     event.name &&
-     event.name.toLowerCase().includes(searchTerm.toLowerCase())
- );
+ const filteredEvents = events.filter((event) =>
+   event.name?.toLowerCase().includes(searchTerm.toLowerCase()) ?? false
+ );
📝 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 filteredEvents = events.filter(
(event) =>
event.name &&
event.name.toLowerCase().includes(searchTerm.toLowerCase())
);
const filteredEvents = events.filter((event) =>
event.name?.toLowerCase().includes(searchTerm.toLowerCase()) ?? false
);
🧰 Tools
🪛 Biome (1.9.4)

[error] 43-44: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

@1989ONCE 1989ONCE added the enhancement New feature or request label Dec 3, 2024
Copy link
Member

@1989ONCE 1989ONCE left a comment

Choose a reason for hiding this comment

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

Great!

@1989ONCE 1989ONCE merged commit 231a57d into NCUAppTeam:main Dec 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

2 participants