@@ -45,25 +53,20 @@ const SidebarLink = ({ to, icon, text, onClick }) => (
);
-SidebarLink.propTypes = {
- to: PropTypes.string.isRequired,
- icon: PropTypes.string.isRequired,
- text: PropTypes.string.isRequired,
- onClick: PropTypes.func.isRequired,
-};
+const getOtherAccounts = makeGetOtherAccounts();
-const SidebarMenu = () => {
+const SidebarMenu: React.FC = (): JSX.Element | null => {
const intl = useIntl();
const dispatch = useDispatch();
- const logo = useSelector((state) => getSoapboxConfig(state).get('logo'));
- const features = useSelector((state) => getFeatures(state.get('instance')));
+ const { logo } = useSoapboxConfig();
+ const features = useFeatures();
const getAccount = makeGetAccount();
- const getOtherAccounts = makeGetOtherAccounts();
- const me = useSelector((state) => state.get('me'));
- const account = useSelector((state) => getAccount(state, me));
- const otherAccounts = useSelector((state) => getOtherAccounts(state));
- const sidebarOpen = useSelector((state) => state.get('sidebar').sidebarOpen);
+ const instance = useAppSelector((state) => state.instance);
+ const me = useAppSelector((state) => state.me);
+ const account = useAppSelector((state) => me ? getAccount(state, me) : null);
+ const otherAccounts: ImmutableList
= useAppSelector((state) => getOtherAccounts(state));
+ const sidebarOpen = useAppSelector((state) => state.sidebar.sidebarOpen);
const closeButtonRef = React.useRef(null);
@@ -76,25 +79,27 @@ const SidebarMenu = () => {
onClose();
};
- const handleSwitchAccount = (event, account) => {
- event.preventDefault();
- switchAccount(account);
- dispatch(switchAccount(account.get('id')));
+ const handleSwitchAccount = (account: AccountEntity): React.EventHandler => {
+ return (e) => {
+ e.preventDefault();
+ switchAccount(account);
+ dispatch(switchAccount(account.id));
+ };
};
- const onClickLogOut = (event) => {
- event.preventDefault();
+ const onClickLogOut: React.EventHandler = (e) => {
+ e.preventDefault();
dispatch(logOut(intl));
};
- const handleSwitcherClick = (e) => {
+ const handleSwitcherClick: React.EventHandler = (e) => {
e.preventDefault();
setSwitcher((prevState) => (!prevState));
};
- const renderAccount = (account) => (
- handleSwitchAccount(event, account)} key={account.get('id')}>
+ const renderAccount = (account: AccountEntity) => (
+
);
@@ -103,17 +108,13 @@ const SidebarMenu = () => {
dispatch(fetchOwnAccounts());
}, []);
- if (!account) {
- return null;
- }
-
- const acct = account.get('acct');
- const classes = classNames('sidebar-menu__root', {
- 'sidebar-menu__root--visible': sidebarOpen,
- });
+ if (!account) return null;
return (
-
+
{
{logo ? (
-
+
): (
{
-
+
+ {/* TODO: make this available to everyone */}
{account.staff && (