Skip to content

Commit

Permalink
Added user-query package and updated components
Browse files Browse the repository at this point in the history
  • Loading branch information
c3ho committed Jan 20, 2021
1 parent 992b756 commit 8ded959
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/frontend/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-use": "^15.3.8",
"swr": "^0.4.0"
"swr": "^0.4.0",
"use-query-params": "^1.1.9"
},
"devDependencies": {
"@types/node": "^14.14.8",
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/next/src/components/SearchPage/SearchPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, FormEvent, useState } from 'react';
import { FormEvent, useState } from 'react';
import { useQueryParam, StringParam } from 'use-query-params';
import { makeStyles } from '@material-ui/core/styles';

Expand All @@ -13,7 +13,7 @@ const useStyles = makeStyles(() => ({
},
}));

export const SearchPage: FC = () => {
export const SearchPage = () => {
const classes = useStyles();
// We synchronize the `text` and `filter` values to the URL's query string
// via `textParam` and `filterParam`. The <SearchBar> UI uses our internal
Expand Down
18 changes: 3 additions & 15 deletions src/frontend/next/src/components/SearchPage/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,9 @@ import useSiteMetadata from '../../hooks/use-site-metadata';
import Timeline from '../Posts/Timeline.jsx';
import Spinner from '../Spinner';

// Need below to disable some upper scope issue
// eslint-disable-next-line no-shadow
enum Filter {
Post,
Author,
}

/* This combined with the above will only allow either the string 'Post' or 'Author'.
See https://www.typescriptlang.org/docs/handbook/enums.html for more info */
type FilterStrings = keyof typeof Filter;

type SearchPageProps = {
text: string | null;
filter: FilterStrings;
filter: string | null;
};

const useStyles = makeStyles(() => ({
Expand All @@ -36,12 +25,11 @@ const useStyles = makeStyles(() => ({
const SearchResults = ({ text, filter }: SearchPageProps) => {
const classes = useStyles();
const { telescopeUrl } = useSiteMetadata();
const prepareUrl = (index: number) => {
return text
const prepareUrl = (index: number) =>
text
? `${telescopeUrl}/query?text=${encodeURIComponent(text)}&filter=${filter}&page=${index}`
: // Should we return an empty string? or null here?
null;
};

// We only bother doing the request if we have something to search for.
// Can't do optional chaining below on text only because text could be null
Expand Down

0 comments on commit 8ded959

Please sign in to comment.