import { useEffect } from 'react';
import { FormattedMessage } from 'react-intl';
import { Link } from 'react-router-dom';
import AddIcon from '@/material-icons/400-24px/add.svg?react';
import { DisplayName } from 'mastodon/components/display_name';
import { EmptyState } from 'mastodon/components/empty_state';
import { Icon } from 'mastodon/components/icon';
import { LoadingIndicator } from 'mastodon/components/loading_indicator';
import { ItemList } from 'mastodon/components/scrollable_list/components';
import { useAccount } from 'mastodon/hooks/useAccount';
import { useAccountId, useCurrentAccountId } from 'mastodon/hooks/useAccountId';
import {
fetchCollectionsCreatedByAccount,
selectAccountCollections,
} from 'mastodon/reducers/slices/collections';
import { useAppSelector, useAppDispatch } from 'mastodon/store';
import { CollectionListItem } from '../components/collection_list_item';
import {
messages as editorMessages,
MaxCollectionsCallout,
userCollectionLimit,
} from '../editor';
import classes from '../styles.module.scss';
const CreateButton: React.FC = () => (
);
export const CollectionListError: React.FC = () => (
}
/>
);
export function useCollectionsCreatedBy(accountId: string | null | undefined) {
const dispatch = useAppDispatch();
useEffect(() => {
if (accountId) {
void dispatch(fetchCollectionsCreatedByAccount({ accountId }));
}
}, [dispatch, accountId]);
return useAppSelector((state) =>
selectAccountCollections(state, accountId, 'createdBy'),
);
}
export const CollectionsCreatedByAccount: React.FC = () => {
const me = useCurrentAccountId();
const accountId = useAccountId();
const account = useAccount(accountId);
const { collections, status } = useCollectionsCreatedBy(accountId);
const canCreateMoreCollections = collections.length < userCollectionLimit;
const isOwnCollectionPage = accountId === me;
const showCreateButton =
isOwnCollectionPage && status === 'idle' && canCreateMoreCollections;
if (status === 'error' || !accountId) {
return ;
}
if (status === 'loading') {
return ;
}
if (collections.length === 0) {
if (isOwnCollectionPage) {
return (
}
message={
}
>
);
} else {
return (
,
}}
/>
}
/>
);
}
}
return (
<>
{showCreateButton && }
{isOwnCollectionPage && !canCreateMoreCollections && (
)}
{collections.map((item, index) => (
))}
>
);
};