SidebarMenu: useAccount hook
This commit is contained in:
parent
e01ee84ee9
commit
69d8817b6d
|
@ -1,17 +1,18 @@
|
||||||
/* eslint-disable jsx-a11y/interactive-supports-focus */
|
/* eslint-disable jsx-a11y/interactive-supports-focus */
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import React from 'react';
|
import React, { useCallback } from 'react';
|
||||||
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
|
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
|
||||||
import { Link, NavLink } from 'react-router-dom';
|
import { Link, NavLink } from 'react-router-dom';
|
||||||
|
|
||||||
import { fetchOwnAccounts, logOut, switchAccount } from 'soapbox/actions/auth';
|
import { fetchOwnAccounts, logOut, switchAccount } from 'soapbox/actions/auth';
|
||||||
import { getSettings } from 'soapbox/actions/settings';
|
import { getSettings } from 'soapbox/actions/settings';
|
||||||
import { closeSidebar } from 'soapbox/actions/sidebar';
|
import { closeSidebar } from 'soapbox/actions/sidebar';
|
||||||
|
import { useAccount } from 'soapbox/api/hooks';
|
||||||
import Account from 'soapbox/components/account';
|
import Account from 'soapbox/components/account';
|
||||||
import { Stack } from 'soapbox/components/ui';
|
import { Stack } from 'soapbox/components/ui';
|
||||||
import ProfileStats from 'soapbox/features/ui/components/profile-stats';
|
import ProfileStats from 'soapbox/features/ui/components/profile-stats';
|
||||||
import { useAppDispatch, useAppSelector, useGroupsPath, useFeatures } from 'soapbox/hooks';
|
import { useAppDispatch, useAppSelector, useGroupsPath, useFeatures } from 'soapbox/hooks';
|
||||||
import { makeGetAccount, makeGetOtherAccounts } from 'soapbox/selectors';
|
import { makeGetOtherAccounts } from 'soapbox/selectors';
|
||||||
|
|
||||||
import { Divider, HStack, Icon, IconButton, Text } from './ui';
|
import { Divider, HStack, Icon, IconButton, Text } from './ui';
|
||||||
|
|
||||||
|
@ -76,16 +77,14 @@ const SidebarLink: React.FC<ISidebarLink> = ({ href, to, icon, text, onClick })
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getOtherAccounts = makeGetOtherAccounts();
|
|
||||||
|
|
||||||
const SidebarMenu: React.FC = (): JSX.Element | null => {
|
const SidebarMenu: React.FC = (): JSX.Element | null => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
const getOtherAccounts = useCallback(makeGetOtherAccounts(), []);
|
||||||
const features = useFeatures();
|
const features = useFeatures();
|
||||||
const getAccount = makeGetAccount();
|
|
||||||
const me = useAppSelector((state) => state.me);
|
const me = useAppSelector((state) => state.me);
|
||||||
const account = useAppSelector((state) => me ? getAccount(state, me) : null);
|
const { account } = useAccount(me || undefined);
|
||||||
const otherAccounts: ImmutableList<AccountEntity> = useAppSelector((state) => getOtherAccounts(state));
|
const otherAccounts: ImmutableList<AccountEntity> = useAppSelector((state) => getOtherAccounts(state));
|
||||||
const sidebarOpen = useAppSelector((state) => state.sidebar.sidebarOpen);
|
const sidebarOpen = useAppSelector((state) => state.sidebar.sidebarOpen);
|
||||||
const settings = useAppSelector((state) => getSettings(state));
|
const settings = useAppSelector((state) => getSettings(state));
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { NavLink } from 'react-router-dom';
|
||||||
import { HStack, Text } from 'soapbox/components/ui';
|
import { HStack, Text } from 'soapbox/components/ui';
|
||||||
import { shortNumberFormat } from 'soapbox/utils/numbers';
|
import { shortNumberFormat } from 'soapbox/utils/numbers';
|
||||||
|
|
||||||
import type { Account } from 'soapbox/types/entities';
|
import type { Account } from 'soapbox/schemas';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
followers: { id: 'account.followers', defaultMessage: 'Followers' },
|
followers: { id: 'account.followers', defaultMessage: 'Followers' },
|
||||||
|
@ -13,7 +13,7 @@ const messages = defineMessages({
|
||||||
});
|
});
|
||||||
|
|
||||||
interface IProfileStats {
|
interface IProfileStats {
|
||||||
account: Account | undefined
|
account: Pick<Account, 'acct' | 'followers_count' | 'following_count'> | undefined
|
||||||
onClickHandler?: React.MouseEventHandler
|
onClickHandler?: React.MouseEventHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue