-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add title format; add search page
- Loading branch information
1 parent
e5f070a
commit f832ef0
Showing
8 changed files
with
143 additions
and
21 deletions.
There are no files selected for viewing
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,81 @@ | ||
import React, { useEffect } from 'react'; | ||
import { Helmet, Link, useHistory } from 'umi'; | ||
import { Input, List, Spin } from 'antd'; | ||
import { useReq } from '@/utils/request'; | ||
import { api } from '@/services/api'; | ||
import urlcat from 'urlcat'; | ||
import dayjs from 'dayjs'; | ||
import { EyeOutlined } from '@ant-design/icons'; | ||
import { formatTitle } from '@/utils/title-format.util'; | ||
|
||
export default function SearchPage({ location }: any) { | ||
const kw = location.query.kw; | ||
const history = useHistory(); | ||
const [isInit, setIsInit] = React.useState(false); | ||
|
||
const onSearch = (value: string) => { | ||
history.push({ search: `kw=${encodeURIComponent(value)}` }); | ||
}; | ||
|
||
const { | ||
run: runSearch, | ||
loading, | ||
data, | ||
} = useReq(api.searchRanklist.bind(api), { | ||
manual: true, | ||
}); | ||
|
||
const count = data?.ranks.length || 0; | ||
const rows = data?.ranks || []; | ||
|
||
useEffect(() => { | ||
if (kw) { | ||
setIsInit(true); | ||
runSearch({ kw }); | ||
} | ||
}, [kw]); | ||
|
||
const renderResult = () => { | ||
if (loading) { | ||
return <Spin className="mt-10" />; | ||
} | ||
return ( | ||
<div className="mt-10"> | ||
<div className="opacity-70">搜索到 {count} 个结果</div> | ||
{count > 0 && ( | ||
<div className="mt-2"> | ||
<List | ||
key="id" | ||
dataSource={rows} | ||
size="small" | ||
renderItem={(item) => ( | ||
<List.Item> | ||
<p className="mb-0"> | ||
<Link to={urlcat('/ranklist/:uniqueKey', { uniqueKey: item.uniqueKey })}>{item.name}</Link> | ||
<span className="ml-2 opacity-70"><EyeOutlined /> {item.viewCnt}</span> | ||
</p> | ||
<p className="mb-0 opacity-50 text-sm"> | ||
创建于 {dayjs(item.createdAt).format('YYYY-MM-DD HH:mm')} | ||
</p> | ||
</List.Item> | ||
)} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="normal-content"> | ||
<Helmet> | ||
<title>{formatTitle('Explore')}</title> | ||
</Helmet> | ||
<div> | ||
<h3 className="mb-6">在榜单数据库中探索</h3> | ||
<Input.Search defaultValue={kw || ''} placeholder="输入关键词" onSearch={onSearch} enterButton /> | ||
{isInit && renderResult()} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export enum LogicExceptionKind { | ||
NotFound = 'NotFound', | ||
} | ||
|
||
export class LogicException extends Error { | ||
public kind: LogicExceptionKind; | ||
|
||
public constructor(kind: LogicExceptionKind) { | ||
super(`logic exception with kind: ${kind}`); | ||
this.name = 'LogicException'; | ||
this.kind = kind; | ||
// @ts-ignore | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} |
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,3 @@ | ||
export function formatTitle(title?: string) { | ||
return title ? `${title} | RankLand` : 'RankLand'; | ||
} |
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ declare module '*.svg' { | |
const url: string; | ||
export default url; | ||
} | ||
declare module '*.txt'; |