Move getActualStatus logic to utils
This commit is contained in:
parent
89390083a9
commit
82d717d8ce
3 changed files with 18 additions and 12 deletions
|
@ -7,7 +7,7 @@ import { NavLink, useHistory } from 'react-router-dom';
|
|||
import Icon from 'soapbox/components/icon';
|
||||
import AccountContainer from 'soapbox/containers/account_container';
|
||||
import QuotedStatus from 'soapbox/features/status/containers/quoted_status_container';
|
||||
import { defaultMediaVisibility, textForScreenReader } from 'soapbox/utils/status';
|
||||
import { defaultMediaVisibility, textForScreenReader, getActualStatus } from 'soapbox/utils/status';
|
||||
|
||||
import StatusMedia from './status-media';
|
||||
import StatusReplyMentions from './status-reply-mentions';
|
||||
|
@ -201,11 +201,7 @@ const Status: React.FC<IStatus> = (props) => {
|
|||
};
|
||||
|
||||
const _properStatus = (): StatusEntity => {
|
||||
if (status.reblog && typeof status.reblog === 'object') {
|
||||
return status.reblog;
|
||||
} else {
|
||||
return status;
|
||||
}
|
||||
return getActualStatus(status);
|
||||
};
|
||||
|
||||
if (!status) return null;
|
||||
|
|
|
@ -8,6 +8,7 @@ import StatusContent from 'soapbox/components/status_content';
|
|||
import { HStack, Text } from 'soapbox/components/ui';
|
||||
import AccountContainer from 'soapbox/containers/account_container';
|
||||
import QuotedStatus from 'soapbox/features/status/containers/quoted_status_container';
|
||||
import { getActualStatus } from 'soapbox/utils/status';
|
||||
|
||||
import StatusInteractionBar from './status-interaction-bar';
|
||||
|
||||
|
@ -42,12 +43,7 @@ const DetailedStatus: React.FC<IDetailedStatus> = ({
|
|||
onOpenCompareHistoryModal(status);
|
||||
};
|
||||
|
||||
const getActualStatus = () => {
|
||||
if (!status) return undefined;
|
||||
return status.reblog && typeof status.reblog === 'object' ? status.reblog : status;
|
||||
};
|
||||
|
||||
const actualStatus = getActualStatus();
|
||||
const actualStatus = getActualStatus(status);
|
||||
if (!actualStatus) return null;
|
||||
const { account } = actualStatus;
|
||||
if (!account || typeof account !== 'object') return null;
|
||||
|
|
|
@ -58,3 +58,17 @@ export const textForScreenReader = (intl: IntlShape, status: StatusEntity, reblo
|
|||
|
||||
return values.join(', ');
|
||||
};
|
||||
|
||||
/** Get reblogged status if any, otherwise return the original status. */
|
||||
// @ts-ignore The type seems right, but TS doesn't like it.
|
||||
export const getActualStatus: {
|
||||
(status: StatusEntity): StatusEntity,
|
||||
(status: undefined): undefined,
|
||||
(status: null): null,
|
||||
} = (status) => {
|
||||
if (status?.reblog && typeof status?.reblog === 'object') {
|
||||
return status.reblog as StatusEntity;
|
||||
} else {
|
||||
return status;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue