diff --git a/app/soapbox/actions/about.ts b/app/soapbox/actions/about.ts index dc6610eb7..07a486fd2 100644 --- a/app/soapbox/actions/about.ts +++ b/app/soapbox/actions/about.ts @@ -6,7 +6,7 @@ const FETCH_ABOUT_PAGE_REQUEST = 'FETCH_ABOUT_PAGE_REQUEST'; const FETCH_ABOUT_PAGE_SUCCESS = 'FETCH_ABOUT_PAGE_SUCCESS'; const FETCH_ABOUT_PAGE_FAIL = 'FETCH_ABOUT_PAGE_FAIL'; -const fetchAboutPage = (slug = 'index', locale?: string) => (dispatch: React.Dispatch, getState: any) => { +const fetchAboutPage = (slug = 'index', locale?: string) => (dispatch: React.Dispatch) => { dispatch({ type: FETCH_ABOUT_PAGE_REQUEST, slug, locale }); const filename = `${slug}${locale ? `.${locale}` : ''}.html`; diff --git a/app/soapbox/actions/account-notes.ts b/app/soapbox/actions/account-notes.ts index f7d28fe57..33391cff4 100644 --- a/app/soapbox/actions/account-notes.ts +++ b/app/soapbox/actions/account-notes.ts @@ -4,6 +4,7 @@ import { openModal, closeModal } from './modals'; import type { AxiosError } from 'axios'; import type { AnyAction } from 'redux'; +import type { RootState } from 'soapbox/store'; import type { Account } from 'soapbox/types/entities'; const ACCOUNT_NOTE_SUBMIT_REQUEST = 'ACCOUNT_NOTE_SUBMIT_REQUEST'; @@ -14,14 +15,14 @@ const ACCOUNT_NOTE_INIT_MODAL = 'ACCOUNT_NOTE_INIT_MODAL'; const ACCOUNT_NOTE_CHANGE_COMMENT = 'ACCOUNT_NOTE_CHANGE_COMMENT'; -const submitAccountNote = () => (dispatch: React.Dispatch, getState: any) => { +const submitAccountNote = () => (dispatch: React.Dispatch, getState: () => RootState) => { dispatch(submitAccountNoteRequest()); - const id = getState().getIn(['account_notes', 'edit', 'account_id']); + const id = getState().account_notes.edit.account; return api(getState) .post(`/api/v1/accounts/${id}/note`, { - comment: getState().getIn(['account_notes', 'edit', 'comment']), + comment: getState().account_notes.edit.comment, }) .then(response => { dispatch(closeModal()); @@ -50,8 +51,8 @@ function submitAccountNoteFail(error: AxiosError) { }; } -const initAccountNoteModal = (account: Account) => (dispatch: React.Dispatch, getState: any) => { - const comment = getState().getIn(['relationships', account.get('id'), 'note']); +const initAccountNoteModal = (account: Account) => (dispatch: React.Dispatch, getState: () => RootState) => { + const comment = getState().relationships.get(account.id)!.note; dispatch({ type: ACCOUNT_NOTE_INIT_MODAL, diff --git a/app/soapbox/actions/auth.ts b/app/soapbox/actions/auth.ts index 49de0e475..44598beca 100644 --- a/app/soapbox/actions/auth.ts +++ b/app/soapbox/actions/auth.ts @@ -77,7 +77,7 @@ const getAuthApp = () => }; const createAuthApp = () => - (dispatch: AppDispatch, getState: () => any) => { + (dispatch: AppDispatch, getState: () => RootState) => { const params = { client_name: sourceCode.displayName, redirect_uris: 'urn:ietf:wg:oauth:2.0:oob', @@ -91,7 +91,7 @@ const createAuthApp = () => }; const createAppToken = () => - (dispatch: AppDispatch, getState: () => any) => { + (dispatch: AppDispatch, getState: () => RootState) => { const app = getState().auth.get('app'); const params = { @@ -108,7 +108,7 @@ const createAppToken = () => }; const createUserToken = (username: string, password: string) => - (dispatch: AppDispatch, getState: () => any) => { + (dispatch: AppDispatch, getState: () => RootState) => { const app = getState().auth.get('app'); const params = { @@ -146,7 +146,7 @@ export const refreshUserToken = () => }; export const otpVerify = (code: string, mfa_token: string) => - (dispatch: AppDispatch, getState: () => any) => { + (dispatch: AppDispatch, getState: () => RootState) => { const app = getState().auth.get('app'); return api(getState, 'app').post('/oauth/mfa/challenge', { client_id: app.get('client_id'), @@ -162,7 +162,7 @@ export const otpVerify = (code: string, mfa_token: string) => export const verifyCredentials = (token: string, accountUrl?: string) => { const baseURL = parseBaseURL(accountUrl); - return (dispatch: AppDispatch, getState: () => any) => { + return (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: VERIFY_CREDENTIALS_REQUEST, token }); return baseClient(token, baseURL).get('/api/v1/accounts/verify_credentials').then(({ data: account }) => { @@ -188,7 +188,7 @@ export const verifyCredentials = (token: string, accountUrl?: string) => { }; export const rememberAuthAccount = (accountUrl: string) => - (dispatch: AppDispatch, getState: () => any) => { + (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: AUTH_ACCOUNT_REMEMBER_REQUEST, accountUrl }); return KVStore.getItemOrError(`authAccount:${accountUrl}`).then(account => { dispatch(importFetchedAccount(account)); @@ -230,7 +230,7 @@ export const logIn = (username: string, password: string) => }); export const deleteSession = () => - (dispatch: AppDispatch, getState: () => any) => api(getState).delete('/api/sign_out'); + (dispatch: AppDispatch, getState: () => RootState) => api(getState).delete('/api/sign_out'); export const logOut = () => (dispatch: AppDispatch, getState: () => RootState) => { @@ -256,7 +256,7 @@ export const logOut = () => }; export const switchAccount = (accountId: string, background = false) => - (dispatch: AppDispatch, getState: () => any) => { + (dispatch: AppDispatch, getState: () => RootState) => { const account = getState().accounts.get(accountId); return dispatch({ type: SWITCH_ACCOUNT, account, background }); }; @@ -286,7 +286,7 @@ export const register = (params: Record) => }; export const fetchCaptcha = () => - (_dispatch: AppDispatch, getState: () => any) => { + (_dispatch: AppDispatch, getState: () => RootState) => { return api(getState).get('/api/pleroma/captcha'); }; diff --git a/app/soapbox/actions/backups.ts b/app/soapbox/actions/backups.ts index 2057782ba..c95e504db 100644 --- a/app/soapbox/actions/backups.ts +++ b/app/soapbox/actions/backups.ts @@ -1,6 +1,6 @@ import api from '../api'; -import type { AppDispatch } from 'soapbox/store'; +import type { AppDispatch, RootState } from 'soapbox/store'; export const BACKUPS_FETCH_REQUEST = 'BACKUPS_FETCH_REQUEST'; export const BACKUPS_FETCH_SUCCESS = 'BACKUPS_FETCH_SUCCESS'; @@ -11,7 +11,7 @@ export const BACKUPS_CREATE_SUCCESS = 'BACKUPS_CREATE_SUCCESS'; export const BACKUPS_CREATE_FAIL = 'BACKUPS_CREATE_FAIL'; export const fetchBackups = () => - (dispatch: AppDispatch, getState: () => any) => { + (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: BACKUPS_FETCH_REQUEST }); return api(getState).get('/api/v1/pleroma/backups').then(({ data: backups }) => dispatch({ type: BACKUPS_FETCH_SUCCESS, backups }), @@ -21,7 +21,7 @@ export const fetchBackups = () => }; export const createBackup = () => - (dispatch: AppDispatch, getState: () => any) => { + (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: BACKUPS_CREATE_REQUEST }); return api(getState).post('/api/v1/pleroma/backups').then(({ data: backups }) => dispatch({ type: BACKUPS_CREATE_SUCCESS, backups }), diff --git a/app/soapbox/actions/blocks.ts b/app/soapbox/actions/blocks.ts index 25488d0f6..629be6f90 100644 --- a/app/soapbox/actions/blocks.ts +++ b/app/soapbox/actions/blocks.ts @@ -8,6 +8,7 @@ import { importFetchedAccounts } from './importer'; import type { AnyAction } from '@reduxjs/toolkit'; import type { AxiosError } from 'axios'; +import type { RootState } from 'soapbox/store'; const BLOCKS_FETCH_REQUEST = 'BLOCKS_FETCH_REQUEST'; const BLOCKS_FETCH_SUCCESS = 'BLOCKS_FETCH_SUCCESS'; @@ -17,7 +18,7 @@ const BLOCKS_EXPAND_REQUEST = 'BLOCKS_EXPAND_REQUEST'; const BLOCKS_EXPAND_SUCCESS = 'BLOCKS_EXPAND_SUCCESS'; const BLOCKS_EXPAND_FAIL = 'BLOCKS_EXPAND_FAIL'; -const fetchBlocks = () => (dispatch: React.Dispatch, getState: any) => { +const fetchBlocks = () => (dispatch: React.Dispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return null; const nextLinkName = getNextLinkName(getState); @@ -53,11 +54,11 @@ function fetchBlocksFail(error: AxiosError) { }; } -const expandBlocks = () => (dispatch: React.Dispatch, getState: any) => { +const expandBlocks = () => (dispatch: React.Dispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return null; const nextLinkName = getNextLinkName(getState); - const url = getState().getIn(['user_lists', 'blocks', 'next']); + const url = getState().user_lists.getIn(['blocks', 'next']); if (url === null) { return null; diff --git a/app/soapbox/actions/bundles.ts b/app/soapbox/actions/bundles.ts index cdc032cdd..fc5ef9321 100644 --- a/app/soapbox/actions/bundles.ts +++ b/app/soapbox/actions/bundles.ts @@ -12,7 +12,7 @@ const fetchBundleSuccess = (skipLoading?: boolean) => ({ skipLoading, }); -const fetchBundleFail = (error, skipLoading?: boolean) => ({ +const fetchBundleFail = (error: any, skipLoading?: boolean) => ({ type: BUNDLE_FETCH_FAIL, error, skipLoading, diff --git a/app/soapbox/actions/directory.ts b/app/soapbox/actions/directory.ts index e9e309de4..98e2dc2b2 100644 --- a/app/soapbox/actions/directory.ts +++ b/app/soapbox/actions/directory.ts @@ -3,6 +3,7 @@ import api from '../api'; import { fetchRelationships } from './accounts'; import { importFetchedAccounts } from './importer'; +import type { AxiosError } from 'axios'; import type { AppDispatch, RootState } from 'soapbox/store'; import type { APIEntity } from 'soapbox/types/entities'; @@ -14,14 +15,14 @@ const DIRECTORY_EXPAND_REQUEST = 'DIRECTORY_EXPAND_REQUEST'; const DIRECTORY_EXPAND_SUCCESS = 'DIRECTORY_EXPAND_SUCCESS'; const DIRECTORY_EXPAND_FAIL = 'DIRECTORY_EXPAND_FAIL'; -const fetchDirectory = params => +const fetchDirectory = (params: Record) => (dispatch: AppDispatch, getState: () => RootState) => { dispatch(fetchDirectoryRequest()); api(getState).get('/api/v1/directory', { params: { ...params, limit: 20 } }).then(({ data }) => { dispatch(importFetchedAccounts(data)); dispatch(fetchDirectorySuccess(data)); - dispatch(fetchRelationships(data.map(x => x.id))); + dispatch(fetchRelationships(data.map((x: APIEntity) => x.id))); }).catch(error => dispatch(fetchDirectoryFail(error))); }; @@ -29,17 +30,17 @@ const fetchDirectoryRequest = () => ({ type: DIRECTORY_FETCH_REQUEST, }); -const fetchDirectorySuccess = accounts => ({ +const fetchDirectorySuccess = (accounts: APIEntity[]) => ({ type: DIRECTORY_FETCH_SUCCESS, accounts, }); -const fetchDirectoryFail = error => ({ +const fetchDirectoryFail = (error: AxiosError) => ({ type: DIRECTORY_FETCH_FAIL, error, }); -const expandDirectory = params => +const expandDirectory = (params: Record) => (dispatch: AppDispatch, getState: () => RootState) => { dispatch(expandDirectoryRequest()); @@ -56,12 +57,12 @@ const expandDirectoryRequest = () => ({ type: DIRECTORY_EXPAND_REQUEST, }); -const expandDirectorySuccess = accounts => ({ +const expandDirectorySuccess = (accounts: APIEntity[]) => ({ type: DIRECTORY_EXPAND_SUCCESS, accounts, }); -const expandDirectoryFail = error => ({ +const expandDirectoryFail = (error: AxiosError) => ({ type: DIRECTORY_EXPAND_FAIL, error, }); diff --git a/app/soapbox/actions/email_list.ts b/app/soapbox/actions/email_list.ts index 561f13a2d..eeac0ed47 100644 --- a/app/soapbox/actions/email_list.ts +++ b/app/soapbox/actions/email_list.ts @@ -3,15 +3,15 @@ import api from '../api'; import type { RootState } from 'soapbox/store'; const getSubscribersCsv = () => - (dispatch, getState: () => RootState) => + (dispatch: any, getState: () => RootState) => api(getState).get('/api/v1/pleroma/admin/email_list/subscribers.csv'); const getUnsubscribersCsv = () => - (dispatch, getState: () => RootState) => + (dispatch: any, getState: () => RootState) => api(getState).get('/api/v1/pleroma/admin/email_list/unsubscribers.csv'); const getCombinedCsv = () => - (dispatch, getState: () => RootState) => + (dispatch: any, getState: () => RootState) => api(getState).get('/api/v1/pleroma/admin/email_list/combined.csv'); export { diff --git a/app/soapbox/actions/filters.ts b/app/soapbox/actions/filters.ts index 97e445425..16bb23951 100644 --- a/app/soapbox/actions/filters.ts +++ b/app/soapbox/actions/filters.ts @@ -66,7 +66,7 @@ const createFilter = (phrase: string, expires_at: string, context: Array }; -const deleteFilter = (id) => +const deleteFilter = (id: string) => (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: FILTERS_DELETE_REQUEST }); return api(getState).delete(`/api/v1/filters/${id}`).then(response => { diff --git a/app/soapbox/actions/pin_statuses.ts b/app/soapbox/actions/pin_statuses.ts index 8df193472..dacf502c2 100644 --- a/app/soapbox/actions/pin_statuses.ts +++ b/app/soapbox/actions/pin_statuses.ts @@ -4,6 +4,7 @@ import api from '../api'; import { importFetchedStatuses } from './importer'; +import type { AxiosError } from 'axios'; import type { AppDispatch, RootState } from 'soapbox/store'; import type { APIEntity } from 'soapbox/types/entities'; @@ -36,7 +37,7 @@ const fetchPinnedStatusesSuccess = (statuses: APIEntity[], next: string | null) next, }); -const fetchPinnedStatusesFail = (error) => ({ +const fetchPinnedStatusesFail = (error: AxiosError) => ({ type: PINNED_STATUSES_FETCH_FAIL, error, }); diff --git a/app/soapbox/actions/polls.ts b/app/soapbox/actions/polls.ts index 0bf03219b..da4579f71 100644 --- a/app/soapbox/actions/polls.ts +++ b/app/soapbox/actions/polls.ts @@ -2,7 +2,9 @@ import api from '../api'; import { importFetchedPoll } from './importer'; +import type { AxiosError } from 'axios'; import type { AppDispatch, RootState } from 'soapbox/store'; +import type { APIEntity } from 'soapbox/types/entities'; const POLL_VOTE_REQUEST = 'POLL_VOTE_REQUEST'; const POLL_VOTE_SUCCESS = 'POLL_VOTE_SUCCESS'; @@ -40,12 +42,12 @@ const voteRequest = () => ({ type: POLL_VOTE_REQUEST, }); -const voteSuccess = poll => ({ +const voteSuccess = (poll: APIEntity) => ({ type: POLL_VOTE_SUCCESS, poll, }); -const voteFail = error => ({ +const voteFail = (error: AxiosError) => ({ type: POLL_VOTE_FAIL, error, }); @@ -54,12 +56,12 @@ const fetchPollRequest = () => ({ type: POLL_FETCH_REQUEST, }); -const fetchPollSuccess = poll => ({ +const fetchPollSuccess = (poll: APIEntity) => ({ type: POLL_FETCH_SUCCESS, poll, }); -const fetchPollFail = error => ({ +const fetchPollFail = (error: AxiosError) => ({ type: POLL_FETCH_FAIL, error, }); diff --git a/app/soapbox/actions/push_subscriptions.ts b/app/soapbox/actions/push_subscriptions.ts index 129637a20..b370c5045 100644 --- a/app/soapbox/actions/push_subscriptions.ts +++ b/app/soapbox/actions/push_subscriptions.ts @@ -39,7 +39,7 @@ const fetchPushSubscription = () => }; const updatePushSubscription = (params: Record) => - (dispatch: AppDispatch, getState: () => any) => { + (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: PUSH_SUBSCRIPTION_UPDATE_REQUEST, params }); return api(getState).put('/api/v1/push/subscription', params).then(({ data: subscription }) => dispatch({ type: PUSH_SUBSCRIPTION_UPDATE_SUCCESS, params, subscription }), diff --git a/app/soapbox/actions/remote_timeline.ts b/app/soapbox/actions/remote_timeline.ts index 6cbcc2869..cb21126b9 100644 --- a/app/soapbox/actions/remote_timeline.ts +++ b/app/soapbox/actions/remote_timeline.ts @@ -1,10 +1,11 @@ import { getSettings, changeSetting } from 'soapbox/actions/settings'; +import type { OrderedSet as ImmutableOrderedSet } from 'immutable'; import type { AppDispatch, RootState } from 'soapbox/store'; const getPinnedHosts = (state: RootState) => { const settings = getSettings(state); - return settings.getIn(['remote_timeline', 'pinnedHosts']); + return settings.getIn(['remote_timeline', 'pinnedHosts']) as ImmutableOrderedSet; }; const pinHost = (host: string) => @@ -12,15 +13,15 @@ const pinHost = (host: string) => const state = getState(); const pinnedHosts = getPinnedHosts(state); - return dispatch(changeSetting(['remote_timeline', 'pinnedHosts'], pinnedHosts.push(host))); + return dispatch(changeSetting(['remote_timeline', 'pinnedHosts'], pinnedHosts.add(host))); }; -const unpinHost = (host) => +const unpinHost = (host: string) => (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); const pinnedHosts = getPinnedHosts(state); - return dispatch(changeSetting(['remote_timeline', 'pinnedHosts'], pinnedHosts.filter((value) => value !== host))); + return dispatch(changeSetting(['remote_timeline', 'pinnedHosts'], pinnedHosts.remove(host))); }; export { diff --git a/app/soapbox/actions/rules.ts b/app/soapbox/actions/rules.ts index 1e2c29eea..b5b3b90a4 100644 --- a/app/soapbox/actions/rules.ts +++ b/app/soapbox/actions/rules.ts @@ -1,6 +1,7 @@ import api from '../api'; import type { Rule } from 'soapbox/reducers/rules'; +import type { RootState } from 'soapbox/store'; const RULES_FETCH_REQUEST = 'RULES_FETCH_REQUEST'; const RULES_FETCH_SUCCESS = 'RULES_FETCH_SUCCESS'; @@ -16,7 +17,7 @@ type RulesFetchRequestSuccessAction = { export type RulesActions = RulesFetchRequestAction | RulesFetchRequestSuccessAction -const fetchRules = () => (dispatch: React.Dispatch, getState: any) => { +const fetchRules = () => (dispatch: React.Dispatch, getState: () => RootState) => { dispatch({ type: RULES_FETCH_REQUEST }); return api(getState) diff --git a/app/soapbox/features/export_data/components/csv_exporter.tsx b/app/soapbox/features/export_data/components/csv_exporter.tsx index de524bcce..2b2e760c9 100644 --- a/app/soapbox/features/export_data/components/csv_exporter.tsx +++ b/app/soapbox/features/export_data/components/csv_exporter.tsx @@ -3,7 +3,7 @@ import { MessageDescriptor, useIntl } from 'react-intl'; import { Button, Form, FormActions, Text } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; -import { AppDispatch } from 'soapbox/store'; +import { AppDispatch, RootState } from 'soapbox/store'; interface ICSVExporter { messages: { @@ -11,7 +11,7 @@ interface ICSVExporter { input_hint: MessageDescriptor, submit: MessageDescriptor, }, - action: () => (dispatch: AppDispatch, getState: any) => Promise, + action: () => (dispatch: AppDispatch, getState: () => RootState) => Promise, } const CSVExporter: React.FC = ({ messages, action }) => { diff --git a/app/soapbox/features/filters/index.tsx b/app/soapbox/features/filters/index.tsx index 31fa728fb..fcdf262eb 100644 --- a/app/soapbox/features/filters/index.tsx +++ b/app/soapbox/features/filters/index.tsx @@ -86,7 +86,7 @@ const Filters = () => { }; const handleFilterDelete: React.MouseEventHandler = e => { - dispatch(deleteFilter(e.currentTarget.dataset.value)).then(() => { + dispatch(deleteFilter(e.currentTarget.dataset.value!)).then(() => { return dispatch(fetchFilters()); }).catch(() => { dispatch(snackbar.error(intl.formatMessage(messages.delete_error))); diff --git a/app/soapbox/features/import_data/components/csv_importer.tsx b/app/soapbox/features/import_data/components/csv_importer.tsx index 65d9e1ee4..6785e5cbd 100644 --- a/app/soapbox/features/import_data/components/csv_importer.tsx +++ b/app/soapbox/features/import_data/components/csv_importer.tsx @@ -3,7 +3,8 @@ import { MessageDescriptor, useIntl } from 'react-intl'; import { Button, FileInput, Form, FormActions, FormGroup, Text } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; -import { AppDispatch } from 'soapbox/store'; + +import type { AppDispatch, RootState } from 'soapbox/store'; interface ICSVImporter { messages: { @@ -11,7 +12,7 @@ interface ICSVImporter { input_hint: MessageDescriptor, submit: MessageDescriptor, }, - action: (params: FormData) => (dispatch: AppDispatch, getState: any) => Promise, + action: (params: FormData) => (dispatch: AppDispatch, getState: () => RootState) => Promise, } const CSVImporter: React.FC = ({ messages, action }) => { diff --git a/app/soapbox/features/ui/components/embed_modal.tsx b/app/soapbox/features/ui/components/embed_modal.tsx index 00a8f3767..0b3be1bc1 100644 --- a/app/soapbox/features/ui/components/embed_modal.tsx +++ b/app/soapbox/features/ui/components/embed_modal.tsx @@ -5,8 +5,10 @@ import api from 'soapbox/api'; import { Modal, Stack, Text, Input } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; +import type { RootState } from 'soapbox/store'; + const fetchEmbed = (url: string) => { - return (dispatch: any, getState: any) => { + return (dispatch: any, getState: () => RootState) => { return api(getState).get('/api/oembed', { params: { url } }); }; };