revite/src/context/intermediate/popovers/UserPicker.tsx

62 lines
2 KiB
TypeScript
Raw Normal View History

import { Users } from "revolt.js/dist/api/objects";
2021-07-05 06:23:23 -04:00
import styles from "./UserPicker.module.scss";
2021-06-19 13:46:05 -04:00
import { Text } from "preact-i18n";
import { useState } from "preact/hooks";
2021-07-05 06:23:23 -04:00
import { useData } from "../../../mobx/State";
2021-06-20 15:30:42 -04:00
import UserCheckbox from "../../../components/common/user/UserCheckbox";
2021-07-05 06:23:23 -04:00
import Modal from "../../../components/ui/Modal";
2021-06-19 13:46:05 -04:00
interface Props {
2021-07-05 06:25:20 -04:00
omit?: string[];
onClose: () => void;
callback: (users: string[]) => Promise<void>;
2021-06-19 13:46:05 -04:00
}
export function UserPicker(props: Props) {
2021-07-05 06:25:20 -04:00
const [selected, setSelected] = useState<string[]>([]);
const omit = [...(props.omit || []), "00000000000000000000000000"];
2021-06-19 13:46:05 -04:00
const store = useData();
2021-06-19 13:46:05 -04:00
2021-07-05 06:25:20 -04:00
return (
<Modal
visible={true}
title={<Text id="app.special.popovers.user_picker.select" />}
onClose={props.onClose}
actions={[
{
2021-07-06 06:34:36 -04:00
children: <Text id="app.special.modals.actions.ok" />,
2021-07-05 06:25:20 -04:00
onClick: () => props.callback(selected).then(props.onClose),
},
]}>
<div className={styles.list}>
{[...store.users.values()]
.filter(
2021-07-05 06:25:20 -04:00
(x) =>
x &&
x.relationship === Users.Relationship.Friend &&
!omit.includes(x._id),
)
2021-07-05 06:25:20 -04:00
.map((x) => (
<UserCheckbox
user={x}
checked={selected.includes(x._id)}
2021-07-05 06:25:20 -04:00
onChange={(v) => {
if (v) {
setSelected([...selected, x._id]);
} else {
setSelected(
selected.filter((y) => y !== x._id),
);
}
}}
/>
))}
</div>
</Modal>
);
2021-06-19 13:46:05 -04:00
}