diff --git a/app/soapbox/pages/profile_page.tsx b/app/soapbox/pages/profile_page.tsx index 5cf8bee21d..e1691e14b6 100644 --- a/app/soapbox/pages/profile_page.tsx +++ b/app/soapbox/pages/profile_page.tsx @@ -27,23 +27,22 @@ interface IProfilePage { }, } +/** Page to display a user's profile. */ const ProfilePage: React.FC = ({ params, children }) => { const history = useHistory(); + const username = params?.username || ''; - const { accountId, account, accountUsername, realAccount } = useAppSelector(state => { - const username = params?.username || ''; + const { accountId, account, realAccount } = useAppSelector(state => { const { accounts } = state; const accountFetchError = (((state.accounts.getIn([-1, 'username']) || '') as string).toLowerCase() === username.toLowerCase()); let accountId: string | -1 | null = -1; let account = null; - let accountUsername = username; if (accountFetchError) { accountId = null; } else { account = findAccountByUsername(state, username); accountId = account ? account.id : -1; - accountUsername = account ? account.acct : ''; } let realAccount; @@ -57,7 +56,6 @@ const ProfilePage: React.FC = ({ params, children }) => { return { account: typeof accountId === 'string' ? getAccount(state, accountId) : account, accountId, - accountUsername, realAccount, }; }); @@ -66,24 +64,30 @@ const ProfilePage: React.FC = ({ params, children }) => { const features = useFeatures(); const { displayFqn } = useSoapboxConfig(); + // Redirect from a user ID if (realAccount) { return ; } + // Fix case of username + if (account && account.acct !== username) { + return ; + } + const tabItems = [ { text: , - to: `/@${accountUsername}`, + to: `/@${username}`, name: 'profile', }, { text: , - to: `/@${accountUsername}/with_replies`, + to: `/@${username}/with_replies`, name: 'replies', }, { text: , - to: `/@${accountUsername}/media`, + to: `/@${username}/media`, name: 'media', }, ]; @@ -100,14 +104,14 @@ const ProfilePage: React.FC = ({ params, children }) => { } let activeItem; - const pathname = history.location.pathname.replace(`@${accountUsername}/`, ''); + const pathname = history.location.pathname.replace(`@${username}/`, ''); if (pathname.includes('with_replies')) { activeItem = 'replies'; } else if (pathname.includes('media')) { activeItem = 'media'; } else if (pathname.includes('favorites')) { activeItem = 'likes'; - } else if (pathname === `/@${accountUsername}`) { + } else { activeItem = 'profile'; } @@ -117,13 +121,13 @@ const ProfilePage: React.FC = ({ params, children }) => {
{/* @ts-ignore */} - + - {Component => } + {Component => } - {account && activeItem && ( + {account && ( )}