Skip to content

Commit

Permalink
feat: add a search field to server bans
Browse files Browse the repository at this point in the history
  • Loading branch information
sussycatgirl committed Apr 10, 2022
1 parent 002cb5e commit 854e228
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions src/pages/settings/server/Bans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useEffect, useState } from "preact/hooks";

import UserIcon from "../../../components/common/user/UserIcon";
import IconButton from "../../../components/ui/IconButton";
import InputBox from "../../../components/ui/InputBox";
import Preloader from "../../../components/ui/Preloader";

interface InnerProps {
Expand Down Expand Up @@ -53,6 +54,7 @@ interface Props {
}

export const Bans = observer(({ server }: Props) => {
const [query, setQuery] = useState("");
const [data, setData] = useState<
Route<"GET", "/servers/id/bans">["response"] | undefined
>(undefined);
Expand All @@ -63,6 +65,12 @@ export const Bans = observer(({ server }: Props) => {

return (
<div className={styles.userList}>
<InputBox
placeholder="Search for a specific user..."
value={query}
onChange={(e) => setQuery(e.currentTarget.value)}
contrast
/>
<div className={styles.subtitle}>
<span>
<Text id="app.settings.server_pages.bans.user" />
Expand All @@ -79,24 +87,33 @@ export const Bans = observer(({ server }: Props) => {
<div className={styles.virtual}>
<Virtuoso
totalCount={data.bans.length}
itemContent={(index) => (
<Inner
key={data.bans[index]._id.user}
server={server}
users={data.users}
ban={data.bans[index]}
removeSelf={() => {
setData({
bans: data.bans.filter(
(y) =>
y._id.user !==
data.bans[index]._id.user,
),
users: data.users,
});
}}
/>
)}
itemContent={(index) =>
(!query ||
data.users
.find(
(u) =>
u._id == data.bans[index]._id.user,
)
?.username.toLowerCase()
.includes(query.toLowerCase())) && (
<Inner
key={data.bans[index]._id.user}
server={server}
users={data.users}
ban={data.bans[index]}
removeSelf={() => {
setData({
bans: data.bans.filter(
(y) =>
y._id.user !==
data.bans[index]._id.user,
),
users: data.users,
});
}}
/>
)
}
/>
</div>
)}
Expand Down

0 comments on commit 854e228

Please sign in to comment.