Fix Instance types
This commit is contained in:
parent
a81424262a
commit
12c57e02a5
|
@ -1,12 +1,11 @@
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import { AnyAction } from 'redux';
|
import { AnyAction } from 'redux';
|
||||||
import { ThunkAction } from 'redux-thunk'
|
|
||||||
import { AxiosResponse } from 'axios';
|
|
||||||
|
|
||||||
import KVStore from 'soapbox/storage/kv_store';
|
import KVStore from 'soapbox/storage/kv_store';
|
||||||
import { AppDispatch, RootState } from 'soapbox/store';
|
import { AppDispatch, RootState } from 'soapbox/store';
|
||||||
import { getAuthUserUrl } from 'soapbox/utils/auth';
|
import { getAuthUserUrl } from 'soapbox/utils/auth';
|
||||||
import { parseVersion } from 'soapbox/utils/features';
|
import { parseVersion } from 'soapbox/utils/features';
|
||||||
|
|
||||||
import api from '../api';
|
import api from '../api';
|
||||||
|
|
||||||
export const INSTANCE_FETCH_REQUEST = 'INSTANCE_FETCH_REQUEST';
|
export const INSTANCE_FETCH_REQUEST = 'INSTANCE_FETCH_REQUEST';
|
||||||
|
@ -38,7 +37,7 @@ export const getHost = (state: RootState) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export function rememberInstance(host: string) {
|
export function rememberInstance(host: string) {
|
||||||
return (dispatch: AppDispatch, _getState: () => RootState) => {
|
return (dispatch: AppDispatch, _getState: () => RootState): AnyAction => {
|
||||||
dispatch({ type: INSTANCE_REMEMBER_REQUEST, host });
|
dispatch({ type: INSTANCE_REMEMBER_REQUEST, host });
|
||||||
return KVStore.getItemOrError(`instance:${host}`).then((instance: Record<string, any>) => {
|
return KVStore.getItemOrError(`instance:${host}`).then((instance: Record<string, any>) => {
|
||||||
dispatch({ type: INSTANCE_REMEMBER_SUCCESS, host, instance });
|
dispatch({ type: INSTANCE_REMEMBER_SUCCESS, host, instance });
|
||||||
|
@ -55,8 +54,8 @@ const needsNodeinfo = (instance: Record<string, any>): boolean => {
|
||||||
return v.software === 'Pleroma' && !get(instance, ['pleroma', 'metadata']);
|
return v.software === 'Pleroma' && !get(instance, ['pleroma', 'metadata']);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function fetchInstance(): ThunkAction<AxiosResponse, RootState, unknown, AnyAction> {
|
export function fetchInstance() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
dispatch({ type: INSTANCE_FETCH_REQUEST });
|
dispatch({ type: INSTANCE_FETCH_REQUEST });
|
||||||
return api(getState).get('/api/v1/instance').then(({ data: instance }: { data: Record<string, any> }) => {
|
return api(getState).get('/api/v1/instance').then(({ data: instance }: { data: Record<string, any> }) => {
|
||||||
dispatch({ type: INSTANCE_FETCH_SUCCESS, instance });
|
dispatch({ type: INSTANCE_FETCH_SUCCESS, instance });
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
import localforage from 'localforage';
|
import localforage from 'localforage';
|
||||||
|
|
||||||
|
interface IKVStore extends LocalForage {
|
||||||
|
getItemOrError?: (key: string) => Promise<any>,
|
||||||
|
}
|
||||||
|
|
||||||
// localForage
|
// localForage
|
||||||
// https://localforage.github.io/localForage/#settings-api-config
|
// https://localforage.github.io/localForage/#settings-api-config
|
||||||
export const KVStore = localforage.createInstance({
|
export const KVStore: IKVStore = localforage.createInstance({
|
||||||
name: 'soapbox',
|
name: 'soapbox',
|
||||||
description: 'Soapbox offline data store',
|
description: 'Soapbox offline data store',
|
||||||
driver: localforage.INDEXEDDB,
|
driver: localforage.INDEXEDDB,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { composeWithDevTools } from '@redux-devtools/extension';
|
import { composeWithDevTools } from '@redux-devtools/extension';
|
||||||
import { createStore, applyMiddleware } from 'redux';
|
import { createStore, applyMiddleware, AnyAction } from 'redux';
|
||||||
import thunk from 'redux-thunk';
|
import thunk, { ThunkDispatch } from 'redux-thunk';
|
||||||
|
|
||||||
import errorsMiddleware from './middleware/errors';
|
import errorsMiddleware from './middleware/errors';
|
||||||
import soundsMiddleware from './middleware/sounds';
|
import soundsMiddleware from './middleware/sounds';
|
||||||
|
@ -20,4 +20,4 @@ export const store = createStore(
|
||||||
// Infer the `RootState` and `AppDispatch` types from the store itself
|
// Infer the `RootState` and `AppDispatch` types from the store itself
|
||||||
// https://redux.js.org/usage/usage-with-typescript
|
// https://redux.js.org/usage/usage-with-typescript
|
||||||
export type RootState = ReturnType<typeof store.getState>;
|
export type RootState = ReturnType<typeof store.getState>;
|
||||||
export type AppDispatch = typeof store.dispatch;
|
export type AppDispatch = ThunkDispatch<{}, {}, AnyAction>;
|
||||||
|
|
Loading…
Reference in New Issue