// @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 usePrevious from 'effects/use-previous'; import usePersistedState from 'effects/use-persisted-state'; import ChannelBlockButton from 'component/channelBlockButton'; import ChannelMuteButton from 'component/channelMuteButton'; 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); const [loading, setLoading] = React.useState(!blockedUris || !blockedUris.length); // 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 previousFetchingModBlockList = usePrevious(fetchingModerationBlockList); 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); React.useEffect(() => { if (previousFetchingModBlockList && !fetchingModerationBlockList) { setLoading(false); } }, [setLoading, previousFetchingModBlockList, fetchingModerationBlockList]); 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]); return ( {loading && (
)} {!loading && ( <>
{viewMode === VIEW_MUTED ? __( '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.' ) : __( "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 (
{viewMode === VIEW_MUTED ? ( <> ) : ( <> )}
); }} /> )}
); } export default ListBlocked;