import { List as ImmutableList } from 'immutable'; import React, { useEffect } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { fetchAliases, removeFromAliases } from 'soapbox/actions/aliases'; import Icon from 'soapbox/components/icon'; import ScrollableList from 'soapbox/components/scrollable-list'; import { CardHeader, CardTitle, Column, HStack, Text } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import { makeGetAccount } from 'soapbox/selectors'; import { getFeatures } from 'soapbox/utils/features'; import Account from './components/account'; import Search from './components/search'; const messages = defineMessages({ heading: { id: 'column.aliases', defaultMessage: 'Account aliases' }, subheading_add_new: { id: 'column.aliases.subheading_add_new', defaultMessage: 'Add New Alias' }, create_error: { id: 'column.aliases.create_error', defaultMessage: 'Error creating alias' }, delete_error: { id: 'column.aliases.delete_error', defaultMessage: 'Error deleting alias' }, subheading_aliases: { id: 'column.aliases.subheading_aliases', defaultMessage: 'Current aliases' }, delete: { id: 'column.aliases.delete', defaultMessage: 'Delete' }, }); const getAccount = makeGetAccount(); const Aliases = () => { const intl = useIntl(); const dispatch = useAppDispatch(); const aliases = useAppSelector((state) => { const me = state.me as string; const account = getAccount(state, me); const instance = state.instance; const features = getFeatures(instance); if (features.accountMoving) return state.aliases.aliases.items; return account!.pleroma.get('also_known_as'); }) as ImmutableList; const searchAccountIds = useAppSelector((state) => state.aliases.suggestions.items); const loaded = useAppSelector((state) => state.aliases.suggestions.loaded); useEffect(() => { dispatch(fetchAliases); }, []); const handleFilterDelete: React.MouseEventHandler = e => { dispatch(removeFromAliases(e.currentTarget.dataset.value as string)); }; const emptyMessage = ; return ( { loaded && searchAccountIds.size === 0 ? (
) : (
{searchAccountIds.map(accountId => )}
) }
{aliases.map((alias, i) => (
{' '} {alias}
))}
); }; export default Aliases;