Skip to content

Commit

Permalink
feat: add search sort filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Pleasurecruise committed Jan 1, 2025
1 parent 63d2028 commit c03af09
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const Layout: React.FC<LayoutProps> = ({ children }) => {
<div>{children}</div>
) : (
<div className='flex flex-row md:border-none'>
{pathname === '/' && <TagList />}
{(pathname === '/' || pathname === '/search/result') && <TagList />}
<div
className={`relative ${
pathname === '/'
pathname === '/' || pathname === '/search/result'
? 'w-0 flex-grow lg:w-7/12'
: 'w-0 flex-grow lg:w-9/12'
}`}
Expand Down
30 changes: 30 additions & 0 deletions src/pages/search/result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ import { fetcher } from '@/services/base';
import { makeUrl } from '@/utils/api';

import { SearchItemType, SearchResponse } from '@/types/search';
import IndexBar from '@/components/navbar/IndexBar';
import { indexRankBy, indexSortBy } from '@/utils/constants';

// TODO 需要测试
type QueryProps = {
sort_by?: string;
tid?: string;
rank_by?: string;
year?: number;
month?: number;
};

const Result: NextPage = () => {
const router = useRouter();
Expand Down Expand Up @@ -54,10 +65,29 @@ const Result: NextPage = () => {
rootMargin: '0px 0px 100px 0px',
});

const {
tid = 'all',
sort_by = 'featured',
rank_by = 'newest',
year,
month,
}: QueryProps = router.query;
const sortBy = indexSortBy.includes(sort_by) ? sort_by : 'featured';
const rankBy = indexRankBy.includes(rank_by) ? rank_by : 'newest';

return (
<>
<Seo title={t('title')} description={t('description')} />
<Navbar middleText={t('navbar')} />
<IndexBar
tid={tid}
sortBy={sortBy}
t={t}
i18n_lang={i18n.language}
rankBy={rankBy}
year={year}
month={month}
/>
<div className='h-screen'>
<div className='divide-y divide-gray-100 overflow-y-hidden bg-white dark:divide-gray-700 md:rounded-lg'>
{list.map((item) => (
Expand Down

0 comments on commit c03af09

Please sign in to comment.