2022-10-24 18:27:34 +00:00
|
|
|
import { Atom, useAtom, WritableAtom } from "jotai";
|
2022-10-24 08:49:22 +00:00
|
|
|
import { Badge, ListGroup } from "react-bootstrap";
|
2022-10-24 07:10:52 +00:00
|
|
|
|
|
|
|
export interface IPerson {
|
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
personAtom: Atom<IPerson>;
|
2022-10-24 18:27:34 +00:00
|
|
|
splitBetweenAtom: WritableAtom<Atom<IPerson>[]>;
|
2022-10-24 07:10:52 +00:00
|
|
|
}
|
|
|
|
|
2022-10-24 08:49:22 +00:00
|
|
|
export default function Person({ personAtom, splitBetweenAtom }: Props) {
|
|
|
|
const [person] = useAtom(personAtom);
|
|
|
|
const [splitBetween, setSplitBetween] = useAtom(splitBetweenAtom);
|
|
|
|
|
|
|
|
const removeSelf = (_) => {
|
|
|
|
setSplitBetween([...splitBetween.filter((x) => x != personAtom)]);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ListGroup.Item>
|
|
|
|
{person.name}
|
|
|
|
<Badge
|
|
|
|
bg="danger"
|
|
|
|
pill
|
|
|
|
onClick={removeSelf}
|
|
|
|
style={{ cursor: "pointer" }}
|
|
|
|
>
|
|
|
|
×
|
|
|
|
</Badge>
|
|
|
|
</ListGroup.Item>
|
|
|
|
);
|
2022-10-24 07:10:52 +00:00
|
|
|
}
|