[catalog][m]: re-implemented search page using TailwindUI.

This commit is contained in:
anuveyatsu 2021-08-14 13:09:53 +06:00
parent b0ee6b4c71
commit e8f9d2bc8e
5 changed files with 57 additions and 12 deletions

View File

@ -1,7 +0,0 @@
import { Item } from 'portal';
const SearchItem: React.FC<{ datapackage: any }> = ({ datapackage }) => {
return <Item dataset={datapackage} />;
};
export default SearchItem;

View File

@ -1,5 +1,6 @@
import { useQuery } from '@apollo/react-hooks';
import Item from './Item';
import Link from 'next/link';
import * as timeago from 'timeago.js';
import { ErrorMessage } from '../_shared';
import { SEARCH_QUERY } from '../../graphql/queries';
@ -16,9 +17,53 @@ const List: React.FC<{ variables: any }> = ({ variables }) => {
if (loading) return <div>Loading</div>;
const { result } = data.search;
return (
<ul>
{result.results.map((pkg, index) => (
<Item datapackage={pkg} key={index} />
<ul className="divide-y divide-gray-200">
{result.results.map((dataset, index) => (
<li
key={index}
className="relative bg-white py-5 px-4 hover:bg-gray-50 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
>
<div className="flex justify-between space-x-3">
<div className="min-w-0 flex-1">
<Link
href={`/@${
dataset.organization ? dataset.organization.name : 'dataset'
}/${dataset.name}`}
>
{/*
Linting fails because href is required for anchor tags and it
ignores NextJS's Link API. Please, see this issue for details:
https://github.com/vercel/next.js/issues/5533
*/}
{/* eslint-disable-next-line */}
<a className="block focus:outline-none">
<span className="absolute inset-0" aria-hidden="true" />
<p className="text-sm font-medium text-gray-900">
{dataset.title}
</p>
<p className="text-sm text-gray-500 truncate">
{dataset.organization
? dataset.organization.title
: 'dataset'}{' '}
/ {dataset.name}
</p>
</a>
</Link>
</div>
<time
dateTime={dataset.metadata_modified}
className="flex-shrink-0 whitespace-nowrap text-sm text-gray-500"
>
Updated {timeago.format(dataset.metadata_modified)}
</time>
</div>
<div className="mt-1">
<p className="line-clamp-2 text-sm text-gray-600">
{dataset.description ||
"This dataset doesn't have a description."}
</p>
</div>
</li>
))}
</ul>
);

View File

@ -57,6 +57,7 @@ export const SEARCH_QUERY = gql`
results {
name
title
metadata_modified
organization {
name
title

View File

@ -47,7 +47,8 @@
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router": "^5.2.0",
"slugify": "^1.4.0"
"slugify": "^1.4.0",
"timeago.js": "^4.0.2"
},
"devDependencies": {
"@tailwindcss/forms": "^0.3.3",

View File

@ -17605,6 +17605,11 @@ thunky@^1.0.2:
resolved "https://registry.yarnpkg.com/thunky/-/thunky-1.1.0.tgz#5abaf714a9405db0504732bbccd2cedd9ef9537d"
integrity sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==
timeago.js@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/timeago.js/-/timeago.js-4.0.2.tgz#724e8c8833e3490676c7bb0a75f5daf20e558028"
integrity sha512-a7wPxPdVlQL7lqvitHGGRsofhdwtkoSXPGATFuSOA2i1ZNQEPLrGnj68vOp2sOJTCFAQVXPeNMX/GctBaO9L2w==
timers-browserify@2.0.12:
version "2.0.12"
resolved "https://registry.yarnpkg.com/timers-browserify/-/timers-browserify-2.0.12.tgz#44a45c11fbf407f34f97bccd1577c652361b00ee"