Skip to content

Commit eac37c6

Browse files
committed
(refactor) - move to click-based search instead of keystroke
1 parent 216dba4 commit eac37c6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/components/Link.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ const Link = ({ link, index }) => {
2727
const [{ fetching }, executeMutation] = useMutation(VOTE_MUTATION);
2828

2929
const voteMutation = React.useCallback(() => {
30-
executeMutation({ linkId: link.id });
31-
}, [link, executeMutation]);
30+
if (!fetching) {
31+
executeMutation({ linkId: link.id });
32+
}
33+
}, [fetching, link, executeMutation]);
3234

3335
return (
3436
<div className="flex mt2 items-start">

src/components/Search.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ const FEED_SEARCH_QUERY = gql`
2828

2929
const Search = () => {
3030
const [filter, setFilter] = React.useState('');
31-
const [result] = useQuery({ query: FEED_SEARCH_QUERY, variables: { filter} });
31+
const [result, executeQuery] = useQuery({ query: FEED_SEARCH_QUERY, variables: { filter}, pause: true });
32+
33+
const links = result.data ? result.data.feed.links : [];
34+
const search = React.useCallback(() => {
35+
executeQuery();
36+
}, [executeQuery]);
3237

3338
return (
3439
<div>
@@ -38,8 +43,9 @@ const Search = () => {
3843
type="text"
3944
onChange={e => setFilter(e.target.value)}
4045
/>
46+
<button onClick={search}>search</button>
4147
</div>
42-
{result.data && result.data.feed && result.data.feed.links.map((link, index) => (
48+
{links.map((link, index) => (
4349
<Link key={link.id} link={link} index={index} />
4450
))}
4551
</div>

0 commit comments

Comments
 (0)