Skip to content

Commit 0f267ae

Browse files
committed
Add some more detail to the search results
1 parent 5f5df59 commit 0f267ae

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ The code can be found in `./src`. It uses [React Router](https://reactrouter.com
3131

3232
This project is enhanced as a [FAB](https://fab.dev/), which allows us to sprinkle in some server-side functionality. These plugins can be found in the `./api` folder. Right now, there's just a mock GraphQL server, but in the future, we could use this for user authorization etc.
3333

34+
To run the full FAB build (which is as close to production as you can get), `npm run build:fab && npx fab serve`
35+
3436
## Testing
3537

3638
Pretty minimal at this point, but CRA comes with [Jest](https://jestjs.io/) built-in and there's one example in `./src/App.test.tsx`.

src/components/SearchResults.tsx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
import { QueryResult } from "@apollo/client";
2-
import { Search } from "../pages/__generated__/Search";
2+
import {
3+
Search,
4+
Search_search_documents_edges_node,
5+
} from "../pages/__generated__/Search";
6+
7+
const SearchResult = ({
8+
node,
9+
}: {
10+
node: Search_search_documents_edges_node;
11+
}) => (
12+
<li className="py-4" key={node.id}>
13+
<a className="text-lg leading-6 font-medium text-gray-500" href={node.url}>
14+
{node.name}
15+
</a>
16+
<p className="mt-1 text-sm text-gray-500">{node.description}</p>
17+
<p className="text-xs text-gray-500 text-right">
18+
Sourced from{" "}
19+
<a
20+
className="font-medium"
21+
href={node.externalSource.url}
22+
rel="noopener noreferrer"
23+
target="_blank"
24+
>
25+
{node.externalSource.name}
26+
</a>
27+
</p>
28+
</li>
29+
);
330

431
export const SearchResults = ({
532
loading,
@@ -9,11 +36,12 @@ export const SearchResults = ({
936
if (loading) return <div>Loading...</div>;
1037
if (error) return <div>Error: {JSON.stringify(error)}</div>;
1138

39+
const documentEdges = data?.search.documents.edges || [];
1240
return (
1341
<ul className="divide-y divide-gray-200">
14-
{data?.search.documents.edges?.map(edge => (
15-
<li className="py-4">{edge?.node?.name}</li>
16-
))}
42+
{documentEdges.map(
43+
edge => edge?.node && <SearchResult node={edge.node} />
44+
)}
1745
</ul>
1846
);
1947
};

src/pages/Home.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ const SEARCH = gql`
1313
documents {
1414
edges {
1515
node {
16+
id
1617
name
1718
description
1819
url
20+
externalSource {
21+
id
22+
name
23+
description
24+
url
25+
}
1926
}
2027
}
2128
}

src/pages/__generated__/Search.ts

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)