mirror of
https://github.com/mastodon/mastodon.git
synced 2026-09-12 07:45:48 -05:00
New hook useFollowReference
This commit is contained in:
@@ -3,10 +3,9 @@ import type { FC } from 'react';
|
||||
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import { useLocation } from 'react-router-dom';
|
||||
|
||||
import { followAccount } from '@/mastodon/actions/accounts';
|
||||
import { useAccount } from '@/mastodon/hooks/useAccount';
|
||||
import { useFollowReference } from '@/mastodon/hooks/useFollowReference';
|
||||
import { getAccountHidden } from '@/mastodon/selectors/accounts';
|
||||
import { useAppDispatch, useAppSelector } from '@/mastodon/store';
|
||||
import NotificationsIcon from '@/material-icons/400-24px/notifications.svg?react';
|
||||
@@ -83,10 +82,8 @@ const AccountButtonsOther: FC<
|
||||
});
|
||||
}
|
||||
}, [accountUrl]);
|
||||
const { state } = useLocation<{
|
||||
reference?: string;
|
||||
} | null>();
|
||||
const reference = state?.reference ?? 'profile';
|
||||
|
||||
const reference = useFollowReference('profile');
|
||||
|
||||
if (!account) {
|
||||
return null;
|
||||
|
||||
9
app/javascript/mastodon/hooks/useFollowReference.ts
Normal file
9
app/javascript/mastodon/hooks/useFollowReference.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { useLocation } from 'react-router-dom';
|
||||
|
||||
import type { LocationState } from '../components/router';
|
||||
|
||||
export function useFollowReference(fallbackReference: string) {
|
||||
const { state } = useLocation<LocationState>();
|
||||
|
||||
return state?.reference ?? fallbackReference;
|
||||
}
|
||||
Reference in New Issue
Block a user