-
Notifications
You must be signed in to change notification settings - Fork 27
Add community skills search, pagination, and an "Add your skill" section #34
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
Open
kaankacar
wants to merge
8
commits into
main
Choose a base branch
from
33-community-skills-search-pagination-and-an-add-your-skill-section
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
97dc0d9
Add community skills search, pagination, and an "Add your skill" section
kaankacar 2d5fb7d
Drop the unused category field from ecosystem entries
kaankacar 07c77a5
Match search width to the card column and show a result count
kaankacar 500e2a4
Size the community count line like the card descriptions
kaankacar 286c31a
Potential fix for pull request finding
kaankacar 69eafc7
Size the community count line as a caption, not body text
kaankacar 1f0badd
Style the community count line at 14px semibold
kaankacar a915c31
Match the community count line color to the card titles (gray-12)
kaankacar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| "use client"; | ||
|
|
||
| import { Children, ReactNode, useId, useState } from "react"; | ||
|
|
||
| import { Input, Pagination } from "@stellar/design-system"; | ||
|
|
||
| /** Cards shown per page in the 2-column community grid. */ | ||
| const PAGE_SIZE = 8; | ||
|
|
||
| type Props = { | ||
| /** Lowercased "title description" haystack for each child, in the | ||
| * same render order as `children`. Search runs against these strings | ||
| * so the cards themselves stay server-rendered; this island only | ||
| * toggles wrapper visibility. */ | ||
| searchTexts: readonly string[]; | ||
| /** Pre-rendered card markup (server). One child per searchTexts | ||
| * entry, same order. */ | ||
| children: ReactNode; | ||
| }; | ||
|
|
||
| /** | ||
| * Client island that adds search and pagination to the community | ||
| * skills grid. The cards render server-side and are passed in as | ||
| * `children` (same slot pattern as `SkillsFilter`), so every card's | ||
| * title/description/link stays in the static HTML for non-JS clients; | ||
| * this component only hides wrappers that don't match the query or | ||
| * fall outside the current page. | ||
| * | ||
| * Search matches a case-insensitive substring of the card title or any | ||
| * part of its description, so a query like "DEX" finds a card that | ||
| * only mentions it mid-description. | ||
| */ | ||
| export const CommunitySearch = ({ searchTexts, children }: Props) => { | ||
| const searchInputId = useId(); | ||
| const [query, setQuery] = useState(""); | ||
| const [page, setPage] = useState(1); | ||
|
|
||
| const needle = query.trim().toLowerCase(); | ||
| const matches = searchTexts.reduce<number[]>((acc, text, index) => { | ||
| if (text.includes(needle)) acc.push(index); | ||
| return acc; | ||
| }, []); | ||
|
|
||
| // Clamp instead of trusting `page`: a new query can shrink the match | ||
| // list below the previously selected page. | ||
| const pageCount = Math.max(1, Math.ceil(matches.length / PAGE_SIZE)); | ||
| const currentPage = Math.min(page, pageCount); | ||
| const visible = new Set( | ||
| matches.slice((currentPage - 1) * PAGE_SIZE, currentPage * PAGE_SIZE), | ||
| ); | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="SkillsLanding__communitySearch"> | ||
| <Input | ||
| id={searchInputId} | ||
| fieldSize="md" | ||
| type="search" | ||
| placeholder="Search community skills" | ||
| aria-label="Search community skills by title or description" | ||
| value={query} | ||
| onChange={(event) => { | ||
| setQuery(event.target.value); | ||
| setPage(1); | ||
| }} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="SkillsLanding__ecosystemGrid"> | ||
| {Children.map(children, (child, index) => ( | ||
| <div | ||
| key={index} | ||
| className="SkillsLanding__communityItem" | ||
| data-hidden={!visible.has(index)} | ||
| > | ||
| {child} | ||
| </div> | ||
| ))} | ||
| </div> | ||
|
|
||
| {matches.length === 0 && ( | ||
| <p className="SkillsLanding__communityEmpty"> | ||
| No community skills match your search. | ||
| </p> | ||
| )} | ||
|
|
||
| <p | ||
| className="SkillsLanding__communityCount" | ||
| role="status" | ||
| aria-live="polite" | ||
| > | ||
| Showing {visible.size} of {searchTexts.length} skill | ||
| {searchTexts.length === 1 ? "" : "s"} | ||
| </p> | ||
|
|
||
| {matches.length > PAGE_SIZE && ( | ||
| <div className="SkillsLanding__communityPagination"> | ||
| <Pagination | ||
| pageSize={PAGE_SIZE} | ||
| itemCount={matches.length} | ||
| currentPage={currentPage} | ||
| setCurrentPage={setPage} | ||
| /> | ||
| </div> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.