Fix Instance types

remove-makegetotheraccounts
Alex Gleason 2022-03-18 16:04:08 -05:00
rodzic a81424262a
commit 12c57e02a5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
3 zmienionych plików z 12 dodań i 9 usunięć

Wyświetl plik

@ -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<string, any>) => {
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']);
};
export function fetchInstance(): ThunkAction<AxiosResponse, RootState, unknown, AnyAction> {
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<string, any> }) => {
dispatch({ type: INSTANCE_FETCH_SUCCESS, instance });

Wyświetl plik

@ -1,8 +1,12 @@
import localforage from 'localforage';
interface IKVStore extends LocalForage {
getItemOrError?: (key: string) => Promise<any>,
}
// 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,

Wyświetl plik

@ -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<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
export type AppDispatch = ThunkDispatch<{}, {}, AnyAction>;