2022-11-17 17:34:20 +01:00
|
|
|
import {
|
2022-11-18 14:11:52 +01:00
|
|
|
EmojiLaughing,
|
|
|
|
HandThumbsDown,
|
|
|
|
HandThumbsUp,
|
|
|
|
Heart,
|
|
|
|
People,
|
2022-11-20 16:54:25 +01:00
|
|
|
Plus,
|
2022-11-18 14:11:52 +01:00
|
|
|
Trash3,
|
2022-11-17 17:34:20 +01:00
|
|
|
} from "react-bootstrap-icons";
|
|
|
|
|
|
|
|
import Card from "./Card";
|
|
|
|
import TextInput from "./TextInput";
|
2022-11-18 14:11:52 +01:00
|
|
|
import Button, { ButtonStyle } from "./Button";
|
2022-11-20 16:54:25 +01:00
|
|
|
import { useState } from "react";
|
2022-11-17 17:34:20 +01:00
|
|
|
|
|
|
|
export interface EditField {
|
2022-11-18 14:11:52 +01:00
|
|
|
id: number;
|
|
|
|
name: string;
|
|
|
|
pronouns: Record<string, PronounChoice>;
|
2022-11-17 17:34:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export enum PronounChoice {
|
2022-11-18 14:11:52 +01:00
|
|
|
favourite,
|
|
|
|
okay,
|
|
|
|
jokingly,
|
|
|
|
friendsOnly,
|
|
|
|
avoid,
|
2022-11-17 17:34:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type EditableCardProps = {
|
2022-11-18 14:11:52 +01:00
|
|
|
field: EditField;
|
|
|
|
onChangeName: React.ChangeEventHandler<HTMLInputElement>;
|
2022-11-20 16:54:25 +01:00
|
|
|
onChangePronoun: React.ChangeEventHandler<HTMLInputElement>;
|
|
|
|
onAddPronoun(pronoun: string): void;
|
2022-11-18 14:11:52 +01:00
|
|
|
onChangeFavourite(
|
|
|
|
e: React.MouseEvent<HTMLButtonElement>,
|
|
|
|
entry: string
|
|
|
|
): void;
|
|
|
|
onChangeOkay(e: React.MouseEvent<HTMLButtonElement>, entry: string): void;
|
|
|
|
onChangeJokingly(e: React.MouseEvent<HTMLButtonElement>, entry: string): void;
|
|
|
|
onChangeFriends(e: React.MouseEvent<HTMLButtonElement>, entry: string): void;
|
|
|
|
onChangeAvoid(e: React.MouseEvent<HTMLButtonElement>, entry: string): void;
|
|
|
|
onClickDelete: React.MouseEventHandler<HTMLButtonElement>;
|
2022-11-17 17:34:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export function EditableCard(props: EditableCardProps) {
|
2022-11-20 16:54:25 +01:00
|
|
|
const [input, setInput] = useState("");
|
|
|
|
|
2022-11-18 14:11:52 +01:00
|
|
|
const footer = (
|
|
|
|
<div className="flex justify-between">
|
|
|
|
<TextInput value={props.field.name} onChange={props.onChangeName} />
|
|
|
|
<Button style={ButtonStyle.danger} onClick={props.onClickDelete}>
|
|
|
|
<Trash3 aria-hidden className="inline" /> Delete
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
);
|
2022-11-17 17:34:20 +01:00
|
|
|
|
2022-11-18 14:11:52 +01:00
|
|
|
return (
|
|
|
|
<Card title={props.field.name} draggable footer={footer}>
|
|
|
|
<ul>
|
|
|
|
{Object.keys(props.field.pronouns).map((pronoun, index) => {
|
|
|
|
const choice = props.field.pronouns[pronoun];
|
|
|
|
return (
|
2022-11-20 16:54:25 +01:00
|
|
|
<li className="flex justify-between my-1 items-center" key={index}>
|
|
|
|
<TextInput
|
|
|
|
value={pronoun}
|
|
|
|
prevValue={pronoun}
|
|
|
|
onChange={props.onChangePronoun}
|
|
|
|
/>
|
2022-11-18 14:11:52 +01:00
|
|
|
<div className="rounded-md">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={(e) => props.onChangeFavourite(e, pronoun)}
|
|
|
|
className={`${
|
|
|
|
choice == PronounChoice.favourite
|
|
|
|
? "bg-slate-500"
|
|
|
|
: "bg-slate-600"
|
|
|
|
} hover:bg-slate-400 p-2`}
|
|
|
|
>
|
|
|
|
<Heart />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={(e) => props.onChangeOkay(e, pronoun)}
|
|
|
|
className={`${
|
|
|
|
choice == PronounChoice.okay
|
|
|
|
? "bg-slate-500"
|
|
|
|
: "bg-slate-600"
|
|
|
|
} hover:bg-slate-400 p-2`}
|
|
|
|
>
|
|
|
|
<HandThumbsUp />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={(e) => props.onChangeJokingly(e, pronoun)}
|
|
|
|
className={`${
|
|
|
|
choice == PronounChoice.jokingly
|
|
|
|
? "bg-slate-500"
|
|
|
|
: "bg-slate-600"
|
|
|
|
} hover:bg-slate-400 p-2`}
|
|
|
|
>
|
|
|
|
<EmojiLaughing />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={(e) => props.onChangeFriends(e, pronoun)}
|
|
|
|
className={`${
|
|
|
|
choice == PronounChoice.friendsOnly
|
|
|
|
? "bg-slate-500"
|
|
|
|
: "bg-slate-600"
|
|
|
|
} hover:bg-slate-400 p-2`}
|
|
|
|
>
|
|
|
|
<People />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={(e) => props.onChangeAvoid(e, pronoun)}
|
|
|
|
className={`${
|
|
|
|
choice == PronounChoice.avoid
|
|
|
|
? "bg-slate-500"
|
|
|
|
: "bg-slate-600"
|
|
|
|
} hover:bg-slate-400 p-2`}
|
|
|
|
>
|
|
|
|
<HandThumbsDown />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="bg-red-600 dark:bg-red-700 hover:bg-red-700 hover:dark:bg-red-800 p-2"
|
|
|
|
>
|
|
|
|
<Trash3 />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
})}
|
2022-11-20 16:54:25 +01:00
|
|
|
<li className="flex justify-between my-1 items-center">
|
|
|
|
<TextInput value={input} onChange={(e) => setInput(e.target.value)} />
|
|
|
|
<Button
|
|
|
|
style={ButtonStyle.success}
|
|
|
|
onClick={() => {
|
|
|
|
props.onAddPronoun(input);
|
|
|
|
setInput("");
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Plus aria-hidden className="inline" /> Add
|
|
|
|
</Button>
|
|
|
|
</li>
|
2022-11-18 14:11:52 +01:00
|
|
|
</ul>
|
|
|
|
</Card>
|
|
|
|
);
|
2022-11-17 17:34:20 +01:00
|
|
|
}
|