diff --git a/app/soapbox/actions/lists.js b/app/soapbox/actions/lists.js deleted file mode 100644 index 6b39978d2..000000000 --- a/app/soapbox/actions/lists.js +++ /dev/null @@ -1,394 +0,0 @@ -import { isLoggedIn } from 'soapbox/utils/auth'; - -import api from '../api'; - -import { showAlertForError } from './alerts'; -import { importFetchedAccounts } from './importer'; - -export const LIST_FETCH_REQUEST = 'LIST_FETCH_REQUEST'; -export const LIST_FETCH_SUCCESS = 'LIST_FETCH_SUCCESS'; -export const LIST_FETCH_FAIL = 'LIST_FETCH_FAIL'; - -export const LISTS_FETCH_REQUEST = 'LISTS_FETCH_REQUEST'; -export const LISTS_FETCH_SUCCESS = 'LISTS_FETCH_SUCCESS'; -export const LISTS_FETCH_FAIL = 'LISTS_FETCH_FAIL'; - -export const LIST_EDITOR_TITLE_CHANGE = 'LIST_EDITOR_TITLE_CHANGE'; -export const LIST_EDITOR_RESET = 'LIST_EDITOR_RESET'; -export const LIST_EDITOR_SETUP = 'LIST_EDITOR_SETUP'; - -export const LIST_CREATE_REQUEST = 'LIST_CREATE_REQUEST'; -export const LIST_CREATE_SUCCESS = 'LIST_CREATE_SUCCESS'; -export const LIST_CREATE_FAIL = 'LIST_CREATE_FAIL'; - -export const LIST_UPDATE_REQUEST = 'LIST_UPDATE_REQUEST'; -export const LIST_UPDATE_SUCCESS = 'LIST_UPDATE_SUCCESS'; -export const LIST_UPDATE_FAIL = 'LIST_UPDATE_FAIL'; - -export const LIST_DELETE_REQUEST = 'LIST_DELETE_REQUEST'; -export const LIST_DELETE_SUCCESS = 'LIST_DELETE_SUCCESS'; -export const LIST_DELETE_FAIL = 'LIST_DELETE_FAIL'; - -export const LIST_ACCOUNTS_FETCH_REQUEST = 'LIST_ACCOUNTS_FETCH_REQUEST'; -export const LIST_ACCOUNTS_FETCH_SUCCESS = 'LIST_ACCOUNTS_FETCH_SUCCESS'; -export const LIST_ACCOUNTS_FETCH_FAIL = 'LIST_ACCOUNTS_FETCH_FAIL'; - -export const LIST_EDITOR_SUGGESTIONS_CHANGE = 'LIST_EDITOR_SUGGESTIONS_CHANGE'; -export const LIST_EDITOR_SUGGESTIONS_READY = 'LIST_EDITOR_SUGGESTIONS_READY'; -export const LIST_EDITOR_SUGGESTIONS_CLEAR = 'LIST_EDITOR_SUGGESTIONS_CLEAR'; - -export const LIST_EDITOR_ADD_REQUEST = 'LIST_EDITOR_ADD_REQUEST'; -export const LIST_EDITOR_ADD_SUCCESS = 'LIST_EDITOR_ADD_SUCCESS'; -export const LIST_EDITOR_ADD_FAIL = 'LIST_EDITOR_ADD_FAIL'; - -export const LIST_EDITOR_REMOVE_REQUEST = 'LIST_EDITOR_REMOVE_REQUEST'; -export const LIST_EDITOR_REMOVE_SUCCESS = 'LIST_EDITOR_REMOVE_SUCCESS'; -export const LIST_EDITOR_REMOVE_FAIL = 'LIST_EDITOR_REMOVE_FAIL'; - -export const LIST_ADDER_RESET = 'LIST_ADDER_RESET'; -export const LIST_ADDER_SETUP = 'LIST_ADDER_SETUP'; - -export const LIST_ADDER_LISTS_FETCH_REQUEST = 'LIST_ADDER_LISTS_FETCH_REQUEST'; -export const LIST_ADDER_LISTS_FETCH_SUCCESS = 'LIST_ADDER_LISTS_FETCH_SUCCESS'; -export const LIST_ADDER_LISTS_FETCH_FAIL = 'LIST_ADDER_LISTS_FETCH_FAIL'; - -export const fetchList = id => (dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - if (getState().getIn(['lists', id])) { - return; - } - - dispatch(fetchListRequest(id)); - - api(getState).get(`/api/v1/lists/${id}`) - .then(({ data }) => dispatch(fetchListSuccess(data))) - .catch(err => dispatch(fetchListFail(id, err))); -}; - -export const fetchListRequest = id => ({ - type: LIST_FETCH_REQUEST, - id, -}); - -export const fetchListSuccess = list => ({ - type: LIST_FETCH_SUCCESS, - list, -}); - -export const fetchListFail = (id, error) => ({ - type: LIST_FETCH_FAIL, - id, - error, -}); - -export const fetchLists = () => (dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - dispatch(fetchListsRequest()); - - api(getState).get('/api/v1/lists') - .then(({ data }) => dispatch(fetchListsSuccess(data))) - .catch(err => dispatch(fetchListsFail(err))); -}; - -export const fetchListsRequest = () => ({ - type: LISTS_FETCH_REQUEST, -}); - -export const fetchListsSuccess = lists => ({ - type: LISTS_FETCH_SUCCESS, - lists, -}); - -export const fetchListsFail = error => ({ - type: LISTS_FETCH_FAIL, - error, -}); - -export const submitListEditor = shouldReset => (dispatch, getState) => { - const listId = getState().getIn(['listEditor', 'listId']); - const title = getState().getIn(['listEditor', 'title']); - - if (listId === null) { - dispatch(createList(title, shouldReset)); - } else { - dispatch(updateList(listId, title, shouldReset)); - } -}; - -export const setupListEditor = listId => (dispatch, getState) => { - dispatch({ - type: LIST_EDITOR_SETUP, - list: getState().getIn(['lists', listId]), - }); - - dispatch(fetchListAccounts(listId)); -}; - -export const changeListEditorTitle = value => ({ - type: LIST_EDITOR_TITLE_CHANGE, - value, -}); - -export const createList = (title, shouldReset) => (dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - dispatch(createListRequest()); - - api(getState).post('/api/v1/lists', { title }).then(({ data }) => { - dispatch(createListSuccess(data)); - - if (shouldReset) { - dispatch(resetListEditor()); - } - }).catch(err => dispatch(createListFail(err))); -}; - -export const createListRequest = () => ({ - type: LIST_CREATE_REQUEST, -}); - -export const createListSuccess = list => ({ - type: LIST_CREATE_SUCCESS, - list, -}); - -export const createListFail = error => ({ - type: LIST_CREATE_FAIL, - error, -}); - -export const updateList = (id, title, shouldReset) => (dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - dispatch(updateListRequest(id)); - - api(getState).put(`/api/v1/lists/${id}`, { title }).then(({ data }) => { - dispatch(updateListSuccess(data)); - - if (shouldReset) { - dispatch(resetListEditor()); - } - }).catch(err => dispatch(updateListFail(id, err))); -}; - -export const updateListRequest = id => ({ - type: LIST_UPDATE_REQUEST, - id, -}); - -export const updateListSuccess = list => ({ - type: LIST_UPDATE_SUCCESS, - list, -}); - -export const updateListFail = (id, error) => ({ - type: LIST_UPDATE_FAIL, - id, - error, -}); - -export const resetListEditor = () => ({ - type: LIST_EDITOR_RESET, -}); - -export const deleteList = id => (dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - dispatch(deleteListRequest(id)); - - api(getState).delete(`/api/v1/lists/${id}`) - .then(() => dispatch(deleteListSuccess(id))) - .catch(err => dispatch(deleteListFail(id, err))); -}; - -export const deleteListRequest = id => ({ - type: LIST_DELETE_REQUEST, - id, -}); - -export const deleteListSuccess = id => ({ - type: LIST_DELETE_SUCCESS, - id, -}); - -export const deleteListFail = (id, error) => ({ - type: LIST_DELETE_FAIL, - id, - error, -}); - -export const fetchListAccounts = listId => (dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - dispatch(fetchListAccountsRequest(listId)); - - api(getState).get(`/api/v1/lists/${listId}/accounts`, { params: { limit: 0 } }).then(({ data }) => { - dispatch(importFetchedAccounts(data)); - dispatch(fetchListAccountsSuccess(listId, data)); - }).catch(err => dispatch(fetchListAccountsFail(listId, err))); -}; - -export const fetchListAccountsRequest = id => ({ - type: LIST_ACCOUNTS_FETCH_REQUEST, - id, -}); - -export const fetchListAccountsSuccess = (id, accounts, next) => ({ - type: LIST_ACCOUNTS_FETCH_SUCCESS, - id, - accounts, - next, -}); - -export const fetchListAccountsFail = (id, error) => ({ - type: LIST_ACCOUNTS_FETCH_FAIL, - id, - error, -}); - -export const fetchListSuggestions = q => (dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - const params = { - q, - resolve: false, - limit: 4, - following: true, - }; - - api(getState).get('/api/v1/accounts/search', { params }).then(({ data }) => { - dispatch(importFetchedAccounts(data)); - dispatch(fetchListSuggestionsReady(q, data)); - }).catch(error => dispatch(showAlertForError(error))); -}; - -export const fetchListSuggestionsReady = (query, accounts) => ({ - type: LIST_EDITOR_SUGGESTIONS_READY, - query, - accounts, -}); - -export const clearListSuggestions = () => ({ - type: LIST_EDITOR_SUGGESTIONS_CLEAR, -}); - -export const changeListSuggestions = value => ({ - type: LIST_EDITOR_SUGGESTIONS_CHANGE, - value, -}); - -export const addToListEditor = accountId => (dispatch, getState) => { - dispatch(addToList(getState().getIn(['listEditor', 'listId']), accountId)); -}; - -export const addToList = (listId, accountId) => (dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - dispatch(addToListRequest(listId, accountId)); - - api(getState).post(`/api/v1/lists/${listId}/accounts`, { account_ids: [accountId] }) - .then(() => dispatch(addToListSuccess(listId, accountId))) - .catch(err => dispatch(addToListFail(listId, accountId, err))); -}; - -export const addToListRequest = (listId, accountId) => ({ - type: LIST_EDITOR_ADD_REQUEST, - listId, - accountId, -}); - -export const addToListSuccess = (listId, accountId) => ({ - type: LIST_EDITOR_ADD_SUCCESS, - listId, - accountId, -}); - -export const addToListFail = (listId, accountId, error) => ({ - type: LIST_EDITOR_ADD_FAIL, - listId, - accountId, - error, -}); - -export const removeFromListEditor = accountId => (dispatch, getState) => { - dispatch(removeFromList(getState().getIn(['listEditor', 'listId']), accountId)); -}; - -export const removeFromList = (listId, accountId) => (dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - dispatch(removeFromListRequest(listId, accountId)); - - api(getState).delete(`/api/v1/lists/${listId}/accounts`, { params: { account_ids: [accountId] } }) - .then(() => dispatch(removeFromListSuccess(listId, accountId))) - .catch(err => dispatch(removeFromListFail(listId, accountId, err))); -}; - -export const removeFromListRequest = (listId, accountId) => ({ - type: LIST_EDITOR_REMOVE_REQUEST, - listId, - accountId, -}); - -export const removeFromListSuccess = (listId, accountId) => ({ - type: LIST_EDITOR_REMOVE_SUCCESS, - listId, - accountId, -}); - -export const removeFromListFail = (listId, accountId, error) => ({ - type: LIST_EDITOR_REMOVE_FAIL, - listId, - accountId, - error, -}); - -export const resetListAdder = () => ({ - type: LIST_ADDER_RESET, -}); - -export const setupListAdder = accountId => (dispatch, getState) => { - dispatch({ - type: LIST_ADDER_SETUP, - account: getState().getIn(['accounts', accountId]), - }); - dispatch(fetchLists()); - dispatch(fetchAccountLists(accountId)); -}; - -export const fetchAccountLists = accountId => (dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - dispatch(fetchAccountListsRequest(accountId)); - - api(getState).get(`/api/v1/accounts/${accountId}/lists`) - .then(({ data }) => dispatch(fetchAccountListsSuccess(accountId, data))) - .catch(err => dispatch(fetchAccountListsFail(accountId, err))); -}; - -export const fetchAccountListsRequest = id => ({ - type: LIST_ADDER_LISTS_FETCH_REQUEST, - id, -}); - -export const fetchAccountListsSuccess = (id, lists) => ({ - type: LIST_ADDER_LISTS_FETCH_SUCCESS, - id, - lists, -}); - -export const fetchAccountListsFail = (id, err) => ({ - type: LIST_ADDER_LISTS_FETCH_FAIL, - id, - err, -}); - -export const addToListAdder = listId => (dispatch, getState) => { - dispatch(addToList(listId, getState().getIn(['listAdder', 'accountId']))); -}; - -export const removeFromListAdder = listId => (dispatch, getState) => { - dispatch(removeFromList(listId, getState().getIn(['listAdder', 'accountId']))); -}; diff --git a/app/soapbox/actions/lists.ts b/app/soapbox/actions/lists.ts new file mode 100644 index 000000000..bf7dba8ba --- /dev/null +++ b/app/soapbox/actions/lists.ts @@ -0,0 +1,486 @@ +import { isLoggedIn } from 'soapbox/utils/auth'; + +import api from '../api'; + +import { showAlertForError } from './alerts'; +import { importFetchedAccounts } from './importer'; + +import type { AxiosError } from 'axios'; +import type { AppDispatch, RootState } from 'soapbox/store'; +import type { APIEntity } from 'soapbox/types/entities'; + +const LIST_FETCH_REQUEST = 'LIST_FETCH_REQUEST'; +const LIST_FETCH_SUCCESS = 'LIST_FETCH_SUCCESS'; +const LIST_FETCH_FAIL = 'LIST_FETCH_FAIL'; + +const LISTS_FETCH_REQUEST = 'LISTS_FETCH_REQUEST'; +const LISTS_FETCH_SUCCESS = 'LISTS_FETCH_SUCCESS'; +const LISTS_FETCH_FAIL = 'LISTS_FETCH_FAIL'; + +const LIST_EDITOR_TITLE_CHANGE = 'LIST_EDITOR_TITLE_CHANGE'; +const LIST_EDITOR_RESET = 'LIST_EDITOR_RESET'; +const LIST_EDITOR_SETUP = 'LIST_EDITOR_SETUP'; + +const LIST_CREATE_REQUEST = 'LIST_CREATE_REQUEST'; +const LIST_CREATE_SUCCESS = 'LIST_CREATE_SUCCESS'; +const LIST_CREATE_FAIL = 'LIST_CREATE_FAIL'; + +const LIST_UPDATE_REQUEST = 'LIST_UPDATE_REQUEST'; +const LIST_UPDATE_SUCCESS = 'LIST_UPDATE_SUCCESS'; +const LIST_UPDATE_FAIL = 'LIST_UPDATE_FAIL'; + +const LIST_DELETE_REQUEST = 'LIST_DELETE_REQUEST'; +const LIST_DELETE_SUCCESS = 'LIST_DELETE_SUCCESS'; +const LIST_DELETE_FAIL = 'LIST_DELETE_FAIL'; + +const LIST_ACCOUNTS_FETCH_REQUEST = 'LIST_ACCOUNTS_FETCH_REQUEST'; +const LIST_ACCOUNTS_FETCH_SUCCESS = 'LIST_ACCOUNTS_FETCH_SUCCESS'; +const LIST_ACCOUNTS_FETCH_FAIL = 'LIST_ACCOUNTS_FETCH_FAIL'; + +const LIST_EDITOR_SUGGESTIONS_CHANGE = 'LIST_EDITOR_SUGGESTIONS_CHANGE'; +const LIST_EDITOR_SUGGESTIONS_READY = 'LIST_EDITOR_SUGGESTIONS_READY'; +const LIST_EDITOR_SUGGESTIONS_CLEAR = 'LIST_EDITOR_SUGGESTIONS_CLEAR'; + +const LIST_EDITOR_ADD_REQUEST = 'LIST_EDITOR_ADD_REQUEST'; +const LIST_EDITOR_ADD_SUCCESS = 'LIST_EDITOR_ADD_SUCCESS'; +const LIST_EDITOR_ADD_FAIL = 'LIST_EDITOR_ADD_FAIL'; + +const LIST_EDITOR_REMOVE_REQUEST = 'LIST_EDITOR_REMOVE_REQUEST'; +const LIST_EDITOR_REMOVE_SUCCESS = 'LIST_EDITOR_REMOVE_SUCCESS'; +const LIST_EDITOR_REMOVE_FAIL = 'LIST_EDITOR_REMOVE_FAIL'; + +const LIST_ADDER_RESET = 'LIST_ADDER_RESET'; +const LIST_ADDER_SETUP = 'LIST_ADDER_SETUP'; + +const LIST_ADDER_LISTS_FETCH_REQUEST = 'LIST_ADDER_LISTS_FETCH_REQUEST'; +const LIST_ADDER_LISTS_FETCH_SUCCESS = 'LIST_ADDER_LISTS_FETCH_SUCCESS'; +const LIST_ADDER_LISTS_FETCH_FAIL = 'LIST_ADDER_LISTS_FETCH_FAIL'; + +const fetchList = (id: string | number) => (dispatch: AppDispatch, getState: () => RootState) => { + if (!isLoggedIn(getState)) return; + + if (getState().lists.get(String(id))) { + return; + } + + dispatch(fetchListRequest(id)); + + api(getState).get(`/api/v1/lists/${id}`) + .then(({ data }) => dispatch(fetchListSuccess(data))) + .catch(err => dispatch(fetchListFail(id, err))); +}; + +const fetchListRequest = (id: string | number) => ({ + type: LIST_FETCH_REQUEST, + id, +}); + +const fetchListSuccess = (list: APIEntity) => ({ + type: LIST_FETCH_SUCCESS, + list, +}); + +const fetchListFail = (id: string | number, error: AxiosError) => ({ + type: LIST_FETCH_FAIL, + id, + error, +}); + +const fetchLists = () => (dispatch: AppDispatch, getState: () => RootState) => { + if (!isLoggedIn(getState)) return; + + dispatch(fetchListsRequest()); + + api(getState).get('/api/v1/lists') + .then(({ data }) => dispatch(fetchListsSuccess(data))) + .catch(err => dispatch(fetchListsFail(err))); +}; + +const fetchListsRequest = () => ({ + type: LISTS_FETCH_REQUEST, +}); + +const fetchListsSuccess = (lists: APIEntity[]) => ({ + type: LISTS_FETCH_SUCCESS, + lists, +}); + +const fetchListsFail = (error: AxiosError) => ({ + type: LISTS_FETCH_FAIL, + error, +}); + +const submitListEditor = (shouldReset?: boolean) => (dispatch: AppDispatch, getState: () => RootState) => { + const listId = getState().listEditor.listId!; + const title = getState().listEditor.title; + + if (listId === null) { + dispatch(createList(title, shouldReset)); + } else { + dispatch(updateList(listId, title, shouldReset)); + } +}; + +const setupListEditor = (listId: string | number) => (dispatch: AppDispatch, getState: () => RootState) => { + dispatch({ + type: LIST_EDITOR_SETUP, + list: getState().lists.get(String(listId)), + }); + + dispatch(fetchListAccounts(listId)); +}; + +const changeListEditorTitle = (value: string) => ({ + type: LIST_EDITOR_TITLE_CHANGE, + value, +}); + +const createList = (title: string, shouldReset?: boolean) => (dispatch: AppDispatch, getState: () => RootState) => { + if (!isLoggedIn(getState)) return; + + dispatch(createListRequest()); + + api(getState).post('/api/v1/lists', { title }).then(({ data }) => { + dispatch(createListSuccess(data)); + + if (shouldReset) { + dispatch(resetListEditor()); + } + }).catch(err => dispatch(createListFail(err))); +}; + +const createListRequest = () => ({ + type: LIST_CREATE_REQUEST, +}); + +const createListSuccess = (list: APIEntity) => ({ + type: LIST_CREATE_SUCCESS, + list, +}); + +const createListFail = (error: AxiosError) => ({ + type: LIST_CREATE_FAIL, + error, +}); + +const updateList = (id: string | number, title: string, shouldReset?: boolean) => (dispatch: AppDispatch, getState: () => RootState) => { + if (!isLoggedIn(getState)) return; + + dispatch(updateListRequest(id)); + + api(getState).put(`/api/v1/lists/${id}`, { title }).then(({ data }) => { + dispatch(updateListSuccess(data)); + + if (shouldReset) { + dispatch(resetListEditor()); + } + }).catch(err => dispatch(updateListFail(id, err))); +}; + +const updateListRequest = (id: string | number) => ({ + type: LIST_UPDATE_REQUEST, + id, +}); + +const updateListSuccess = (list: APIEntity) => ({ + type: LIST_UPDATE_SUCCESS, + list, +}); + +const updateListFail = (id: string | number, error: AxiosError) => ({ + type: LIST_UPDATE_FAIL, + id, + error, +}); + +const resetListEditor = () => ({ + type: LIST_EDITOR_RESET, +}); + +const deleteList = (id: string | number) => (dispatch: AppDispatch, getState: () => RootState) => { + if (!isLoggedIn(getState)) return; + + dispatch(deleteListRequest(id)); + + api(getState).delete(`/api/v1/lists/${id}`) + .then(() => dispatch(deleteListSuccess(id))) + .catch(err => dispatch(deleteListFail(id, err))); +}; + +const deleteListRequest = (id: string | number) => ({ + type: LIST_DELETE_REQUEST, + id, +}); + +const deleteListSuccess = (id: string | number) => ({ + type: LIST_DELETE_SUCCESS, + id, +}); + +const deleteListFail = (id: string | number, error: AxiosError) => ({ + type: LIST_DELETE_FAIL, + id, + error, +}); + +const fetchListAccounts = (listId: string | number) => (dispatch: AppDispatch, getState: () => RootState) => { + if (!isLoggedIn(getState)) return; + + dispatch(fetchListAccountsRequest(listId)); + + api(getState).get(`/api/v1/lists/${listId}/accounts`, { params: { limit: 0 } }).then(({ data }) => { + dispatch(importFetchedAccounts(data)); + dispatch(fetchListAccountsSuccess(listId, data, null)); + }).catch(err => dispatch(fetchListAccountsFail(listId, err))); +}; + +const fetchListAccountsRequest = (id: string | number) => ({ + type: LIST_ACCOUNTS_FETCH_REQUEST, + id, +}); + +const fetchListAccountsSuccess = (id: string | number, accounts: APIEntity[], next: string | null) => ({ + type: LIST_ACCOUNTS_FETCH_SUCCESS, + id, + accounts, + next, +}); + +const fetchListAccountsFail = (id: string | number, error: AxiosError) => ({ + type: LIST_ACCOUNTS_FETCH_FAIL, + id, + error, +}); + +const fetchListSuggestions = (q: string) => (dispatch: AppDispatch, getState: () => RootState) => { + if (!isLoggedIn(getState)) return; + + const params = { + q, + resolve: false, + limit: 4, + following: true, + }; + + api(getState).get('/api/v1/accounts/search', { params }).then(({ data }) => { + dispatch(importFetchedAccounts(data)); + dispatch(fetchListSuggestionsReady(q, data)); + }).catch(error => dispatch(showAlertForError(error))); +}; + +const fetchListSuggestionsReady = (query: string, accounts: APIEntity[]) => ({ + type: LIST_EDITOR_SUGGESTIONS_READY, + query, + accounts, +}); + +const clearListSuggestions = () => ({ + type: LIST_EDITOR_SUGGESTIONS_CLEAR, +}); + +const changeListSuggestions = (value: string) => ({ + type: LIST_EDITOR_SUGGESTIONS_CHANGE, + value, +}); + +const addToListEditor = (accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { + dispatch(addToList(getState().listEditor.listId!, accountId)); +}; + +const addToList = (listId: string | number, accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { + if (!isLoggedIn(getState)) return; + + dispatch(addToListRequest(listId, accountId)); + + api(getState).post(`/api/v1/lists/${listId}/accounts`, { account_ids: [accountId] }) + .then(() => dispatch(addToListSuccess(listId, accountId))) + .catch(err => dispatch(addToListFail(listId, accountId, err))); +}; + +const addToListRequest = (listId: string | number, accountId: string) => ({ + type: LIST_EDITOR_ADD_REQUEST, + listId, + accountId, +}); + +const addToListSuccess = (listId: string | number, accountId: string) => ({ + type: LIST_EDITOR_ADD_SUCCESS, + listId, + accountId, +}); + +const addToListFail = (listId: string | number, accountId: string, error: APIEntity) => ({ + type: LIST_EDITOR_ADD_FAIL, + listId, + accountId, + error, +}); + +const removeFromListEditor = (accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { + dispatch(removeFromList(getState().listEditor.listId!, accountId)); +}; + +const removeFromList = (listId: string | number, accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { + if (!isLoggedIn(getState)) return; + + dispatch(removeFromListRequest(listId, accountId)); + + api(getState).delete(`/api/v1/lists/${listId}/accounts`, { params: { account_ids: [accountId] } }) + .then(() => dispatch(removeFromListSuccess(listId, accountId))) + .catch(err => dispatch(removeFromListFail(listId, accountId, err))); +}; + +const removeFromListRequest = (listId: string | number, accountId: string) => ({ + type: LIST_EDITOR_REMOVE_REQUEST, + listId, + accountId, +}); + +const removeFromListSuccess = (listId: string | number, accountId: string) => ({ + type: LIST_EDITOR_REMOVE_SUCCESS, + listId, + accountId, +}); + +const removeFromListFail = (listId: string | number, accountId: string, error: AxiosError) => ({ + type: LIST_EDITOR_REMOVE_FAIL, + listId, + accountId, + error, +}); + +const resetListAdder = () => ({ + type: LIST_ADDER_RESET, +}); + +const setupListAdder = (accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { + dispatch({ + type: LIST_ADDER_SETUP, + account: getState().accounts.get(accountId), + }); + dispatch(fetchLists()); + dispatch(fetchAccountLists(accountId)); +}; + +const fetchAccountLists = (accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { + if (!isLoggedIn(getState)) return; + + dispatch(fetchAccountListsRequest(accountId)); + + api(getState).get(`/api/v1/accounts/${accountId}/lists`) + .then(({ data }) => dispatch(fetchAccountListsSuccess(accountId, data))) + .catch(err => dispatch(fetchAccountListsFail(accountId, err))); +}; + +const fetchAccountListsRequest = (id: string) => ({ + type: LIST_ADDER_LISTS_FETCH_REQUEST, + id, +}); + +const fetchAccountListsSuccess = (id: string, lists: APIEntity[]) => ({ + type: LIST_ADDER_LISTS_FETCH_SUCCESS, + id, + lists, +}); + +const fetchAccountListsFail = (id: string, err: AxiosError) => ({ + type: LIST_ADDER_LISTS_FETCH_FAIL, + id, + err, +}); + +const addToListAdder = (listId: string | number) => (dispatch: AppDispatch, getState: () => RootState) => { + dispatch(addToList(listId, getState().listAdder.accountId!)); +}; + +const removeFromListAdder = (listId: string | number) => (dispatch: AppDispatch, getState: () => RootState) => { + dispatch(removeFromList(listId, getState().listAdder.accountId!)); +}; + +export { + LIST_FETCH_REQUEST, + LIST_FETCH_SUCCESS, + LIST_FETCH_FAIL, + LISTS_FETCH_REQUEST, + LISTS_FETCH_SUCCESS, + LISTS_FETCH_FAIL, + LIST_EDITOR_TITLE_CHANGE, + LIST_EDITOR_RESET, + LIST_EDITOR_SETUP, + LIST_CREATE_REQUEST, + LIST_CREATE_SUCCESS, + LIST_CREATE_FAIL, + LIST_UPDATE_REQUEST, + LIST_UPDATE_SUCCESS, + LIST_UPDATE_FAIL, + LIST_DELETE_REQUEST, + LIST_DELETE_SUCCESS, + LIST_DELETE_FAIL, + LIST_ACCOUNTS_FETCH_REQUEST, + LIST_ACCOUNTS_FETCH_SUCCESS, + LIST_ACCOUNTS_FETCH_FAIL, + LIST_EDITOR_SUGGESTIONS_CHANGE, + LIST_EDITOR_SUGGESTIONS_READY, + LIST_EDITOR_SUGGESTIONS_CLEAR, + LIST_EDITOR_ADD_REQUEST, + LIST_EDITOR_ADD_SUCCESS, + LIST_EDITOR_ADD_FAIL, + LIST_EDITOR_REMOVE_REQUEST, + LIST_EDITOR_REMOVE_SUCCESS, + LIST_EDITOR_REMOVE_FAIL, + LIST_ADDER_RESET, + LIST_ADDER_SETUP, + LIST_ADDER_LISTS_FETCH_REQUEST, + LIST_ADDER_LISTS_FETCH_SUCCESS, + LIST_ADDER_LISTS_FETCH_FAIL, + fetchList, + fetchListRequest, + fetchListSuccess, + fetchListFail, + fetchLists, + fetchListsRequest, + fetchListsSuccess, + fetchListsFail, + submitListEditor, + setupListEditor, + changeListEditorTitle, + createList, + createListRequest, + createListSuccess, + createListFail, + updateList, + updateListRequest, + updateListSuccess, + updateListFail, + resetListEditor, + deleteList, + deleteListRequest, + deleteListSuccess, + deleteListFail, + fetchListAccounts, + fetchListAccountsRequest, + fetchListAccountsSuccess, + fetchListAccountsFail, + fetchListSuggestions, + fetchListSuggestionsReady, + clearListSuggestions, + changeListSuggestions, + addToListEditor, + addToList, + addToListRequest, + addToListSuccess, + addToListFail, + removeFromListEditor, + removeFromList, + removeFromListRequest, + removeFromListSuccess, + removeFromListFail, + resetListAdder, + setupListAdder, + fetchAccountLists, + fetchAccountListsRequest, + fetchAccountListsSuccess, + fetchAccountListsFail, + addToListAdder, + removeFromListAdder, +}; diff --git a/app/soapbox/actions/settings.js b/app/soapbox/actions/settings.ts similarity index 79% rename from app/soapbox/actions/settings.js rename to app/soapbox/actions/settings.ts index 45b5759be..fd37735b1 100644 --- a/app/soapbox/actions/settings.js +++ b/app/soapbox/actions/settings.ts @@ -9,17 +9,19 @@ import { isLoggedIn } from 'soapbox/utils/auth'; import { showAlertForError } from './alerts'; import snackbar from './snackbar'; -export const SETTING_CHANGE = 'SETTING_CHANGE'; -export const SETTING_SAVE = 'SETTING_SAVE'; -export const SETTINGS_UPDATE = 'SETTINGS_UPDATE'; +import type { AppDispatch, RootState } from 'soapbox/store'; -export const FE_NAME = 'soapbox_fe'; +const SETTING_CHANGE = 'SETTING_CHANGE'; +const SETTING_SAVE = 'SETTING_SAVE'; +const SETTINGS_UPDATE = 'SETTINGS_UPDATE'; + +const FE_NAME = 'soapbox_fe'; const messages = defineMessages({ saveSuccess: { id: 'settings.save.success', defaultMessage: 'Your preferences have been saved!' }, }); -export const defaultSettings = ImmutableMap({ +const defaultSettings = ImmutableMap({ onboarded: false, skinTone: 1, reduceMotion: false, @@ -166,17 +168,17 @@ export const defaultSettings = ImmutableMap({ }), }); -export const getSettings = createSelector([ - state => state.getIn(['soapbox', 'defaultSettings']), - state => state.get('settings'), +const getSettings = createSelector([ + (state: RootState) => state.soapbox.get('defaultSettings'), + (state: RootState) => state.settings, ], (soapboxSettings, settings) => { return defaultSettings .mergeDeep(soapboxSettings) .mergeDeep(settings); }); -export function changeSettingImmediate(path, value) { - return dispatch => { +const changeSettingImmediate = (path: string[], value: any) => + (dispatch: AppDispatch) => { dispatch({ type: SETTING_CHANGE, path, @@ -185,10 +187,9 @@ export function changeSettingImmediate(path, value) { dispatch(saveSettingsImmediate()); }; -} -export function changeSetting(path, value) { - return dispatch => { +const changeSetting = (path: string[], value: any) => + (dispatch: AppDispatch) => { dispatch({ type: SETTING_CHANGE, path, @@ -197,22 +198,21 @@ export function changeSetting(path, value) { return dispatch(saveSettings()); }; -} -export function saveSettingsImmediate() { - return (dispatch, getState) => { +const saveSettingsImmediate = () => + (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; const state = getState(); if (getSettings(state).getIn(['saved'])) return; - const data = state.get('settings').delete('saved').toJS(); + const data = state.settings.delete('saved').toJS(); dispatch(patchMe({ pleroma_settings_store: { [FE_NAME]: data, }, - })).then(response => { + })).then(() => { dispatch({ type: SETTING_SAVE }); dispatch(snackbar.success(messages.saveSuccess)); @@ -220,8 +220,19 @@ export function saveSettingsImmediate() { dispatch(showAlertForError(error)); }); }; -} -export function saveSettings() { - return (dispatch, getState) => dispatch(saveSettingsImmediate()); -} +const saveSettings = () => + (dispatch: AppDispatch) => dispatch(saveSettingsImmediate()); + +export { + SETTING_CHANGE, + SETTING_SAVE, + SETTINGS_UPDATE, + FE_NAME, + defaultSettings, + getSettings, + changeSettingImmediate, + changeSetting, + saveSettingsImmediate, + saveSettings, +}; diff --git a/app/soapbox/actions/statuses.js b/app/soapbox/actions/statuses.ts similarity index 61% rename from app/soapbox/actions/statuses.js rename to app/soapbox/actions/statuses.ts index bc580455a..cf9306b67 100644 --- a/app/soapbox/actions/statuses.js +++ b/app/soapbox/actions/statuses.ts @@ -9,43 +9,46 @@ import { importFetchedStatus, importFetchedStatuses } from './importer'; import { openModal } from './modals'; import { deleteFromTimelines } from './timelines'; -export const STATUS_CREATE_REQUEST = 'STATUS_CREATE_REQUEST'; -export const STATUS_CREATE_SUCCESS = 'STATUS_CREATE_SUCCESS'; -export const STATUS_CREATE_FAIL = 'STATUS_CREATE_FAIL'; +import type { AppDispatch, RootState } from 'soapbox/store'; +import type { APIEntity } from 'soapbox/types/entities'; -export const STATUS_FETCH_SOURCE_REQUEST = 'STATUS_FETCH_SOURCE_REQUEST'; -export const STATUS_FETCH_SOURCE_SUCCESS = 'STATUS_FETCH_SOURCE_SUCCESS'; -export const STATUS_FETCH_SOURCE_FAIL = 'STATUS_FETCH_SOURCE_FAIL'; +const STATUS_CREATE_REQUEST = 'STATUS_CREATE_REQUEST'; +const STATUS_CREATE_SUCCESS = 'STATUS_CREATE_SUCCESS'; +const STATUS_CREATE_FAIL = 'STATUS_CREATE_FAIL'; -export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST'; -export const STATUS_FETCH_SUCCESS = 'STATUS_FETCH_SUCCESS'; -export const STATUS_FETCH_FAIL = 'STATUS_FETCH_FAIL'; +const STATUS_FETCH_SOURCE_REQUEST = 'STATUS_FETCH_SOURCE_REQUEST'; +const STATUS_FETCH_SOURCE_SUCCESS = 'STATUS_FETCH_SOURCE_SUCCESS'; +const STATUS_FETCH_SOURCE_FAIL = 'STATUS_FETCH_SOURCE_FAIL'; -export const STATUS_DELETE_REQUEST = 'STATUS_DELETE_REQUEST'; -export const STATUS_DELETE_SUCCESS = 'STATUS_DELETE_SUCCESS'; -export const STATUS_DELETE_FAIL = 'STATUS_DELETE_FAIL'; +const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST'; +const STATUS_FETCH_SUCCESS = 'STATUS_FETCH_SUCCESS'; +const STATUS_FETCH_FAIL = 'STATUS_FETCH_FAIL'; -export const CONTEXT_FETCH_REQUEST = 'CONTEXT_FETCH_REQUEST'; -export const CONTEXT_FETCH_SUCCESS = 'CONTEXT_FETCH_SUCCESS'; -export const CONTEXT_FETCH_FAIL = 'CONTEXT_FETCH_FAIL'; +const STATUS_DELETE_REQUEST = 'STATUS_DELETE_REQUEST'; +const STATUS_DELETE_SUCCESS = 'STATUS_DELETE_SUCCESS'; +const STATUS_DELETE_FAIL = 'STATUS_DELETE_FAIL'; -export const STATUS_MUTE_REQUEST = 'STATUS_MUTE_REQUEST'; -export const STATUS_MUTE_SUCCESS = 'STATUS_MUTE_SUCCESS'; -export const STATUS_MUTE_FAIL = 'STATUS_MUTE_FAIL'; +const CONTEXT_FETCH_REQUEST = 'CONTEXT_FETCH_REQUEST'; +const CONTEXT_FETCH_SUCCESS = 'CONTEXT_FETCH_SUCCESS'; +const CONTEXT_FETCH_FAIL = 'CONTEXT_FETCH_FAIL'; -export const STATUS_UNMUTE_REQUEST = 'STATUS_UNMUTE_REQUEST'; -export const STATUS_UNMUTE_SUCCESS = 'STATUS_UNMUTE_SUCCESS'; -export const STATUS_UNMUTE_FAIL = 'STATUS_UNMUTE_FAIL'; +const STATUS_MUTE_REQUEST = 'STATUS_MUTE_REQUEST'; +const STATUS_MUTE_SUCCESS = 'STATUS_MUTE_SUCCESS'; +const STATUS_MUTE_FAIL = 'STATUS_MUTE_FAIL'; -export const STATUS_REVEAL = 'STATUS_REVEAL'; -export const STATUS_HIDE = 'STATUS_HIDE'; +const STATUS_UNMUTE_REQUEST = 'STATUS_UNMUTE_REQUEST'; +const STATUS_UNMUTE_SUCCESS = 'STATUS_UNMUTE_SUCCESS'; +const STATUS_UNMUTE_FAIL = 'STATUS_UNMUTE_FAIL'; -const statusExists = (getState, statusId) => { - return getState().getIn(['statuses', statusId], null) !== null; +const STATUS_REVEAL = 'STATUS_REVEAL'; +const STATUS_HIDE = 'STATUS_HIDE'; + +const statusExists = (getState: () => RootState, statusId: string) => { + return (getState().statuses.get(statusId) || null) !== null; }; -export function createStatus(params, idempotencyKey, statusId) { - return (dispatch, getState) => { +const createStatus = (params: Record, idempotencyKey: string, statusId: string) => { + return (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: STATUS_CREATE_REQUEST, params, idempotencyKey }); return api(getState).request({ @@ -85,13 +88,13 @@ export function createStatus(params, idempotencyKey, statusId) { throw error; }); }; -} +}; -export const editStatus = (id) => (dispatch, getState) => { - let status = getState().getIn(['statuses', id]); +const editStatus = (id: string) => (dispatch: AppDispatch, getState: () => RootState) => { + let status = getState().statuses.get(id)!; - if (status.get('poll')) { - status = status.set('poll', getState().getIn(['polls', status.get('poll')])); + if (status.poll) { + status = status.set('poll', getState().polls.get(status.poll) as any); } dispatch({ type: STATUS_FETCH_SOURCE_REQUEST }); @@ -106,8 +109,8 @@ export const editStatus = (id) => (dispatch, getState) => { }); }; -export function fetchStatus(id) { - return (dispatch, getState) => { +const fetchStatus = (id: string) => { + return (dispatch: AppDispatch, getState: () => RootState) => { const skipLoading = statusExists(getState, id); dispatch({ type: STATUS_FETCH_REQUEST, id, skipLoading }); @@ -120,16 +123,16 @@ export function fetchStatus(id) { dispatch({ type: STATUS_FETCH_FAIL, id, error, skipLoading, skipAlert: true }); }); }; -} +}; -export function deleteStatus(id, routerHistory, withRedraft = false) { - return (dispatch, getState) => { +const deleteStatus = (id: string, withRedraft = false) => { + return (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return null; - let status = getState().getIn(['statuses', id]); + let status = getState().statuses.get(id)!; - if (status.get('poll')) { - status = status.set('poll', getState().getIn(['polls', status.get('poll')])); + if (status.poll) { + status = status.set('poll', getState().polls.get(status.poll) as any); } dispatch({ type: STATUS_DELETE_REQUEST, params: status }); @@ -149,13 +152,13 @@ export function deleteStatus(id, routerHistory, withRedraft = false) { dispatch({ type: STATUS_DELETE_FAIL, params: status, error }); }); }; -} +}; -export const updateStatus = status => dispatch => +const updateStatus = (status: APIEntity) => (dispatch: AppDispatch) => dispatch(importFetchedStatus(status)); -export function fetchContext(id) { - return (dispatch, getState) => { +const fetchContext = (id: string) => + (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: CONTEXT_FETCH_REQUEST, id }); return api(getState).get(`/api/v1/statuses/${id}/context`).then(({ data: context }) => { @@ -180,10 +183,9 @@ export function fetchContext(id) { dispatch({ type: CONTEXT_FETCH_FAIL, id, error, skipAlert: true }); }); }; -} -export function fetchNext(statusId, next) { - return async(dispatch, getState) => { +const fetchNext = (statusId: string, next: string) => + async(dispatch: AppDispatch, getState: () => RootState) => { const response = await api(getState).get(next); dispatch(importFetchedStatuses(response.data)); @@ -196,26 +198,23 @@ export function fetchNext(statusId, next) { return { next: getNextLink(response) }; }; -} -export function fetchAncestors(id) { - return async(dispatch, getState) => { +const fetchAncestors = (id: string) => + async(dispatch: AppDispatch, getState: () => RootState) => { const response = await api(getState).get(`/api/v1/statuses/${id}/context/ancestors`); dispatch(importFetchedStatuses(response.data)); return response; }; -} -export function fetchDescendants(id) { - return async(dispatch, getState) => { +const fetchDescendants = (id: string) => + async(dispatch: AppDispatch, getState: () => RootState) => { const response = await api(getState).get(`/api/v1/statuses/${id}/context/descendants`); dispatch(importFetchedStatuses(response.data)); return response; }; -} -export function fetchStatusWithContext(id) { - return async(dispatch, getState) => { +const fetchStatusWithContext = (id: string) => + async(dispatch: AppDispatch, getState: () => RootState) => { const features = getFeatures(getState().instance); if (features.paginatedContext) { @@ -242,10 +241,10 @@ export function fetchStatusWithContext(id) { return { next: undefined }; } }; -} -export function muteStatus(id) { - return (dispatch, getState) => { + +const muteStatus = (id: string) => + (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; dispatch({ type: STATUS_MUTE_REQUEST, id }); @@ -255,10 +254,9 @@ export function muteStatus(id) { dispatch({ type: STATUS_MUTE_FAIL, id, error }); }); }; -} -export function unmuteStatus(id) { - return (dispatch, getState) => { +const unmuteStatus = (id: string) => + (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; dispatch({ type: STATUS_UNMUTE_REQUEST, id }); @@ -268,9 +266,8 @@ export function unmuteStatus(id) { dispatch({ type: STATUS_UNMUTE_FAIL, id, error }); }); }; -} -export function hideStatus(ids) { +const hideStatus = (ids: string[] | string) => { if (!Array.isArray(ids)) { ids = [ids]; } @@ -279,9 +276,9 @@ export function hideStatus(ids) { type: STATUS_HIDE, ids, }; -} +}; -export function revealStatus(ids) { +const revealStatus = (ids: string[] | string) => { if (!Array.isArray(ids)) { ids = [ids]; } @@ -290,4 +287,44 @@ export function revealStatus(ids) { type: STATUS_REVEAL, ids, }; -} +}; + +export { + STATUS_CREATE_REQUEST, + STATUS_CREATE_SUCCESS, + STATUS_CREATE_FAIL, + STATUS_FETCH_SOURCE_REQUEST, + STATUS_FETCH_SOURCE_SUCCESS, + STATUS_FETCH_SOURCE_FAIL, + STATUS_FETCH_REQUEST, + STATUS_FETCH_SUCCESS, + STATUS_FETCH_FAIL, + STATUS_DELETE_REQUEST, + STATUS_DELETE_SUCCESS, + STATUS_DELETE_FAIL, + CONTEXT_FETCH_REQUEST, + CONTEXT_FETCH_SUCCESS, + CONTEXT_FETCH_FAIL, + STATUS_MUTE_REQUEST, + STATUS_MUTE_SUCCESS, + STATUS_MUTE_FAIL, + STATUS_UNMUTE_REQUEST, + STATUS_UNMUTE_SUCCESS, + STATUS_UNMUTE_FAIL, + STATUS_REVEAL, + STATUS_HIDE, + createStatus, + editStatus, + fetchStatus, + deleteStatus, + updateStatus, + fetchContext, + fetchNext, + fetchAncestors, + fetchDescendants, + fetchStatusWithContext, + muteStatus, + unmuteStatus, + hideStatus, + revealStatus, +}; diff --git a/app/soapbox/components/status_action_bar.tsx b/app/soapbox/components/status_action_bar.tsx index dbb78b8d7..302194d7a 100644 --- a/app/soapbox/components/status_action_bar.tsx +++ b/app/soapbox/components/status_action_bar.tsx @@ -76,7 +76,7 @@ interface IStatusActionBar extends RouteComponentProps { onBookmark: (status: Status) => void, onReblog: (status: Status, e: React.MouseEvent) => void, onQuote: (status: Status, history: History) => void, - onDelete: (status: Status, history: History, redraft?: boolean) => void, + onDelete: (status: Status, redraft?: boolean) => void, onEdit: (status: Status) => void, onDirect: (account: any, history: History) => void, onChat: (account: any, history: History) => void, @@ -241,12 +241,12 @@ class StatusActionBar extends ImmutablePureComponent = (e) => { e.stopPropagation(); - this.props.onDelete(this.props.status, this.props.history); + this.props.onDelete(this.props.status); } handleRedraftClick: React.EventHandler = (e) => { e.stopPropagation(); - this.props.onDelete(this.props.status, this.props.history, true); + this.props.onDelete(this.props.status, true); } handleEditClick: React.EventHandler = () => { diff --git a/app/soapbox/containers/status_container.js b/app/soapbox/containers/status_container.js index a5ecc7f95..43cb72873 100644 --- a/app/soapbox/containers/status_container.js +++ b/app/soapbox/containers/status_container.js @@ -156,18 +156,18 @@ const mapDispatchToProps = (dispatch, { intl }) => { })); }, - onDelete(status, history, withRedraft = false) { + onDelete(status, withRedraft = false) { dispatch((_, getState) => { const deleteModal = getSettings(getState()).get('deleteModal'); if (!deleteModal) { - dispatch(deleteStatus(status.get('id'), history, withRedraft)); + dispatch(deleteStatus(status.get('id'), withRedraft)); } else { dispatch(openModal('CONFIRM', { icon: withRedraft ? require('@tabler/icons/icons/edit.svg') : require('@tabler/icons/icons/trash.svg'), heading: intl.formatMessage(withRedraft ? messages.redraftHeading : messages.deleteHeading), message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage), confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm), - onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)), + onConfirm: () => dispatch(deleteStatus(status.get('id'), withRedraft)), })); } }); diff --git a/app/soapbox/features/status/components/action-bar.tsx b/app/soapbox/features/status/components/action-bar.tsx index 50055df23..885713c45 100644 --- a/app/soapbox/features/status/components/action-bar.tsx +++ b/app/soapbox/features/status/components/action-bar.tsx @@ -94,7 +94,7 @@ interface OwnProps { onQuote: (status: StatusEntity, history: History) => void, onFavourite: (status: StatusEntity) => void, onEmojiReact: (status: StatusEntity, emoji: string) => void, - onDelete: (status: StatusEntity, history: History, redraft?: boolean) => void, + onDelete: (status: StatusEntity, redraft?: boolean) => void, onEdit: (status: StatusEntity) => void, onBookmark: (status: StatusEntity) => void, onDirect: (account: AccountEntity, history: History) => void, @@ -236,11 +236,11 @@ class ActionBar extends React.PureComponent { } handleDeleteClick: React.EventHandler = () => { - this.props.onDelete(this.props.status, this.props.history); + this.props.onDelete(this.props.status); } handleRedraftClick: React.EventHandler = () => { - this.props.onDelete(this.props.status, this.props.history, true); + this.props.onDelete(this.props.status, true); } handleEditClick: React.EventHandler = () => { diff --git a/app/soapbox/features/status/containers/detailed_status_container.js b/app/soapbox/features/status/containers/detailed_status_container.js index d0c871f5a..ae9dcc97a 100644 --- a/app/soapbox/features/status/containers/detailed_status_container.js +++ b/app/soapbox/features/status/containers/detailed_status_container.js @@ -128,18 +128,18 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ })); }, - onDelete(status, history, withRedraft = false) { + onDelete(status, withRedraft = false) { dispatch((_, getState) => { const deleteModal = getSettings(getState()).get('deleteModal'); if (!deleteModal) { - dispatch(deleteStatus(status.get('id'), history, withRedraft)); + dispatch(deleteStatus(status.get('id'), withRedraft)); } else { dispatch(openModal('CONFIRM', { icon: withRedraft ? require('@tabler/icons/icons/edit.svg') : require('@tabler/icons/icons/trash.svg'), heading: intl.formatMessage(withRedraft ? messages.redraftHeading : messages.deleteHeading), message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage), confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm), - onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)), + onConfirm: () => dispatch(deleteStatus(status.get('id'), withRedraft)), })); } }); diff --git a/app/soapbox/features/status/index.tsx b/app/soapbox/features/status/index.tsx index 608278d23..3a0803dc5 100644 --- a/app/soapbox/features/status/index.tsx +++ b/app/soapbox/features/status/index.tsx @@ -312,20 +312,20 @@ class Status extends ImmutablePureComponent { } } - handleDeleteClick = (status: StatusEntity, history: History, withRedraft = false) => { + handleDeleteClick = (status: StatusEntity, withRedraft = false) => { const { dispatch, intl } = this.props; this.props.dispatch((_, getState) => { const deleteModal = getSettings(getState()).get('deleteModal'); if (!deleteModal) { - dispatch(deleteStatus(status.id, history, withRedraft)); + dispatch(deleteStatus(status.id, withRedraft)); } else { dispatch(openModal('CONFIRM', { icon: withRedraft ? require('@tabler/icons/icons/edit.svg') : require('@tabler/icons/icons/trash.svg'), heading: intl.formatMessage(withRedraft ? messages.redraftHeading : messages.deleteHeading), message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage), confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm), - onConfirm: () => dispatch(deleteStatus(status.id, history, withRedraft)), + onConfirm: () => dispatch(deleteStatus(status.id, withRedraft)), })); } });