New hook useFollowReference

This commit is contained in:
diondiondion
2026-09-11 11:35:11 +02:00
parent af9cc84682
commit de88222fb0
2 changed files with 12 additions and 6 deletions

View File

@@ -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;

View 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;
}