-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ search functionality somewhat working
- Loading branch information
1 parent
116176c
commit 306ee0d
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
website/similar-react-native-libraries/components/search_component/SearchComponent.tsx
This file contains 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 @@ | ||
// src/components/SearchComponent.tsx | ||
import React, { useState, useEffect, ChangeEvent } from 'react'; | ||
import debounce from 'lodash/debounce'; | ||
import jsonData from '../../../../category-selector/data/combinedFromChunks.json'; // Adjust the path to your JSON file | ||
|
||
interface GithubData { | ||
githubUrl: string; | ||
npmPkg: string; | ||
examples?: string[]; | ||
ios?: boolean; | ||
android?: boolean; | ||
expoGo?: boolean; | ||
github?: { | ||
urls?: { | ||
repo?: string; | ||
clone?: string; | ||
homepage?: string; | ||
}; | ||
stats?: { | ||
hasIssues?: boolean; | ||
hasWiki?: boolean; | ||
hasPages?: boolean; | ||
hasDownloads?: boolean; | ||
hasTopics?: boolean; | ||
updatedAt?: string; | ||
createdAt?: string; | ||
pushedAt?: string; | ||
forks?: number; | ||
issues?: number; | ||
subscribers?: number; | ||
stars?: number; | ||
}; | ||
name?: string; | ||
fullName?: string; | ||
description?: string; | ||
topics?: string[]; | ||
license?: { | ||
key?: string; | ||
name?: string; | ||
spdxId?: string; | ||
url?: string; | ||
id?: string; | ||
}; | ||
lastRelease?: { | ||
name?: string; | ||
tagName?: string; | ||
createdAt?: string; | ||
publishedAt?: string; | ||
isPrerelease?: boolean; | ||
}; | ||
hasTypes?: boolean; | ||
newArchitecture?: boolean; | ||
}; | ||
images?: string[]; | ||
npm?: { | ||
downloads?: number; | ||
weekDownloads?: number; | ||
start?: string; | ||
end?: string; | ||
period?: string; | ||
}; | ||
score?: number; | ||
matchingScoreModifiers?: string[]; | ||
popularity?: number; | ||
topicSearchString?: string; | ||
matchScore?: number; | ||
category?: string[]; | ||
uniqueCategory?: string; | ||
} | ||
|
||
const SearchComponent: React.FC = () => { | ||
const [query, setQuery] = useState<string>(''); | ||
const [result, setResult] = useState<GithubData | null>(null); | ||
|
||
const handleSearch = debounce((searchTerm: string) => { | ||
if (searchTerm) { | ||
const item = (jsonData as { [key: string]: GithubData })[searchTerm]; | ||
setResult(item || null); | ||
} else { | ||
setResult(null); | ||
} | ||
}, 300); | ||
|
||
useEffect(() => { | ||
handleSearch(query); | ||
}, [query]); | ||
|
||
const handleChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setQuery(e.target.value); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<input type="text" value={query} onChange={handleChange} placeholder="Enter GitHub URL" /> | ||
{result ? ( | ||
<div> | ||
<h2>{result.github.name}</h2> | ||
<p>{result.github.description}</p> | ||
{/* Display other relevant data from the JSON object as needed */} | ||
</div> | ||
) : ( | ||
query && <p>No results found</p> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SearchComponent; |
This file contains 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 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