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 a search component #38

Closed
wants to merge 2 commits into from
Closed

Add a search component #38

wants to merge 2 commits into from

Conversation

santoshyadavdev
Copy link
Owner

@santoshyadavdev santoshyadavdev commented Dec 24, 2024

Add a search component to the portfolio.

  • New Search Component: Create src/components/search.astro to implement search functionality using Lunr.js. Index markdown files and display search results dynamically.
  • Header Component: Modify src/components/header.astro to import and include the new search component.
  • Left Sidebar Component: Modify src/components/leftsidebar.astro to import and include the new search component.
  • Right Sidebar Component: Modify src/components/rightsidebar.astro to import and include the new search component.
  • Devcontainer Configuration: Add .devcontainer/devcontainer.json to configure the development container.

For more details, open the Copilot Workspace session.

Summary by CodeRabbit

  • New Features

    • Introduced a new Search component for enhanced search capabilities in the header, left sidebar, and right sidebar.
    • Added a "launch" task to automate application startup in the development environment.
  • Bug Fixes

    • Replaced the previous Theme component in the header with the new Search component for improved navigation functionality.

Add a search component to the portfolio.

* **New Search Component**: Create `src/components/search.astro` to implement search functionality using Lunr.js. Index markdown files and display search results dynamically.
* **Header Component**: Modify `src/components/header.astro` to import and include the new search component.
* **Left Sidebar Component**: Modify `src/components/leftsidebar.astro` to import and include the new search component.
* **Right Sidebar Component**: Modify `src/components/rightsidebar.astro` to import and include the new search component.
* **Devcontainer Configuration**: Add `.devcontainer/devcontainer.json` to configure the development container.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/santoshyadavdev/portfolio?shareId=XXXX-XXXX-XXXX-XXXX).
Copy link

coderabbitai bot commented Dec 24, 2024

Warning

Rate limit exceeded

@santoshyadavdev has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 7 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 61f7817 and abdb384.

📒 Files selected for processing (4)
  • src/components/header.astro (2 hunks)
  • src/components/leftsidebar.astro (2 hunks)
  • src/components/rightsidebar.astro (2 hunks)
  • src/components/search.astro (1 hunks)

Walkthrough

This pull request introduces a new search functionality across multiple components by adding a Search component to the project. The component is implemented using React hooks and Lunr.js for client-side search capabilities. The search feature is integrated into the header, left sidebar, and right sidebar, replacing the previous theme component. Additionally, a new development container task is added to simplify application startup.

Changes

File Change Summary
.devcontainer/devcontainer.json Added a new "launch" task to execute yarn start
src/components/header.astro Imported and added Search component, replacing Theme component
src/components/leftsidebar.astro Imported and added Search component within the main div
src/components/rightsidebar.astro Imported and added Search component in the nav element
src/components/search.astro Created new React component with search functionality using Lunr.js

Sequence Diagram

sequenceDiagram
    participant User
    participant SearchComponent
    participant SearchIndex
    
    User->>SearchComponent: Enter search query
    SearchComponent->>SearchIndex: Fetch search index
    SearchIndex-->>SearchComponent: Return index data
    SearchComponent->>SearchComponent: Construct Lunr index
    User->>SearchComponent: Type search query
    SearchComponent->>SearchComponent: Perform search
    SearchComponent-->>User: Display search results
Loading

Possibly related PRs

  • add substack #37: Introduces a new component in src/components/newsletter.astro, suggesting similar UI enhancement efforts

Poem

🐰 A search bar hops into view,
Lunr.js magic, results so true!
Sidebars dance with newfound might,
Searching docs becomes a delight!
Code rabbits rejoice, knowledge near! 🔍


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

netlify bot commented Dec 24, 2024

Deploy Preview for santoshyadav failed. Why did it fail? →

Name Link
🔨 Latest commit abdb384
🔍 Latest deploy log https://app.netlify.com/sites/santoshyadav/deploys/676af1f1854c800008f4286c

Copy link

@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 (2)
src/components/search.astro (2)

29-39: Avoid referencing data outside local scope in map callback.
Within line 35, data is out of scope if fetched data is not stored in a local variable. You might consider storing the JSON data in a local state.

-const [results, setResults] = useState([]);
+const [results, setResults] = useState<DocumentType[]>([]);
+const [docs, setDocs] = useState<DocumentType[]>([]);

...
useEffect(() => {
  // ...
  setDocs(data);
}, []);

...
if (index) {
  const newResults = index.search(query).map(({ ref }) => {
-    return data.find((doc) => doc.id === ref);
+    return docs.find((doc) => doc.id === ref);
  });
  setResults(newResults);
}

41-59: UI is straightforward and accessible.
Good job providing a placeholder. Consider adding ARIA labels for better accessibility.

<input
  type="text"
  value={query}
  onChange={handleSearch}
  placeholder="Search..."
+ aria-label="Search text"
  />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4cda9bf and 61f7817.

📒 Files selected for processing (5)
  • .devcontainer/devcontainer.json (1 hunks)
  • src/components/header.astro (2 hunks)
  • src/components/leftsidebar.astro (2 hunks)
  • src/components/rightsidebar.astro (2 hunks)
  • src/components/search.astro (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .devcontainer/devcontainer.json
🔇 Additional comments (8)
src/components/rightsidebar.astro (2)

4-4: Import readability and overall approach look good.
Proactively verifying the path usage ensures no duplication or cyclical imports.


20-20: Nice addition of the <Search /> component in the sidebar.
This helps users quickly find content. No issues noted.

src/components/search.astro (2)

2-4: Validation for external libraries or fallback.
Using useState, useEffect, and lunr is fine. However, consider verifying the environment supports these dependencies. If users have JavaScript disabled or if SSR usage is desired in certain builds, you may need a fallback.


5-8: State declarations appear correct.
The states manage query, results, and index effectively.

src/components/leftsidebar.astro (2)

3-3: Import path is consistent.
No issues with the import syntax.


16-16: Great addition of the <Search /> component.
Aligns well with the sidebar structure and enhances user experience.

src/components/header.astro (2)

6-6: Consistent import reference.
Ensures each location uses the same component.


76-76: Coexistence of <Theme /> and <Search />.
Having both theming and search in the header is beneficial. Verify the layout does not create UI clutter.

Comment on lines 10 to 27
useEffect(() => {
const fetchData = async () => {
const response = await fetch('/search-index.json');
const data = await response.json();
const idx = lunr(function () {
this.ref('id');
this.field('title');
this.field('content');

data.forEach((doc) => {
this.add(doc);
});
});
setIndex(idx);
};

fetchData();
}, []);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure error handling around fetching search data.
If the JSON file fails to load, it might break the search. Add try/catch or handle a non-200 response from the fetch for better resiliency.

 useEffect(() => {
   const fetchData = async () => {
     try {
       const response = await fetch('/search-index.json');
+      if (!response.ok) {
+        console.error("Failed to fetch search index:", response.statusText);
+        return;
+      }
       const data = await response.json();
       // ...
     } catch (error) {
+      console.error("Error fetching search index:", error);
     }
   };
   fetchData();
 }, []);

Committable suggestion skipped: line range outside the PR's diff.

* **header.astro**
  - Import Alpine.js
  - Add search input field with Alpine.js bindings

* **leftsidebar.astro**
  - Add search input field with Alpine.js bindings

* **rightsidebar.astro**
  - Add search input field with Alpine.js bindings

* **search.astro**
  - Replace React state and effects with Alpine.js
  - Add search input field and results section with Alpine.js bindings
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.

1 participant