v.option_entity === p.data.value)}
localNameState={localPollOptionNames[p.data.value]}
setLocalNameState={setLocalPollOptionNames}
/>
))}
{
// remove any poll options that have no name
// look through the localPollOptionNames object and remove any options that have no name
let emptyOptions = Object.entries(localPollOptionNames).filter(
([optionEntity, optionName]) => optionName === "",
);
await Promise.all(
emptyOptions.map(
async ([entity]) =>
await rep?.mutate.removePollOption({
optionEntity: entity,
}),
),
);
await rep?.mutate.assertFact(
Object.entries(localPollOptionNames)
.filter(([, name]) => !!name)
.map(([entity, name]) => ({
entity,
attribute: "poll-option/name",
data: { type: "string", value: name },
})),
);
props.close();
}}
>
Save
>
);
};
const EditPollOption = (props: {
entityID: string;
pollEntity: string;
localNameState: string | undefined;
setLocalNameState: (
s: (s: { [k: string]: string }) => { [k: string]: string },
) => void;
disabled: boolean;
}) => {
let { rep } = useReplicache();
let optionName = useEntity(props.entityID, "poll-option/name")?.data.value;
useEffect(() => {
props.setLocalNameState((s) => ({
...s,
[props.entityID]: optionName || "",
}));
}, [optionName, props.setLocalNameState, props.entityID]);
return (
{
props.setLocalNameState((s) => ({
...s,
[props.entityID]: e.target.value,
}));
}}
onKeyDown={(e) => {
if (e.key === "Backspace" && !e.currentTarget.value) {
e.preventDefault();
rep?.mutate.removePollOption({ optionEntity: props.entityID });
}
}}
/>
);
};
const PollStateToggle = (props: {
setPollState: (pollState: "editing" | "voting" | "results") => void;
hasVoted: boolean;
pollState: "editing" | "voting" | "results";
}) => {
return (
);
};