Updated links model and poll page (#206)

* Improved sharing
* Updated desktop poll
This commit is contained in:
Luke Vella 2022-06-27 15:22:23 +01:00 committed by GitHub
parent c4cbf2f6bb
commit 2ead375b42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 955 additions and 1848 deletions

View file

@ -27,9 +27,9 @@ interface CommentForm {
const Discussion: React.VoidFunctionComponent = () => {
const { locale } = usePreferences();
const queryClient = trpc.useContext();
const {
poll: { pollId },
} = usePoll();
const { poll } = usePoll();
const pollId = poll.id;
const { data: comments } = trpc.useQuery(
["polls.comments.list", { pollId }],
@ -53,8 +53,6 @@ const Discussion: React.VoidFunctionComponent = () => {
},
});
const { poll } = usePoll();
const deleteComment = trpc.useMutation("polls.comments.delete", {
onMutate: ({ commentId }) => {
queryClient.setQueryData(
@ -96,9 +94,7 @@ const Discussion: React.VoidFunctionComponent = () => {
<AnimatePresence initial={false}>
{comments.map((comment) => {
const canDelete =
poll.role === "admin" ||
session.ownsObject(comment) ||
isUnclaimed(comment);
poll.admin || session.ownsObject(comment) || isUnclaimed(comment);
return (
<motion.div
@ -135,23 +131,22 @@ const Discussion: React.VoidFunctionComponent = () => {
)}
</span>
</div>
{canDelete ? (
<Dropdown
placement="bottom-start"
trigger={<CompactButton icon={DotsHorizontal} />}
>
<DropdownItem
icon={Trash}
label="Delete comment"
onClick={() => {
deleteComment.mutate({
commentId: comment.id,
pollId,
});
}}
/>
</Dropdown>
) : null}
<Dropdown
placement="bottom-start"
trigger={<CompactButton icon={DotsHorizontal} />}
>
<DropdownItem
icon={Trash}
label="Delete comment"
disabled={!canDelete}
onClick={() => {
deleteComment.mutate({
commentId: comment.id,
pollId,
});
}}
/>
</Dropdown>
</div>
<div className="w-fit whitespace-pre-wrap">
<TruncatedLinkify>{comment.content}</TruncatedLinkify>
@ -187,11 +182,7 @@ const Discussion: React.VoidFunctionComponent = () => {
)}
/>
</div>
<Button
htmlType="submit"
loading={formState.isSubmitting}
type="primary"
>
<Button htmlType="submit" loading={formState.isSubmitting}>
Comment
</Button>
</div>