Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable thread actions for users that have not joined the community #4521

Merged
merged 57 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
5cc1a6e
Quill initial work
Jun 28, 2023
3f14273
Add monospace font on markdown
Jun 28, 2023
1272b22
Add focus styles
Jun 28, 2023
28b8148
Add disabled state
Jun 29, 2023
d6aa2ef
prevent jump between markdown toggle
Jun 29, 2023
e786f00
Adjust quill all over the app
Jun 29, 2023
bc80c5b
Merge remote-tracking branch 'origin/master' into marcin.4122-quill
Jun 30, 2023
25c17f3
Merge remote-tracking branch 'origin/master' into marcin.4122-quill
Jul 6, 2023
de47d97
Update icons to phosphor
Jul 6, 2023
5f761c0
Add quill to component showcase
Jul 6, 2023
24ee59f
Remove placeholder default text
Jul 7, 2023
3abc909
Merge confclits
Jul 7, 2023
b014112
Add banner component
Jul 10, 2023
e7f7e91
Add static banner to view thread page
Jul 10, 2023
67a0831
Add static banner to create thread page
Jul 10, 2023
b2e4e06
Merge remote-tracking branch 'origin/master' into marcin.4380-show-ct…
Jul 11, 2023
aaa6579
Add closing banner in new thread form
Jul 11, 2023
d2c23b2
Add closing banner in discussion page
Jul 11, 2023
a5f850f
Abstract join community logic into hook
Jul 11, 2023
2d52ee3
use join community hook in new thread form
Jul 11, 2023
0829eaf
use join community hook in view thread page
Jul 11, 2023
ac6cbce
use hook for check active account
Jul 12, 2023
43ac05e
use hook for closing banner logic
Jul 12, 2023
01186a8
abstract AccountSelectorModal
Jul 12, 2023
d408ba7
abstract TOS modal
Jul 12, 2023
edd9501
abstract all join community modals modals
Jul 12, 2023
c8e2128
rename old banner and create new component for join community banner
Jul 12, 2023
19da25a
Merge remote-tracking branch 'origin/master' into marcin.4380-show-ct…
Jul 12, 2023
d11ca48
Fix ts errors
Jul 13, 2023
1ee8b4c
Merge branch 'master' into marcin.4380-show-cta-banner
CowMuon Jul 13, 2023
f471075
Revert merge changes
Jul 14, 2023
cd2c09e
Merge remote-tracking branch 'origin/master' into marcin.4380-show-ct…
Jul 17, 2023
4677ff8
Disable editor 4377
Jul 17, 2023
ad11f61
Change naming
Jul 17, 2023
3745d78
Change naming pt. 2
Jul 17, 2023
ca044d8
Change naming pt. 3
Jul 18, 2023
2aacb92
Unify small upvote button
Jul 18, 2023
3e14a5c
Remove upvote from thread action component
Jul 18, 2023
6fa5419
Replace comment button
Jul 18, 2023
3d3a203
Replace share button
Jul 18, 2023
ddd36f3
Replace subscribe btn
Jul 18, 2023
1e671d5
Merge remote-tracking branch 'origin/master' into marcin.4378-disable…
Jul 19, 2023
39b0daa
Replace overflow btn
Jul 19, 2023
5b1d98b
add upvote to thread action component
Jul 19, 2023
7406269
Change div to button
Jul 19, 2023
e4fb92a
Progress on disabling
Jul 19, 2023
4c43c2e
Add tooltip wrapper to thread action
Jul 19, 2023
8f54461
Edit tooltip styles to adjust new designs
Jul 19, 2023
0a7c314
Add tooltip to disabled buttons
Jul 19, 2023
842e229
Handle reply button
Jul 20, 2023
b58a217
Fix create thread buttons
Jul 20, 2023
09d1686
Merge remote-tracking branch 'origin/master' into marcin.4378-disable…
Jul 20, 2023
ce05cad
self CR
Jul 20, 2023
eb7bcfd
fixed lint errors
Jul 20, 2023
8a198db
remove comment
Jul 20, 2023
6499a97
Merge remote-tracking branch 'origin/master' into marcin.4378-disable…
Jul 21, 2023
2a146a7
conflicts
Jul 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,52 +1,47 @@
import 'components/ReactionButton/CommentReactionButton.scss';
import { notifyError } from 'controllers/app/notifications';
import React, { useState, useEffect } from 'react';
import { notifyError } from 'controllers/app/notifications';
import app from 'state';
import type ChainInfo from '../../../models/ChainInfo';
import type Comment from '../../../models/Comment';
import ReactionCount from '../../../models/ReactionCount';
import {
useCreateCommentReactionMutation,
useDeleteCommentReactionMutation,
useFetchCommentReactionsQuery
useFetchCommentReactionsQuery,
} from '../../../state/api/comments';
import Permissions from '../../../utils/Permissions';
import { LoginModal } from '../../modals/login_modal';
import { CWIcon } from '../component_kit/cw_icons/cw_icon';
import { Modal } from '../component_kit/cw_modal';
import { CWTooltip } from '../component_kit/cw_popover/cw_tooltip';
import {
getClasses,
isWindowMediumSmallInclusive,
} from '../component_kit/helpers';
import {
getDisplayedReactorsForPopup,
onReactionClick,
} from './helpers';
import { isWindowMediumSmallInclusive } from '../component_kit/helpers';
import { getDisplayedReactorsForPopup, onReactionClick } from './helpers';
import CWUpvoteSmall from 'views/components/component_kit/new_designs/CWUpvoteSmall';

type CommentReactionButtonProps = {
comment: Comment<any>;
disabled: boolean;
};

export const CommentReactionButton = ({
comment,
disabled,
}: CommentReactionButtonProps) => {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [reactors, setReactors] = useState<Array<any>>([]);
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const [reactionCounts, setReactionCounts] = useState<ReactionCount<any>>();
const { mutateAsync: createCommentReaction } = useCreateCommentReactionMutation({
commentId: comment.id,
chainId: app.activeChainId()
})
const { mutateAsync: deleteCommentReaction } = useDeleteCommentReactionMutation({
commentId: comment.id,
chainId: app.activeChainId()
})
const { mutateAsync: createCommentReaction } =
useCreateCommentReactionMutation({
commentId: comment.id,
chainId: app.activeChainId(),
});
const { mutateAsync: deleteCommentReaction } =
useDeleteCommentReactionMutation({
commentId: comment.id,
chainId: app.activeChainId(),
});
const { data: reactions } = useFetchCommentReactionsQuery({
chainId: app.activeChainId(),
commentId: comment.id,
})
});

useEffect(() => {
const redrawFunction = (comment_id) => {
Expand Down Expand Up @@ -82,8 +77,6 @@ export const CommentReactionButton = ({
return r.Address.address === activeAddress;
});

setIsLoading(true);

deleteCommentReaction({
canvasHash: foundReaction.canvas_hash,
reactionId: foundReaction.id,
Expand All @@ -92,34 +85,49 @@ export const CommentReactionButton = ({
likes: likes - 1,
hasReacted: false,
},
}).then(() => {
setReactors(
reactors.filter(({ Address }) => Address.address !== userAddress)
);
setReactionCounts(app.comments.reactionCountsStore.getByPost(comment));
setIsLoading(false);
}).catch(() => {
notifyError('Failed to update reaction count');
});
})
.then(() => {
setReactors(
reactors.filter(({ Address }) => Address.address !== userAddress)
);
setReactionCounts(app.comments.reactionCountsStore.getByPost(comment));
})
.catch(() => {
notifyError('Failed to update reaction count');
});
};

const like = (chain: ChainInfo, chainId: string, userAddress: string) => {
setIsLoading(true);

createCommentReaction({
address: userAddress,
commentId: comment.id,
chainId: chainId,
}).then(() => {
setReactors([
...reactors,
{ Address: { address: userAddress, chain } },
]);
setReactionCounts(app.comments.reactionCountsStore.getByPost(comment));
setIsLoading(false);
}).catch(() => {
notifyError('Failed to save reaction');
})
.then(() => {
setReactors([
...reactors,
{ Address: { address: userAddress, chain } },
]);
setReactionCounts(app.comments.reactionCountsStore.getByPost(comment));
})
.catch(() => {
notifyError('Failed to save reaction');
});
};

const handleVoteClick = async (e) => {
e.stopPropagation();
e.preventDefault();

if (!app.isLoggedIn() || !app.user.activeAccount) {
setIsModalOpen(true);
} else {
onReactionClick(e, hasReacted, dislike, like);
}
};

const handleVoteMouseEnter = async () => {
setReactors(reactions);
};

return (
Expand All @@ -130,66 +138,16 @@ export const CommentReactionButton = ({
onClose={() => setIsModalOpen(false)}
open={isModalOpen}
/>
<button
className={getClasses<{ disabled?: boolean }>(
{ disabled: isLoading || isUserForbidden },
`CommentReactionButton ${hasReacted ? ' has-reacted' : ''}`
)}
// TODO: won't be needed now?
onMouseEnter={async () => {
setReactors(reactions);
}}
onClick={async (e) => {
e.stopPropagation();
e.preventDefault();

if (!app.isLoggedIn() || !app.user.activeAccount) {
setIsModalOpen(true);
} else {
onReactionClick(e, hasReacted, dislike, like);
}
}}
>
{likes > 0 ? (
<CWTooltip
content={
<div className="reaction-button-tooltip-contents">
{getDisplayedReactorsForPopup({
reactors: reactors.map((r) => r.Address.address),
})}
</div>
}
renderTrigger={(handleInteraction) => (
<div
onMouseEnter={handleInteraction}
onMouseLeave={handleInteraction}
className="btn-container"
>
<CWIcon
iconName="upvote"
iconSize="small"
{...(hasReacted && { weight: 'fill' })}
/>
<div
className={`reactions-count ${hasReacted ? ' has-reacted' : ''
}`}
>
{likes}
</div>
</div>
)}
/>
) : (
<>
<CWIcon iconName="upvote" iconSize="small" />
<div
className={`reactions-count ${hasReacted ? ' has-reacted' : ''}`}
>
{likes}
</div>
</>
)}
</button>
<CWUpvoteSmall
voteCount={likes}
disabled={isUserForbidden || disabled}
selected={hasReacted}
onMouseEnter={handleVoteMouseEnter}
onClick={handleVoteClick}
tooltipContent={getDisplayedReactorsForPopup({
reactors: reactors.map((r) => r.Address.address),
})}
/>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -1024,8 +1024,7 @@ export const ComponentShowcase = () => {
/>
<CWThreadAction
action="upvote"
count={1}
onClick={() => console.log('Upvote action clicked!!')}
onClick={() => console.log('Upvote action clicked!')}
/>
<CWThreadAction
action="overflow"
Expand All @@ -1049,7 +1048,6 @@ export const ComponentShowcase = () => {
/>
<CWThreadAction
action="upvote"
count={1}
onClick={() => console.log('Upvote action clicked!')}
disabled
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import MinimumProfile from '../../../models/MinimumProfile';
import { Thread } from '../../../models/Thread';
import Topic from '../../../models/Topic';
import { ThreadStage } from '../../../models/types';
import { AuthorAndPublishInfo as ThreadAuthorAndPublishInfo } from '../../pages/discussions/ThreadCard/AuthorAndPublishInfo';
import { Options as ThreadOptions } from '../../pages/discussions/ThreadCard/Options';
import { AuthorAndPublishInfo } from '../../pages/discussions/ThreadCard/AuthorAndPublishInfo';
import { ThreadOptions } from '../../pages/discussions/ThreadCard/ThreadOptions';
import { CWCard } from './cw_card';
import { CWTab, CWTabBar } from './cw_tabs';
import { CWText } from './cw_text';
Expand Down Expand Up @@ -116,7 +116,7 @@ export const CWContentPage = ({
title
)}
<div className="header-info-row">
<ThreadAuthorAndPublishInfo
<AuthorAndPublishInfo
showSplitDotIndicator={true}
isNew={!!displayNewTag}
isLocked={thread?.readOnly}
Expand Down Expand Up @@ -156,8 +156,8 @@ export const CWContentPage = ({
{body &&
body(
<ThreadOptions
canVote={!thread?.readOnly}
canComment={!thread?.readOnly}
upvoteBtnVisible={!thread?.readOnly}
commentBtnVisible={!thread?.readOnly}
thread={thread}
totalComments={thread?.numberOfComments}
onLockToggle={onLockToggle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type UsePopoverProps = {
type PopoverProps = {
content: React.ReactNode;
placement?: Placement;
disablePortal?: boolean;
} & UsePopoverProps;

export type PopoverTriggerProps = {
Expand Down Expand Up @@ -44,14 +45,20 @@ export const usePopover = (): UsePopoverProps => {
};
};

export const Popover = (props: PopoverProps) => {
const { anchorEl, content, id, open, placement } = props;

export const Popover = ({
anchorEl,
content,
id,
open,
placement,
disablePortal,
}: PopoverProps) => {
return (
<PopperUnstyled
id={id}
open={open}
anchorEl={anchorEl}
disablePortal={disablePortal}
placement={placement || 'bottom-start'}
modifiers={[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@ type TooltipProps = {
content: string | React.ReactNode;
hasBackground?: boolean;
placement?: Placement;
disablePortal?: boolean;
} & PopoverTriggerProps;

export const CWTooltip = (props: TooltipProps) => {
const { content, hasBackground, renderTrigger, placement } = props;

export const CWTooltip = ({
content,
hasBackground,
renderTrigger,
placement,
disablePortal,
}: TooltipProps) => {
const popoverProps = usePopover();

return (
<>
{renderTrigger(popoverProps.handleInteraction)}
<Popover
disablePortal={disablePortal}
placement={placement}
content={
typeof content === 'string' ? (
Expand Down
Loading
Loading