Refactor to use 'defaultMediaVisibility' function
This commit is contained in:
parent
4a573270bd
commit
2c701439d9
5 changed files with 17 additions and 18 deletions
|
@ -80,7 +80,7 @@ const Status: React.FC<IStatus> = (props) => {
|
||||||
const didShowCard = useRef(false);
|
const didShowCard = useRef(false);
|
||||||
const node = useRef<HTMLDivElement>(null);
|
const node = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const [showMedia, setShowMedia] = useState<boolean>(status.visibility === 'self' ? false : defaultMediaVisibility(status, displayMedia));
|
const [showMedia, setShowMedia] = useState<boolean>(defaultMediaVisibility(status, displayMedia));
|
||||||
|
|
||||||
const actualStatus = getActualStatus(status);
|
const actualStatus = getActualStatus(status);
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ const Status: React.FC<IStatus> = (props) => {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setShowMedia(status.visibility === 'self' ? false : defaultMediaVisibility(status, displayMedia));
|
setShowMedia(defaultMediaVisibility(status, displayMedia));
|
||||||
}, [status.id]);
|
}, [status.id]);
|
||||||
|
|
||||||
const handleToggleMediaVisibility = (): void => {
|
const handleToggleMediaVisibility = (): void => {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react';
|
||||||
import { defineMessages, useIntl } from 'react-intl';
|
import { defineMessages, useIntl } from 'react-intl';
|
||||||
|
|
||||||
import { useSettings, useSoapboxConfig } from 'soapbox/hooks';
|
import { useSettings, useSoapboxConfig } from 'soapbox/hooks';
|
||||||
|
import { defaultMediaVisibility } from 'soapbox/utils/status';
|
||||||
|
|
||||||
import { Button, HStack, Text } from '../ui';
|
import { Button, HStack, Text } from '../ui';
|
||||||
|
|
||||||
|
@ -27,23 +28,15 @@ interface ISensitiveContentOverlay {
|
||||||
const SensitiveContentOverlay = (props: ISensitiveContentOverlay) => {
|
const SensitiveContentOverlay = (props: ISensitiveContentOverlay) => {
|
||||||
const { onToggleVisibility, status } = props;
|
const { onToggleVisibility, status } = props;
|
||||||
const isUnderReview = status.visibility === 'self';
|
const isUnderReview = status.visibility === 'self';
|
||||||
const isSensitive = status.sensitive;
|
|
||||||
|
|
||||||
const settings = useSettings();
|
const settings = useSettings();
|
||||||
const displayMedia = settings.get('displayMedia') as string | undefined;
|
const displayMedia = settings.get('displayMedia') as string;
|
||||||
|
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
const { links } = useSoapboxConfig();
|
const { links } = useSoapboxConfig();
|
||||||
|
|
||||||
const [visible, setVisible] = useState<boolean>(
|
const [visible, setVisible] = useState<boolean>(defaultMediaVisibility(status, displayMedia));
|
||||||
isUnderReview === true ? false : null
|
|
||||||
|| (
|
|
||||||
props.visible !== undefined
|
|
||||||
? props.visible
|
|
||||||
: (displayMedia !== 'hide_all' && !isSensitive || displayMedia === 'show_all')
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
const toggleVisibility = (event: React.MouseEvent<HTMLButtonElement>) => {
|
const toggleVisibility = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
|
@ -50,7 +50,7 @@ const DetailedStatus: React.FC<IDetailedStatus> = ({
|
||||||
const { account } = actualStatus;
|
const { account } = actualStatus;
|
||||||
if (!account || typeof account !== 'object') return null;
|
if (!account || typeof account !== 'object') return null;
|
||||||
|
|
||||||
const inReview = actualStatus.visibility === 'self';
|
const isUnderReview = actualStatus.visibility === 'self';
|
||||||
const isSensitive = actualStatus.sensitive;
|
const isSensitive = actualStatus.sensitive;
|
||||||
|
|
||||||
let statusTypeIcon = null;
|
let statusTypeIcon = null;
|
||||||
|
@ -94,11 +94,11 @@ const DetailedStatus: React.FC<IDetailedStatus> = ({
|
||||||
justifyContent='end'
|
justifyContent='end'
|
||||||
className={
|
className={
|
||||||
classNames('relative', {
|
classNames('relative', {
|
||||||
'min-h-[220px]': inReview || isSensitive,
|
'min-h-[220px]': isUnderReview || isSensitive,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{(inReview || isSensitive) ? (
|
{(isUnderReview || isSensitive) ? (
|
||||||
<SensitiveContentOverlay
|
<SensitiveContentOverlay
|
||||||
status={status}
|
status={status}
|
||||||
visible={showMedia}
|
visible={showMedia}
|
||||||
|
|
|
@ -135,7 +135,7 @@ const Thread: React.FC<IThread> = (props) => {
|
||||||
const me = useAppSelector(state => state.me);
|
const me = useAppSelector(state => state.me);
|
||||||
const status = useAppSelector(state => getStatus(state, { id: props.params.statusId }));
|
const status = useAppSelector(state => getStatus(state, { id: props.params.statusId }));
|
||||||
const displayMedia = settings.get('displayMedia') as DisplayMedia;
|
const displayMedia = settings.get('displayMedia') as DisplayMedia;
|
||||||
const inReview = status?.visibility === 'self';
|
const isUnderReview = status?.visibility === 'self';
|
||||||
|
|
||||||
const { ancestorsIds, descendantsIds } = useAppSelector(state => {
|
const { ancestorsIds, descendantsIds } = useAppSelector(state => {
|
||||||
let ancestorsIds = ImmutableOrderedSet<string>();
|
let ancestorsIds = ImmutableOrderedSet<string>();
|
||||||
|
@ -463,14 +463,14 @@ const Thread: React.FC<IThread> = (props) => {
|
||||||
ref={statusRef}
|
ref={statusRef}
|
||||||
className={
|
className={
|
||||||
classNames('detailed-status__wrapper focusable relative', {
|
classNames('detailed-status__wrapper focusable relative', {
|
||||||
'min-h-[220px]': inReview,
|
'min-h-[220px]': isUnderReview,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
// FIXME: no "reblogged by" text is added for the screen reader
|
// FIXME: no "reblogged by" text is added for the screen reader
|
||||||
aria-label={textForScreenReader(intl, status)}
|
aria-label={textForScreenReader(intl, status)}
|
||||||
>
|
>
|
||||||
{inReview ? (
|
{isUnderReview ? (
|
||||||
<SensitiveContentOverlay
|
<SensitiveContentOverlay
|
||||||
status={status}
|
status={status}
|
||||||
visible={showMedia}
|
visible={showMedia}
|
||||||
|
|
|
@ -11,6 +11,12 @@ export const defaultMediaVisibility = (status: StatusEntity | undefined | null,
|
||||||
status = status.reblog;
|
status = status.reblog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isUnderReview = status.visibility === 'self';
|
||||||
|
|
||||||
|
if (isUnderReview) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return (displayMedia !== 'hide_all' && !status.sensitive || displayMedia === 'show_all');
|
return (displayMedia !== 'hide_all' && !status.sensitive || displayMedia === 'show_all');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue