Revert "pl-fe: migrate /api/v*/instance to tanstack query"

This reverts commit 1f8b79f309.
This commit is contained in:
mkljczk
2024-12-03 15:20:51 +01:00
parent 76b8ff2819
commit 6472a5e4e2
79 changed files with 337 additions and 240 deletions

View File

@ -56,6 +56,10 @@ const getAuthUserUrl = (state: RootState) => {
].filter(url => url).find(isURL);
};
/** Get the VAPID public key. */
const getVapidKey = (state: RootState) =>
state.auth.app?.vapid_key || state.instance.configuration.vapid.public_key;
const getMeUrl = (state: RootState) => selectOwnAccount(state)?.url;
export {
@ -67,5 +71,6 @@ export {
getAccessToken,
getAuthUserId,
getAuthUserUrl,
getVapidKey,
getMeUrl,
};

View File

@ -1,16 +1,15 @@
import { getFeatures, PLEROMA, TOKI, type Instance } from 'pl-api';
import * as BuildConfig from 'pl-fe/build-config';
import { queryClient } from 'pl-fe/queries/client';
import type { RootState } from 'pl-fe/store';
/**
* Get the OAuth scopes to use for login & signup.
* Mastodon will refuse scopes it doesn't know, so care is needed.
*/
const getInstanceScopes = (instance?: Instance) => {
const software = instance ? getFeatures(instance).version.software : null;
const getInstanceScopes = (instance: Instance) => {
const v = getFeatures(instance).version;
switch (software) {
switch (v.software) {
case TOKI:
return 'read write follow push write:bites';
case PLEROMA:
@ -21,11 +20,7 @@ const getInstanceScopes = (instance?: Instance) => {
};
/** Convenience function to get scopes from instance in store. */
const getScopes = (baseURL = BuildConfig.BACKEND_URL || '') => {
const instance = queryClient.getQueryData<Instance>(['instance', 'instanceInformation', baseURL]);
return getInstanceScopes(instance);
};
const getScopes = (state: RootState) => getInstanceScopes(state.instance);
export {
getInstanceScopes,

View File

@ -9,15 +9,14 @@ import { isPrerendered } from 'pl-fe/precheck';
import { selectOwnAccount } from 'pl-fe/selectors';
import { isURL } from 'pl-fe/utils/auth';
import type { Instance } from 'pl-api';
import type { RootState } from 'pl-fe/store';
/** Whether to display the fqn instead of the acct. */
const displayFqn = (state: RootState): boolean => getPlFeConfig(state).displayFqn;
/** Whether the instance exposes instance blocks through the API. */
const federationRestrictionsDisclosed = (instance: Instance): boolean =>
!!instance.pleroma.metadata.federation.mrf_policies;
const federationRestrictionsDisclosed = (state: RootState): boolean =>
!!state.instance.pleroma.metadata.federation.mrf_policies;
/**
* Determine whether pl-fe is running in standalone mode.