diff --git a/app/soapbox/actions/instance.ts b/app/soapbox/actions/instance.ts index a59970c2f..2eb20f80f 100644 --- a/app/soapbox/actions/instance.ts +++ b/app/soapbox/actions/instance.ts @@ -1,12 +1,11 @@ import { get } from 'lodash'; import { AnyAction } from 'redux'; -import { ThunkAction } from 'redux-thunk' -import { AxiosResponse } from 'axios'; import KVStore from 'soapbox/storage/kv_store'; import { AppDispatch, RootState } from 'soapbox/store'; import { getAuthUserUrl } from 'soapbox/utils/auth'; import { parseVersion } from 'soapbox/utils/features'; + import api from '../api'; export const INSTANCE_FETCH_REQUEST = 'INSTANCE_FETCH_REQUEST'; @@ -38,7 +37,7 @@ export const getHost = (state: RootState) => { }; export function rememberInstance(host: string) { - return (dispatch: AppDispatch, _getState: () => RootState) => { + return (dispatch: AppDispatch, _getState: () => RootState): AnyAction => { dispatch({ type: INSTANCE_REMEMBER_REQUEST, host }); return KVStore.getItemOrError(`instance:${host}`).then((instance: Record) => { dispatch({ type: INSTANCE_REMEMBER_SUCCESS, host, instance }); @@ -55,8 +54,8 @@ const needsNodeinfo = (instance: Record): boolean => { return v.software === 'Pleroma' && !get(instance, ['pleroma', 'metadata']); }; -export function fetchInstance(): ThunkAction { - return (dispatch, getState) => { +export function fetchInstance() { + return (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: INSTANCE_FETCH_REQUEST }); return api(getState).get('/api/v1/instance').then(({ data: instance }: { data: Record }) => { dispatch({ type: INSTANCE_FETCH_SUCCESS, instance }); diff --git a/app/soapbox/storage/kv_store.ts b/app/soapbox/storage/kv_store.ts index 2140486de..5b7225c0d 100644 --- a/app/soapbox/storage/kv_store.ts +++ b/app/soapbox/storage/kv_store.ts @@ -1,8 +1,12 @@ import localforage from 'localforage'; +interface IKVStore extends LocalForage { + getItemOrError?: (key: string) => Promise, +} + // localForage // https://localforage.github.io/localForage/#settings-api-config -export const KVStore = localforage.createInstance({ +export const KVStore: IKVStore = localforage.createInstance({ name: 'soapbox', description: 'Soapbox offline data store', driver: localforage.INDEXEDDB, diff --git a/app/soapbox/store.ts b/app/soapbox/store.ts index 4b34e45e2..5e557ac54 100644 --- a/app/soapbox/store.ts +++ b/app/soapbox/store.ts @@ -1,6 +1,6 @@ import { composeWithDevTools } from '@redux-devtools/extension'; -import { createStore, applyMiddleware } from 'redux'; -import thunk from 'redux-thunk'; +import { createStore, applyMiddleware, AnyAction } from 'redux'; +import thunk, { ThunkDispatch } from 'redux-thunk'; import errorsMiddleware from './middleware/errors'; import soundsMiddleware from './middleware/sounds'; @@ -20,4 +20,4 @@ export const store = createStore( // Infer the `RootState` and `AppDispatch` types from the store itself // https://redux.js.org/usage/usage-with-typescript export type RootState = ReturnType; -export type AppDispatch = typeof store.dispatch; +export type AppDispatch = ThunkDispatch<{}, {}, AnyAction>;