-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1682 from FreeFeed/show-banned-comments
Allow to "unlock" and preview comments from the banned users and with reply to the banned users
- Loading branch information
Showing
13 changed files
with
193 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import cn from 'classnames'; | ||
import { faTimes } from '@fortawesome/free-solid-svg-icons'; | ||
import { Icon } from './fontawesome-icons'; | ||
import { ButtonLink } from './button-link'; | ||
import style from './alternative-text.module.scss'; | ||
|
||
export function AlternativeText({ | ||
status, | ||
icon, | ||
isError = false, | ||
inComment = false, | ||
close, | ||
children, | ||
}) { | ||
return ( | ||
<div className={cn(style.box, inComment && style.inComment)}> | ||
<div className={cn(style.status, isError && style.statusError)}> | ||
<span className={style.icon}> | ||
<Icon icon={icon} /> | ||
</span> | ||
<span className={style.statusText}>{status}</span> | ||
<ButtonLink onClick={close} aria-label="Close" className={style.closeIcon}> | ||
<Icon icon={faTimes} /> | ||
</ButtonLink> | ||
</div> | ||
<div>{children}</div> | ||
</div> | ||
); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { faLockOpen } from '@fortawesome/free-solid-svg-icons'; | ||
import { useEffect } from 'react'; | ||
import { COMMENT_VISIBLE, HIDDEN_AUTHOR_BANNED } from '../utils/frontend-preferences-options'; | ||
import { initialAsyncState } from '../redux/async-helpers'; | ||
import { unlockComment } from '../redux/action-creators'; | ||
import PieceOfText from './piece-of-text'; | ||
import { AlternativeText } from './alternative-text'; | ||
import UserName from './user-name'; | ||
|
||
export function UnlockedHiddenComment({ id, userHover, arrowHover, arrowClick, close }) { | ||
const dispatch = useDispatch(); | ||
const comment = useSelector((state) => state.comments[id]); | ||
|
||
const status = useSelector((store) => store.unlockedCommentStates[id] ?? initialAsyncState); | ||
const unlockedComment = useSelector((store) => store.unlockedComments[id]); | ||
|
||
useEffect(() => { | ||
if (comment.hideType === HIDDEN_AUTHOR_BANNED && status.initial) { | ||
dispatch(unlockComment(id)); | ||
} | ||
}, [comment.hideType, dispatch, id, status.initial]); | ||
|
||
let title; | ||
if (comment.hideType === COMMENT_VISIBLE) { | ||
title = `Comment with reply to blocked user:`; | ||
} else if (comment.hideType === HIDDEN_AUTHOR_BANNED) { | ||
if (status.loading) { | ||
title = `Loading comment from a blocked user...`; | ||
} else if (status.error) { | ||
title = `Error loading comment: ${status.errorText}`; | ||
} else { | ||
title = `Comment from a blocked user:`; | ||
} | ||
} | ||
|
||
let content = null; | ||
if (comment.hideType === COMMENT_VISIBLE) { | ||
content = ( | ||
<CommentContent | ||
comment={comment} | ||
userHover={userHover} | ||
arrowHover={arrowHover} | ||
arrowClick={arrowClick} | ||
/> | ||
); | ||
} else if (comment.hideType === HIDDEN_AUTHOR_BANNED) { | ||
content = ( | ||
<CommentContent | ||
comment={unlockedComment} | ||
userHover={userHover} | ||
arrowHover={arrowHover} | ||
arrowClick={arrowClick} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<AlternativeText icon={faLockOpen} status={title} inComment close={close}> | ||
{content} | ||
</AlternativeText> | ||
); | ||
} | ||
|
||
function CommentContent({ comment, userHover, arrowHover, arrowClick }) { | ||
const allUsers = useSelector((state) => state.users); | ||
const author = allUsers[comment?.createdBy]; | ||
return ( | ||
comment && ( | ||
<> | ||
<PieceOfText | ||
isExpanded | ||
text={comment.body} | ||
userHover={userHover} | ||
arrowHover={arrowHover} | ||
arrowClick={arrowClick} | ||
/> | ||
{author && ( | ||
<> | ||
{' '} | ||
- <UserName user={author} /> | ||
</> | ||
)} | ||
</> | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { UNLOCK_COMMENT } from '../action-types'; | ||
import { asyncResultsMap, asyncStatesMap } from '../async-helpers'; | ||
import { setOnLocationChange } from './helpers'; | ||
|
||
const resetOnLocationChange = setOnLocationChange({}); | ||
|
||
export const unlockedCommentStates = asyncStatesMap(UNLOCK_COMMENT, {}, resetOnLocationChange); | ||
export const unlockedComments = asyncResultsMap( | ||
UNLOCK_COMMENT, | ||
{ | ||
transformer: (action) => action.payload.comments, | ||
}, | ||
resetOnLocationChange, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters