[Glitch] Change "My collections" path to /@username/collections
Port d6c0b93c859febbb88332276d8fa40b9297efbea to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
852e3052e8
commit
4c38bcce5d
@ -73,7 +73,7 @@ const BackButton: React.FC<{
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
title?: string;
|
title?: React.ReactNode;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
iconComponent?: IconProp;
|
iconComponent?: IconProp;
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
|
|||||||
@ -10,11 +10,17 @@ import CollectionsFilledIcon from '@/material-icons/400-24px/category-fill.svg?r
|
|||||||
import SquigglyArrow from '@/svg-icons/squiggly_arrow.svg?react';
|
import SquigglyArrow from '@/svg-icons/squiggly_arrow.svg?react';
|
||||||
import { Column } from 'flavours/glitch/components/column';
|
import { Column } from 'flavours/glitch/components/column';
|
||||||
import { ColumnHeader } from 'flavours/glitch/components/column_header';
|
import { ColumnHeader } from 'flavours/glitch/components/column_header';
|
||||||
|
import { DisplayNameSimple } from 'flavours/glitch/components/display_name/simple';
|
||||||
import { Icon } from 'flavours/glitch/components/icon';
|
import { Icon } from 'flavours/glitch/components/icon';
|
||||||
import {
|
import {
|
||||||
ItemList,
|
ItemList,
|
||||||
Scrollable,
|
Scrollable,
|
||||||
} from 'flavours/glitch/components/scrollable_list/components';
|
} from 'flavours/glitch/components/scrollable_list/components';
|
||||||
|
import { useAccount } from 'flavours/glitch/hooks/useAccount';
|
||||||
|
import {
|
||||||
|
useAccountId,
|
||||||
|
useCurrentAccountId,
|
||||||
|
} from 'flavours/glitch/hooks/useAccountId';
|
||||||
import {
|
import {
|
||||||
fetchAccountCollections,
|
fetchAccountCollections,
|
||||||
selectAccountCollections,
|
selectAccountCollections,
|
||||||
@ -25,7 +31,11 @@ import { CollectionListItem } from './components/collection_list_item';
|
|||||||
import { messages as editorMessages } from './editor';
|
import { messages as editorMessages } from './editor';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
heading: { id: 'column.collections', defaultMessage: 'My collections' },
|
headingMe: { id: 'column.my_collections', defaultMessage: 'My collections' },
|
||||||
|
headingOther: {
|
||||||
|
id: 'column.other_collections',
|
||||||
|
defaultMessage: 'Collections by {name}',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Collections: React.FC<{
|
export const Collections: React.FC<{
|
||||||
@ -33,17 +43,22 @@ export const Collections: React.FC<{
|
|||||||
}> = ({ multiColumn }) => {
|
}> = ({ multiColumn }) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const me = useAppSelector((state) => state.meta.get('me') as string);
|
const me = useCurrentAccountId();
|
||||||
|
const accountId = useAccountId();
|
||||||
|
const account = useAccount(accountId);
|
||||||
|
|
||||||
const { collections, status } = useAppSelector((state) =>
|
const { collections, status } = useAppSelector((state) =>
|
||||||
selectAccountCollections(state, me),
|
selectAccountCollections(state, accountId),
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void dispatch(fetchAccountCollections({ accountId: me }));
|
if (accountId) {
|
||||||
}, [dispatch, me]);
|
void dispatch(fetchAccountCollections({ accountId }));
|
||||||
|
}
|
||||||
|
}, [dispatch, accountId]);
|
||||||
|
|
||||||
const emptyMessage =
|
const emptyMessage =
|
||||||
status === 'error' ? (
|
status === 'error' || !accountId ? (
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='collections.error_loading_collections'
|
id='collections.error_loading_collections'
|
||||||
defaultMessage='There was an error when trying to load your collections.'
|
defaultMessage='There was an error when trying to load your collections.'
|
||||||
@ -67,25 +82,36 @@ export const Collections: React.FC<{
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isOwnCollection = accountId === me;
|
||||||
|
const titleMessage = isOwnCollection
|
||||||
|
? messages.headingMe
|
||||||
|
: messages.headingOther;
|
||||||
|
|
||||||
|
const pageTitle = intl.formatMessage(titleMessage, {
|
||||||
|
name: account?.get('display_name'),
|
||||||
|
});
|
||||||
|
const pageTitleHtml = intl.formatMessage(titleMessage, {
|
||||||
|
name: <DisplayNameSimple account={account} />,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column
|
<Column bindToDocument={!multiColumn} label={pageTitle}>
|
||||||
bindToDocument={!multiColumn}
|
|
||||||
label={intl.formatMessage(messages.heading)}
|
|
||||||
>
|
|
||||||
<ColumnHeader
|
<ColumnHeader
|
||||||
title={intl.formatMessage(messages.heading)}
|
title={pageTitleHtml}
|
||||||
icon='collections'
|
icon='collections'
|
||||||
iconComponent={CollectionsFilledIcon}
|
iconComponent={CollectionsFilledIcon}
|
||||||
multiColumn={multiColumn}
|
multiColumn={multiColumn}
|
||||||
extraButton={
|
extraButton={
|
||||||
<Link
|
isOwnCollection && (
|
||||||
to='/collections/new'
|
<Link
|
||||||
className='column-header__button'
|
to='/collections/new'
|
||||||
title={intl.formatMessage(editorMessages.create)}
|
className='column-header__button'
|
||||||
aria-label={intl.formatMessage(editorMessages.create)}
|
title={intl.formatMessage(editorMessages.create)}
|
||||||
>
|
aria-label={intl.formatMessage(editorMessages.create)}
|
||||||
<Icon id='plus' icon={AddIcon} />
|
>
|
||||||
</Link>
|
<Icon id='plus' icon={AddIcon} />
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -105,7 +131,7 @@ export const Collections: React.FC<{
|
|||||||
</Scrollable>
|
</Scrollable>
|
||||||
|
|
||||||
<Helmet>
|
<Helmet>
|
||||||
<title>{intl.formatMessage(messages.heading)}</title>
|
<title>{pageTitle}</title>
|
||||||
<meta name='robots' content='noindex' />
|
<meta name='robots' content='noindex' />
|
||||||
</Helmet>
|
</Helmet>
|
||||||
</Column>
|
</Column>
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import type { Map as ImmutableMap } from 'immutable';
|
|||||||
import { animated, useSpring } from '@react-spring/web';
|
import { animated, useSpring } from '@react-spring/web';
|
||||||
import { useDrag } from '@use-gesture/react';
|
import { useDrag } from '@use-gesture/react';
|
||||||
|
|
||||||
|
import { useAccount } from '@/flavours/glitch/hooks/useAccount';
|
||||||
import AddIcon from '@/material-icons/400-24px/add.svg?react';
|
import AddIcon from '@/material-icons/400-24px/add.svg?react';
|
||||||
import AlternateEmailIcon from '@/material-icons/400-24px/alternate_email.svg?react';
|
import AlternateEmailIcon from '@/material-icons/400-24px/alternate_email.svg?react';
|
||||||
import BookmarksActiveIcon from '@/material-icons/400-24px/bookmarks-fill.svg?react';
|
import BookmarksActiveIcon from '@/material-icons/400-24px/bookmarks-fill.svg?react';
|
||||||
@ -226,6 +227,7 @@ export const NavigationPanel: React.FC<{ multiColumn?: boolean }> = ({
|
|||||||
const { signedIn, permissions, disabledAccountId } = useIdentity();
|
const { signedIn, permissions, disabledAccountId } = useIdentity();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const showSearch = useBreakpoint('full') && !multiColumn;
|
const showSearch = useBreakpoint('full') && !multiColumn;
|
||||||
|
const account = useAccount(me);
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
let banner: React.ReactNode;
|
let banner: React.ReactNode;
|
||||||
@ -361,7 +363,7 @@ export const NavigationPanel: React.FC<{ multiColumn?: boolean }> = ({
|
|||||||
{areCollectionsEnabled() && (
|
{areCollectionsEnabled() && (
|
||||||
<ColumnLink
|
<ColumnLink
|
||||||
transparent
|
transparent
|
||||||
to='/collections'
|
to={`/@${account?.acct}/collections`}
|
||||||
icon='collections'
|
icon='collections'
|
||||||
iconComponent={CollectionsIcon}
|
iconComponent={CollectionsIcon}
|
||||||
activeIconComponent={CollectionsActiveIcon}
|
activeIconComponent={CollectionsActiveIcon}
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import { defineMessages, useIntl } from 'react-intl';
|
|||||||
|
|
||||||
import { useHistory } from 'react-router';
|
import { useHistory } from 'react-router';
|
||||||
|
|
||||||
|
import { useAccount } from '@/flavours/glitch/hooks/useAccount';
|
||||||
|
import { me } from '@/flavours/glitch/initial_state';
|
||||||
import { deleteCollection } from 'flavours/glitch/reducers/slices/collections';
|
import { deleteCollection } from 'flavours/glitch/reducers/slices/collections';
|
||||||
import { useAppDispatch } from 'flavours/glitch/store';
|
import { useAppDispatch } from 'flavours/glitch/store';
|
||||||
|
|
||||||
@ -34,11 +36,12 @@ export const ConfirmDeleteCollectionModal: React.FC<
|
|||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const { acct: currentUserName } = useAccount(me) ?? {};
|
||||||
|
|
||||||
const onConfirm = useCallback(() => {
|
const onConfirm = useCallback(() => {
|
||||||
void dispatch(deleteCollection({ collectionId: id }));
|
void dispatch(deleteCollection({ collectionId: id }));
|
||||||
history.push('/collections');
|
history.push(`/@${currentUserName}/collections`);
|
||||||
}, [dispatch, history, id]);
|
}, [dispatch, history, id, currentUserName]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfirmationModal
|
<ConfirmationModal
|
||||||
|
|||||||
@ -240,6 +240,13 @@ class SwitchingColumnsArea extends PureComponent {
|
|||||||
|
|
||||||
<WrappedRoute path={['/@:acct', '/accounts/:id']} exact component={AccountTimeline} content={children} />
|
<WrappedRoute path={['/@:acct', '/accounts/:id']} exact component={AccountTimeline} content={children} />
|
||||||
<WrappedRoute path={['/@:acct/featured', '/accounts/:id/featured']} component={AccountFeatured} content={children} />
|
<WrappedRoute path={['/@:acct/featured', '/accounts/:id/featured']} component={AccountFeatured} content={children} />
|
||||||
|
{areCollectionsEnabled() &&
|
||||||
|
[
|
||||||
|
<WrappedRoute path={['/@:acct/collections']} component={Collections} content={children} key='collections-list' />,
|
||||||
|
<WrappedRoute path={['/collections/new', '/collections/:id/edit']} component={CollectionsEditor} content={children} key='collections-editor' />,
|
||||||
|
<WrappedRoute path='/collections/:id' component={CollectionDetail} content={children} key='collections-detail' />,
|
||||||
|
]
|
||||||
|
}
|
||||||
<WrappedRoute path='/@:acct/tagged/:tagged?' exact component={AccountTimeline} content={children} />
|
<WrappedRoute path='/@:acct/tagged/:tagged?' exact component={AccountTimeline} content={children} />
|
||||||
<WrappedRoute path={['/@:acct/with_replies', '/accounts/:id/with_replies']} component={AccountTimeline} content={children} componentParams={{ withReplies: true }} />
|
<WrappedRoute path={['/@:acct/with_replies', '/accounts/:id/with_replies']} component={AccountTimeline} content={children} componentParams={{ withReplies: true }} />
|
||||||
<WrappedRoute path={['/accounts/:id/followers', '/users/:acct/followers', '/@:acct/followers']} component={Followers} content={children} />
|
<WrappedRoute path={['/accounts/:id/followers', '/users/:acct/followers', '/@:acct/followers']} component={Followers} content={children} />
|
||||||
@ -263,13 +270,6 @@ class SwitchingColumnsArea extends PureComponent {
|
|||||||
<WrappedRoute path='/followed_tags' component={FollowedTags} content={children} />
|
<WrappedRoute path='/followed_tags' component={FollowedTags} content={children} />
|
||||||
<WrappedRoute path='/mutes' component={Mutes} content={children} />
|
<WrappedRoute path='/mutes' component={Mutes} content={children} />
|
||||||
<WrappedRoute path='/lists' component={Lists} content={children} />
|
<WrappedRoute path='/lists' component={Lists} content={children} />
|
||||||
{areCollectionsEnabled() &&
|
|
||||||
[
|
|
||||||
<WrappedRoute path={['/collections/new', '/collections/:id/edit']} component={CollectionsEditor} content={children} key='collections-editor' />,
|
|
||||||
<WrappedRoute path='/collections/:id' component={CollectionDetail} content={children} key='collections-detail' />,
|
|
||||||
<WrappedRoute path='/collections' component={Collections} content={children} key='collections-list' />
|
|
||||||
]
|
|
||||||
}
|
|
||||||
<Route component={BundleColumnError} />
|
<Route component={BundleColumnError} />
|
||||||
</WrappedSwitch>
|
</WrappedSwitch>
|
||||||
</ColumnsArea>
|
</ColumnsArea>
|
||||||
|
|||||||
@ -311,7 +311,7 @@ interface AccountCollectionQuery {
|
|||||||
|
|
||||||
export const selectAccountCollections = createAppSelector(
|
export const selectAccountCollections = createAppSelector(
|
||||||
[
|
[
|
||||||
(_, accountId: string | null) => accountId,
|
(_, accountId?: string | null) => accountId,
|
||||||
(state) => state.collections.accountCollections,
|
(state) => state.collections.accountCollections,
|
||||||
(state) => state.collections.collections,
|
(state) => state.collections.collections,
|
||||||
],
|
],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user