[Glitch] Improve collection page loading states
Port afeb63d287a888d0ae475ab0c66ce53c0595d489 to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
675c19a18b
commit
e4fba99ab5
@ -99,15 +99,14 @@ const getCollectionItems = createAppSelector(
|
||||
);
|
||||
|
||||
export const CollectionAccountsList: React.FC<{
|
||||
collection?: ApiCollectionJSON;
|
||||
isLoading: boolean;
|
||||
}> = ({ collection, isLoading }) => {
|
||||
collection: ApiCollectionJSON;
|
||||
}> = ({ collection }) => {
|
||||
const intl = useIntl();
|
||||
const confirmRevoke = useConfirmRevoke(collection);
|
||||
const listHeadingRef = useRef<HTMLHeadingElement>(null);
|
||||
|
||||
const isOwnCollection = collection?.account_id === me;
|
||||
const { account_id: collectionOwnerId, id } = collection ?? {};
|
||||
const isOwnCollection = collection.account_id === me;
|
||||
const { account_id: collectionOwnerId, id } = collection;
|
||||
|
||||
const relationships = useAppSelector((state) => state.relationships);
|
||||
const collectionAccounts = useAppSelector((state) =>
|
||||
@ -194,28 +193,17 @@ export const CollectionAccountsList: React.FC<{
|
||||
tabIndex={-1}
|
||||
ref={listHeadingRef}
|
||||
>
|
||||
{collection ? (
|
||||
<FormattedMessage
|
||||
id='collections.account_count'
|
||||
defaultMessage='{count, plural, one {# account} other {# accounts}}'
|
||||
values={{ count: collection.item_count }}
|
||||
/>
|
||||
) : (
|
||||
<FormattedMessage
|
||||
id='collections.detail.accounts_heading'
|
||||
defaultMessage='Accounts'
|
||||
/>
|
||||
)}
|
||||
</h3>
|
||||
{collection && (
|
||||
<SensitiveScreen
|
||||
sensitive={!isOwnCollection && collection.sensitive}
|
||||
focusTargetRef={listHeadingRef}
|
||||
>
|
||||
<ItemList
|
||||
isLoading={isLoading}
|
||||
emptyMessage={intl.formatMessage(messages.empty)}
|
||||
>
|
||||
<ItemList emptyMessage={intl.formatMessage(messages.empty)}>
|
||||
<TruncatedListItems
|
||||
visibleItems={visibleAccounts}
|
||||
truncatedItems={hiddenAccounts}
|
||||
@ -240,7 +228,6 @@ export const CollectionAccountsList: React.FC<{
|
||||
/>
|
||||
</ItemList>
|
||||
</SensitiveScreen>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@ -23,6 +23,7 @@ import { DisplayName } from 'flavours/glitch/components/display_name';
|
||||
import { useAccountHandle } from 'flavours/glitch/components/display_name/default';
|
||||
import { FormattedDateWrapper } from 'flavours/glitch/components/formatted_date';
|
||||
import { IconButton } from 'flavours/glitch/components/icon_button';
|
||||
import { LoadingIndicator } from 'flavours/glitch/components/loading_indicator';
|
||||
import { Scrollable } from 'flavours/glitch/components/scrollable_list/components';
|
||||
import { useAccount } from 'flavours/glitch/hooks/useAccount';
|
||||
import { domain, me } from 'flavours/glitch/initial_state';
|
||||
@ -218,7 +219,6 @@ export const CollectionDetailPage: React.FC<{
|
||||
const collection = useAppSelector((state) =>
|
||||
id ? state.collections.collections[id] : undefined,
|
||||
);
|
||||
const isLoading = !!id && !collection;
|
||||
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
@ -239,8 +239,14 @@ export const CollectionDetailPage: React.FC<{
|
||||
/>
|
||||
|
||||
<Scrollable>
|
||||
{collection && <CollectionHeader collection={collection} />}
|
||||
<CollectionAccountsList collection={collection} isLoading={isLoading} />
|
||||
{collection ? (
|
||||
<>
|
||||
<CollectionHeader collection={collection} />
|
||||
<CollectionAccountsList collection={collection} />
|
||||
</>
|
||||
) : (
|
||||
<LoadingIndicator />
|
||||
)}
|
||||
</Scrollable>
|
||||
|
||||
<Helmet>
|
||||
|
||||
@ -6,6 +6,7 @@ import { Helmet } from 'react-helmet';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { EmptyState } from '@/flavours/glitch/components/empty_state';
|
||||
import { LoadingIndicator } from '@/flavours/glitch/components/loading_indicator';
|
||||
import { TabLink, TabList } from '@/flavours/glitch/components/tab_list';
|
||||
import AddIcon from '@/material-icons/400-24px/add.svg?react';
|
||||
import { Column } from 'flavours/glitch/components/column';
|
||||
@ -131,9 +132,10 @@ export const Collections: React.FC<{
|
||||
</TabLink>
|
||||
</TabList>
|
||||
</header>
|
||||
{collections.length > 0 ? (
|
||||
{status === 'loading' && <LoadingIndicator />}
|
||||
{status === 'idle' &&
|
||||
(collections.length > 0 ? (
|
||||
<>
|
||||
{status === 'idle' && (
|
||||
<div className={classes.listHeader}>
|
||||
<h2 className={classes.subHeading}>
|
||||
<FormattedMessage
|
||||
@ -146,11 +148,7 @@ export const Collections: React.FC<{
|
||||
</h2>
|
||||
{showCreateButton && <CreateButton />}
|
||||
</div>
|
||||
)}
|
||||
<ItemList
|
||||
emptyMessage={errorMessage}
|
||||
isLoading={status === 'loading'}
|
||||
>
|
||||
<ItemList emptyMessage={errorMessage}>
|
||||
{!canCreateMoreCollections && (
|
||||
<MaxCollectionsCallout
|
||||
className={classes.maxCollectionsError}
|
||||
@ -185,7 +183,7 @@ export const Collections: React.FC<{
|
||||
>
|
||||
<CreateButton />
|
||||
</EmptyState>
|
||||
)}
|
||||
))}
|
||||
</Scrollable>
|
||||
|
||||
<Helmet>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user