[Glitch] Collection accounts editor: Show info badge on accounts that haven't posted in over a week
Port 3d332948703c6bb02d8505e5a12ad6676791980c to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
c16cbb98e5
commit
29e6db98f2
@ -74,6 +74,7 @@ interface AccountProps {
|
|||||||
defaultAction?: 'block' | 'mute';
|
defaultAction?: 'block' | 'mute';
|
||||||
withBio?: boolean;
|
withBio?: boolean;
|
||||||
withMenu?: boolean;
|
withMenu?: boolean;
|
||||||
|
extraAccountInfo?: React.ReactNode;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +86,7 @@ export const Account: React.FC<AccountProps> = ({
|
|||||||
defaultAction,
|
defaultAction,
|
||||||
withBio,
|
withBio,
|
||||||
withMenu = true,
|
withMenu = true,
|
||||||
|
extraAccountInfo,
|
||||||
children,
|
children,
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
@ -349,6 +351,8 @@ export const Account: React.FC<AccountProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
{extraAccountInfo}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!minimal && (
|
{!minimal && (
|
||||||
|
|||||||
@ -6,12 +6,14 @@ import { useHistory, useLocation } from 'react-router-dom';
|
|||||||
|
|
||||||
import CancelIcon from '@/material-icons/400-24px/cancel.svg?react';
|
import CancelIcon from '@/material-icons/400-24px/cancel.svg?react';
|
||||||
import CheckIcon from '@/material-icons/400-24px/check.svg?react';
|
import CheckIcon from '@/material-icons/400-24px/check.svg?react';
|
||||||
|
import WarningIcon from '@/material-icons/400-24px/warning.svg?react';
|
||||||
import { showAlertForError } from 'flavours/glitch/actions/alerts';
|
import { showAlertForError } from 'flavours/glitch/actions/alerts';
|
||||||
import { openModal } from 'flavours/glitch/actions/modal';
|
import { openModal } from 'flavours/glitch/actions/modal';
|
||||||
import { apiFollowAccount } from 'flavours/glitch/api/accounts';
|
import { apiFollowAccount } from 'flavours/glitch/api/accounts';
|
||||||
import type { ApiCollectionJSON } from 'flavours/glitch/api_types/collections';
|
import type { ApiCollectionJSON } from 'flavours/glitch/api_types/collections';
|
||||||
import { Account } from 'flavours/glitch/components/account';
|
import { Account } from 'flavours/glitch/components/account';
|
||||||
import { Avatar } from 'flavours/glitch/components/avatar';
|
import { Avatar } from 'flavours/glitch/components/avatar';
|
||||||
|
import { Badge } from 'flavours/glitch/components/badge';
|
||||||
import { Button } from 'flavours/glitch/components/button';
|
import { Button } from 'flavours/glitch/components/button';
|
||||||
import { Callout } from 'flavours/glitch/components/callout';
|
import { Callout } from 'flavours/glitch/components/callout';
|
||||||
import { DisplayName } from 'flavours/glitch/components/display_name';
|
import { DisplayName } from 'flavours/glitch/components/display_name';
|
||||||
@ -40,19 +42,51 @@ import { WizardStepHeader } from './wizard_step_header';
|
|||||||
const MIN_ACCOUNT_COUNT = 1;
|
const MIN_ACCOUNT_COUNT = 1;
|
||||||
const MAX_ACCOUNT_COUNT = 25;
|
const MAX_ACCOUNT_COUNT = 25;
|
||||||
|
|
||||||
|
function isOlderThanAWeek(date?: string): boolean {
|
||||||
|
if (!date) return false;
|
||||||
|
|
||||||
|
const targetDate = new Date(date);
|
||||||
|
const sevenDaysAgo = new Date();
|
||||||
|
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
|
||||||
|
return targetDate < sevenDaysAgo;
|
||||||
|
}
|
||||||
|
|
||||||
const AddedAccountItem: React.FC<{
|
const AddedAccountItem: React.FC<{
|
||||||
accountId: string;
|
accountId: string;
|
||||||
isRemovable: boolean;
|
isRemovable: boolean;
|
||||||
onRemove: (id: string) => void;
|
onRemove: (id: string) => void;
|
||||||
}> = ({ accountId, isRemovable, onRemove }) => {
|
}> = ({ accountId, isRemovable, onRemove }) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const account = useAccount(accountId);
|
||||||
|
|
||||||
const handleRemoveAccount = useCallback(() => {
|
const handleRemoveAccount = useCallback(() => {
|
||||||
onRemove(accountId);
|
onRemove(accountId);
|
||||||
}, [accountId, onRemove]);
|
}, [accountId, onRemove]);
|
||||||
|
|
||||||
|
const lastPostHint = useMemo(
|
||||||
|
() =>
|
||||||
|
isOlderThanAWeek(account?.last_status_at) && (
|
||||||
|
<Badge
|
||||||
|
label={
|
||||||
|
<FormattedMessage
|
||||||
|
id='collections.old_last_post_note'
|
||||||
|
defaultMessage='Last posted over a week ago'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
icon={<WarningIcon />}
|
||||||
|
className={classes.accountBadge}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
[account?.last_status_at],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Account minimal key={accountId} id={accountId}>
|
<Account
|
||||||
|
minimal
|
||||||
|
key={accountId}
|
||||||
|
id={accountId}
|
||||||
|
extraAccountInfo={lastPostHint}
|
||||||
|
>
|
||||||
{isRemovable && (
|
{isRemovable && (
|
||||||
<IconButton
|
<IconButton
|
||||||
title={intl.formatMessage({
|
title={intl.formatMessage({
|
||||||
|
|||||||
@ -86,3 +86,12 @@
|
|||||||
margin-inline: auto;
|
margin-inline: auto;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.accountBadge {
|
||||||
|
margin-inline-start: 56px;
|
||||||
|
|
||||||
|
@container (width < 360px) {
|
||||||
|
margin-top: 4px;
|
||||||
|
margin-inline-start: 46px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user