// @flow import * as ICONS from 'constants/icons'; import React from 'react'; import classnames from 'classnames'; import ClaimList from 'component/claimList'; import Page from 'component/page'; import Spinner from 'component/spinner'; import Button from 'component/button'; import usePersistedState from 'effects/use-persisted-state'; import ChannelBlockButton from 'component/channelBlockButton'; import ChannelMuteButton from 'component/channelMuteButton'; import Yrbl from 'component/yrbl'; type Props = { mutedUris: ?Array, blockedUris: ?Array, fetchingModerationBlockList: boolean, }; const VIEW_BLOCKED = 'blocked'; const VIEW_MUTED = 'muted'; function ListBlocked(props: Props) { const { mutedUris, blockedUris, fetchingModerationBlockList } = props; const [viewMode, setViewMode] = usePersistedState('blocked-muted:display', VIEW_BLOCKED); // Keep a local list to allow for undoing actions in this component const [localBlockedList, setLocalBlockedList] = React.useState(undefined); const [localMutedList, setLocalMutedList] = React.useState(undefined); const hasLocalMuteList = localMutedList && localMutedList.length > 0; const hasLocalBlockList = localBlockedList && localBlockedList.length > 0; const stringifiedMutedChannels = JSON.stringify(mutedUris); const justMuted = localMutedList && mutedUris && localMutedList.length < mutedUris.length; const justBlocked = localBlockedList && blockedUris && localBlockedList.length < blockedUris.length; const stringifiedBlockedChannels = JSON.stringify(blockedUris); const showUris = (viewMode === VIEW_MUTED && hasLocalMuteList) || (viewMode === VIEW_BLOCKED && hasLocalBlockList); React.useEffect(() => { const jsonMutedChannels = stringifiedMutedChannels && JSON.parse(stringifiedMutedChannels); if (!hasLocalMuteList && jsonMutedChannels && jsonMutedChannels.length > 0) { setLocalMutedList(jsonMutedChannels); } }, [stringifiedMutedChannels, hasLocalMuteList]); React.useEffect(() => { const jsonBlockedChannels = stringifiedBlockedChannels && JSON.parse(stringifiedBlockedChannels); if (!hasLocalBlockList && jsonBlockedChannels && jsonBlockedChannels.length > 0) { setLocalBlockedList(jsonBlockedChannels); } }, [stringifiedBlockedChannels, hasLocalBlockList]); React.useEffect(() => { if (justMuted && stringifiedMutedChannels) { setLocalMutedList(JSON.parse(stringifiedMutedChannels)); } }, [stringifiedMutedChannels, justMuted, setLocalMutedList]); React.useEffect(() => { if (justBlocked && stringifiedBlockedChannels) { setLocalBlockedList(JSON.parse(stringifiedBlockedChannels)); } }, [stringifiedBlockedChannels, justBlocked, setLocalBlockedList]); const mutedHelpText = __( 'Muted channels will be invisible to you in the app. They will not know they are muted and can still interact with you and your content.' ); const blockedHelpText = __( "Blocked channels will be invisible to you in the app. They will not be able to comment on your content, or reply to you comments left on other channels' content." ); return ( {fetchingModerationBlockList && (
)} {!fetchingModerationBlockList && ( <>
{showUris &&
{viewMode === VIEW_MUTED ? mutedHelpText : blockedHelpText}
} {showUris ? ( { return (
{viewMode === VIEW_MUTED ? ( <> ) : ( <> )}
); }} /> ) : (
} /> )} )}
); } export default ListBlocked;