[search][xl]: initial search page with essential components.
- No pagination at the moment. - Sorting isn't functional yet. - Search works - we only have mocks for searching 'gdp' param.
This commit is contained in:
33
components/search/Input.tsx
Normal file
33
components/search/Input.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/router'
|
||||
import Link from 'next/link'
|
||||
|
||||
export default function Input({ query }) {
|
||||
const router = useRouter()
|
||||
const [q, setQ] = useState(query.q)
|
||||
|
||||
const handleChange = (event) => {
|
||||
setQ(event.target.value)
|
||||
}
|
||||
|
||||
const handleSubmit = (event) => {
|
||||
event.preventDefault()
|
||||
router.push({
|
||||
pathname: '/search',
|
||||
query: { q },
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<input
|
||||
type='text'
|
||||
name='q'
|
||||
value={q}
|
||||
onChange={handleChange}
|
||||
placeholder='Search'
|
||||
aria-label='Search'
|
||||
/>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
21
components/search/Item.tsx
Normal file
21
components/search/Item.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import Link from 'next/link'
|
||||
|
||||
export default function Item({ datapackage }) {
|
||||
return (
|
||||
<div>
|
||||
<h3 className="text-2xl font-semibold">
|
||||
<Link href={`/@${datapackage.organization ? datapackage.organization.name : 'dataset'}/${datapackage.name}`}>
|
||||
<a className="text-primary">{ datapackage.title || datapackage.name }</a>
|
||||
</Link>
|
||||
</h3>
|
||||
<Link href={`/@${datapackage.organization ? datapackage.organization.name : 'dataset'}`}>
|
||||
<a className="text-gray-500 block mt-1">
|
||||
{ datapackage.organization ? datapackage.organization.title : 'dataset' }
|
||||
</a>
|
||||
</Link>
|
||||
<div className="leading-relaxed mt-2">
|
||||
{ datapackage.description }
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
9
components/search/List.tsx
Normal file
9
components/search/List.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import Item from './Item'
|
||||
|
||||
export default function List({ datapackages }) {
|
||||
return (
|
||||
<ul>
|
||||
{datapackages.map((datapackage, index) => <Item datapackage={datapackage} key={index} />)}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
14
components/search/Sort.tsx
Normal file
14
components/search/Sort.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
export default function Sort({ selected }) {
|
||||
return (
|
||||
<div>
|
||||
<label htmlFor="field-order-by">Order by:</label>
|
||||
<select className="bg-white" id="field-order-by" name="sort">
|
||||
<option value="score:desc">Relevance</option>
|
||||
<option value="title_string:asc">Name Ascending</option>
|
||||
<option value="title_string:desc">Name Descending</option>
|
||||
<option value="metadata_modified:desc">Last Modified</option>
|
||||
<option value="views_recent:desc">Popular</option>
|
||||
</select>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
3
components/search/Total.tsx
Normal file
3
components/search/Total.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function Total({ total }) {
|
||||
return <h1 className="text-4xl font-semibold text-primary">{ total } results found</h1>
|
||||
}
|
||||
Reference in New Issue
Block a user