Commit 6ecae01f authored by Chunchi Che's avatar Chunchi Che

support search

parent 6d3d6113
Pipeline #23646 passed with stages
in 14 minutes and 37 seconds
...@@ -47,6 +47,7 @@ export const WatchContent: React.FC = () => { ...@@ -47,6 +47,7 @@ export const WatchContent: React.FC = () => {
const [rooms, setRooms] = useState<Room[]>([]); const [rooms, setRooms] = useState<Room[]>([]);
const { message } = App.useApp(); const { message } = App.useApp();
const { watchID } = useSnapshot(watchStore); const { watchID } = useSnapshot(watchStore);
const [query, setQuery] = useState("");
// 暂时只支持竞技匹配的观战,TODO:后面需要加上娱乐匹配的支持 // 暂时只支持竞技匹配的观战,TODO:后面需要加上娱乐匹配的支持
const url = new URL(athleticWatchUrl); const url = new URL(athleticWatchUrl);
url.searchParams.set("filter", "started"); url.searchParams.set("filter", "started");
...@@ -103,46 +104,54 @@ export const WatchContent: React.FC = () => { ...@@ -103,46 +104,54 @@ export const WatchContent: React.FC = () => {
<div className={styles.search}> <div className={styles.search}>
<Input <Input
className={styles.input} className={styles.input}
placeholder="搜索房间" placeholder="通过玩家用户名搜索房间"
bordered={false} bordered={false}
suffix={<Button type="text" icon={<SearchOutlined />} />} suffix={<Button type="text" icon={<SearchOutlined />} />}
value={query}
onChange={(e) => setQuery(e.target.value)}
/> />
</div> </div>
<ScrollableArea maxHeight="50vh"> <ScrollableArea maxHeight="50vh">
{readyState === ReadyState.CONNECTING || rooms.length === 0 ? ( {readyState === ReadyState.CONNECTING || rooms.length === 0 ? (
<Empty /> <Empty />
) : ( ) : (
rooms.map((room) => ( rooms
<div key={room.id}> .filter(
<div (room) =>
className={classNames(styles.item, { room.users?.at(0)?.username.includes(query) ||
[styles["item-selected"]]: watchID && watchID === room.id, room.users?.at(1)?.username.includes(query),
})} )
onClick={() => (watchStore.watchID = room.id)} .map((room) => (
> <div key={room.id}>
<div className={styles.avatar}> <div
<Avatar className={classNames(styles.item, {
src={avatarApi.replace( [styles["item-selected"]]: watchID && watchID === room.id,
"{username}", })}
room.users?.at(0)?.username ?? "?", onClick={() => (watchStore.watchID = room.id)}
)} >
/> <div className={styles.avatar}>
<Avatar <Avatar
src={avatarApi.replace( src={avatarApi.replace(
"{username}", "{username}",
room.users?.at(1)?.username ?? "?", room.users?.at(0)?.username ?? "?",
)} )}
/> />
<Avatar
src={avatarApi.replace(
"{username}",
room.users?.at(1)?.username ?? "?",
)}
/>
</div>
<div className={styles.title}>
{`${room.users?.at(0)?.username} 与 ${room.users?.at(1)
?.username} 的决斗`}
</div>
<div className={styles.mode}>竞技匹配</div>
</div> </div>
<div className={styles.title}> <Divider className={styles.divider} />
{`${room.users?.at(0)?.username} 与 ${room.users?.at(1)
?.username} 的决斗`}
</div>
<div className={styles.mode}>竞技匹配</div>
</div> </div>
<Divider className={styles.divider} /> ))
</div>
))
)} )}
</ScrollableArea> </ScrollableArea>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment