Fixed Follow for ActivityPub (#20544)

We need to make requests to the frontend URL, not the Admin API - but
the Admin X Framework doesn't currently support that, so instead we'll
use a simple `fetch` for now.

---------

Co-authored-by: Princi Vershwal <vershwal.princi@gmail.com>
This commit is contained in:
Fabien 'egg' O'Carroll 2024-07-04 17:58:18 +07:00 committed by GitHub
parent e58fd86b96
commit 3e4b8d825d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
import NiceModal from '@ebay/nice-modal-react';
import {Modal, TextField, showToast} from '@tryghost/admin-x-design-system';
import {useBrowseSite} from '@tryghost/admin-x-framework/api/site';
import {useFollow} from '@tryghost/admin-x-framework/api/activitypub';
import {useQueryClient} from '@tryghost/admin-x-framework';
import {useRouting} from '@tryghost/admin-x-framework/routing';
@ -16,6 +17,9 @@ const FollowSite = NiceModal.create(() => {
const modal = NiceModal.useModal();
const mutation = useFollow();
const client = useQueryClient();
const site = useBrowseSite();
const siteData = site.data?.site;
const siteUrl = siteData?.url ?? window.location.origin;
// mutation.isPending
// mutation.isError
@ -30,8 +34,11 @@ const FollowSite = NiceModal.create(() => {
const handleFollow = async () => {
try {
const url = new URL(`.ghost/activitypub/actions/follow/${profileName}`, siteUrl);
await fetch(url, {
method: 'POST'
});
// Perform the mutation
await mutation.mutateAsync({username: profileName});
// If successful, set the success state to true
// setSuccess(true);
showToast({