-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8affbe2
commit a4b367c
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.wrapper { | ||
text-align: center; | ||
margin-bottom: $spacing-xxs; | ||
} | ||
|
||
.heading { | ||
|
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,31 @@ | ||
import { useQuery } from "@apollo/client"; | ||
|
||
import { SearchResultItemEdge } from "@/lib/types/githubTypes"; | ||
import searchRepositories from "@/lib/queries/searchRepositories"; | ||
import RepositoryItem from "./repositoryItem"; | ||
|
||
interface SearchResultsProps { | ||
searchTerm?: string; | ||
} | ||
|
||
export default function SearchResults({ searchTerm }: SearchResultsProps) { | ||
const { loading, error, data } = useQuery(searchRepositories, { | ||
variables: { | ||
// TODO: Add use-debounce | ||
search_term: searchTerm, | ||
}, | ||
}); | ||
|
||
if (loading && searchTerm) return <p>Loading...</p>; | ||
if (error) return <p>Error: error(</p>; | ||
|
||
return ( | ||
<div> | ||
{data?.search?.edges.map(({ node }: SearchResultItemEdge) => { | ||
if (!node?.id) return; | ||
|
||
return <RepositoryItem key={node.id} repository={node} />; | ||
})} | ||
</div> | ||
); | ||
} |
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,41 @@ | ||
import Link from "next/link"; | ||
import { Repository } from "@/lib/types/githubTypes"; | ||
|
||
import styles from "./repositoryItem.module.scss"; | ||
|
||
// interface RepositoryProps { | ||
// name: string; | ||
// description?: string; | ||
// owner: { login: string }; | ||
// primaryLanguage: string; | ||
// stargazers: { totalCount: string }; | ||
// } | ||
|
||
interface RepositoryItemProps { | ||
key: string; | ||
repository: Repository; | ||
} | ||
|
||
export default function RepositoryItem({ repository }: RepositoryItemProps) { | ||
const { | ||
name, | ||
description, | ||
owner: { login }, | ||
primaryLanguage, | ||
stargazers: { totalCount }, | ||
} = repository; | ||
|
||
return ( | ||
<article className={styles.card}> | ||
<div className={styles.heading}> | ||
<Link href={`/${login}/${name}`}> | ||
<a className={styles.title}>{name}</a> | ||
</Link> | ||
</div> | ||
<span className={styles.owner}> | ||
<small>by</small> {login}{" "} | ||
</span> | ||
{description && <p className={styles.description}>{description}</p>} | ||
</article> | ||
); | ||
} |
Empty file.
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