-
Notifications
You must be signed in to change notification settings - Fork 43
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
Showing
7 changed files
with
334 additions
and
89 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
app/routes/circulars._archive._index/PaginationSelectionFooter.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,54 @@ | ||
import { useSubmit } from '@remix-run/react' | ||
import { Select } from '@trussworks/react-uswds' | ||
|
||
import CircularPagination from './CircularPagination' | ||
|
||
export default function ({ | ||
page, | ||
totalPages, | ||
limit, | ||
query, | ||
formId, | ||
}: { | ||
page: number | ||
totalPages: number | ||
limit?: number | ||
query?: string | ||
formId: string | ||
}) { | ||
const submit = useSubmit() | ||
return ( | ||
<div className="display-flex flex-row flex-wrap"> | ||
<div className="display-flex flex-align-self-center margin-right-2 width-auto"> | ||
<div> | ||
<Select | ||
id="limit" | ||
title="Number of results per page" | ||
className="width-auto height-5 padding-y-0 margin-y-0" | ||
name="limit" | ||
defaultValue="100" | ||
form={formId} | ||
onChange={({ target: { form } }) => { | ||
submit(form) | ||
}} | ||
> | ||
<option value="10">10 / page</option> | ||
<option value="20">20 / page</option> | ||
<option value="50">50 / page</option> | ||
<option value="100">100 / page</option> | ||
</Select> | ||
</div> | ||
</div> | ||
<div className="display-flex flex-fill"> | ||
{totalPages > 1 && ( | ||
<CircularPagination | ||
query={query} | ||
page={page} | ||
limit={limit} | ||
totalPages={totalPages} | ||
/> | ||
)} | ||
</div> | ||
</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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import type { LoaderFunctionArgs } from '@remix-run/node' | ||
import { | ||
Form, | ||
Link, | ||
useLoaderData, | ||
useSearchParams, | ||
useSubmit, | ||
} from '@remix-run/react' | ||
import { | ||
Button, | ||
Grid, | ||
GridContainer, | ||
Icon, | ||
Label, | ||
TextInput, | ||
} from '@trussworks/react-uswds' | ||
import { useId, useState } from 'react' | ||
|
||
import PaginationSelectionFooter from './circulars._archive._index/PaginationSelectionFooter' | ||
import type { SynonymGroup } from './synonyms/synonyms.lib' | ||
import { searchSynonymsByEventId } from './synonyms/synonyms.server' | ||
import { ToolbarButtonGroup } from '~/components/ToolbarButtonGroup' | ||
|
||
import searchImg from 'nasawds/src/img/usa-icons-bg/search--white.svg' | ||
|
||
export async function loader({ request: { url } }: LoaderFunctionArgs) { | ||
const { searchParams } = new URL(url) | ||
const query = searchParams.get('query') || undefined | ||
const limit = parseInt(searchParams.get('limit') || '100') | ||
const page = parseInt(searchParams.get('page') || '1') | ||
const synonyms = searchSynonymsByEventId({ page, eventId: query, limit }) | ||
return synonyms | ||
} | ||
|
||
function SynonymList({ synonyms }: { synonyms: SynonymGroup[] }) { | ||
return ( | ||
<> | ||
<ul> | ||
{synonyms.map((synonym) => { | ||
return ( | ||
<li key={synonym.synonymId}> | ||
<Link to={`/synonyms/${synonym.synonymId}`}> | ||
{' '} | ||
{synonym.eventIds.join(', ')} | ||
</Link> | ||
</li> | ||
) | ||
})} | ||
</ul> | ||
</> | ||
) | ||
} | ||
export default function () { | ||
const { synonyms, page, totalPages } = useLoaderData<typeof loader>() | ||
const submit = useSubmit() | ||
const formId = useId() | ||
const [searchParams] = useSearchParams() | ||
const limit = searchParams.get('limit') || '100' | ||
const query = searchParams.get('query') || '' | ||
|
||
let searchString = searchParams.toString() | ||
if (searchString) searchString = `?${searchString}` | ||
|
||
const [inputQuery, setInputQuery] = useState('') | ||
|
||
return ( | ||
<> | ||
<h1>Synonym Group Moderation</h1> | ||
<GridContainer> | ||
<Grid row> | ||
<ToolbarButtonGroup className="position-sticky top-0 bg-white margin-bottom-1 padding-top-1 z-300"> | ||
<Form | ||
preventScrollReset | ||
className="display-inline-block usa-search usa-search--small" | ||
role="search" | ||
id={formId} | ||
> | ||
<Label srOnly htmlFor="query"> | ||
Search | ||
</Label> | ||
<TextInput | ||
autoFocus | ||
className="minw-15" | ||
id="query" | ||
name="query" | ||
type="search" | ||
defaultValue={inputQuery} | ||
placeholder="Search" | ||
aria-describedby="searchHint" | ||
onChange={({ target: { form, value } }) => { | ||
setInputQuery(value) | ||
if (!value) submit(form, { preventScrollReset: true }) | ||
}} | ||
/> | ||
<Button type="submit"> | ||
<img | ||
src={searchImg} | ||
className="usa-search__submit-icon" | ||
alt="Search" | ||
/> | ||
</Button> | ||
</Form> | ||
<Link to="/synonyms/new"> | ||
<Button type="button" className="padding-y-1"> | ||
<Icon.Edit role="presentation" /> New | ||
</Button> | ||
</Link> | ||
</ToolbarButtonGroup> | ||
</Grid> | ||
</GridContainer> | ||
<SynonymList synonyms={synonyms} /> | ||
<PaginationSelectionFooter | ||
query={query} | ||
page={page} | ||
totalPages={totalPages} | ||
limit={parseInt(limit)} | ||
formId={formId} | ||
/> | ||
</> | ||
) | ||
} |
Oops, something went wrong.