2024-10-11 03:15:21 +00:00
|
|
|
import { MastodonClient } from 'soapbox/api/MastodonClient';
|
2022-08-09 15:24:43 +00:00
|
|
|
|
2024-10-09 06:46:46 +00:00
|
|
|
import { useAppSelector } from './useAppSelector';
|
|
|
|
import { useOwnAccount } from './useOwnAccount';
|
2022-08-09 15:24:43 +00:00
|
|
|
|
2024-10-11 03:15:21 +00:00
|
|
|
export function useApi(): MastodonClient {
|
2024-10-09 06:46:46 +00:00
|
|
|
const { account } = useOwnAccount();
|
|
|
|
const accessToken = useAppSelector((state) => account ? state.auth.users.get(account.url)?.access_token : undefined);
|
2024-10-11 03:15:21 +00:00
|
|
|
const baseUrl = account ? new URL(account.url).origin : location.origin;
|
2024-10-09 06:46:46 +00:00
|
|
|
|
2024-10-11 03:15:21 +00:00
|
|
|
return new MastodonClient(baseUrl, accessToken);
|
2024-10-09 06:46:46 +00:00
|
|
|
}
|