From c41b613cca257e24d515a73e90933530492d745f Mon Sep 17 00:00:00 2001 From: mkljczk Date: Thu, 5 Dec 2024 14:00:01 +0100 Subject: [PATCH] pl-fe: remove unused actions Signed-off-by: mkljczk --- packages/pl-fe/src/actions/admin.ts | 10 +- packages/pl-fe/src/actions/auth.ts | 9 +- packages/pl-fe/src/actions/emoji-reacts.ts | 34 --- packages/pl-fe/src/actions/external-auth.ts | 2 +- packages/pl-fe/src/actions/interactions.ts | 209 +----------------- packages/pl-fe/src/actions/lists.ts | 99 +-------- packages/pl-fe/src/actions/markers.ts | 41 +--- packages/pl-fe/src/actions/me.ts | 34 +-- packages/pl-fe/src/actions/mfa.ts | 88 +------- packages/pl-fe/src/actions/oauth.ts | 39 +--- packages/pl-fe/src/actions/pl-fe.ts | 5 +- .../pl-fe/src/actions/scheduled-statuses.ts | 11 - packages/pl-fe/src/actions/security.ts | 138 +----------- .../src/features/developers/apps/create.tsx | 4 +- .../src/features/event/event-discussion.tsx | 4 +- .../src/features/landing-timeline/index.tsx | 4 +- 16 files changed, 60 insertions(+), 671 deletions(-) diff --git a/packages/pl-fe/src/actions/admin.ts b/packages/pl-fe/src/actions/admin.ts index 58ea0a9b1..afa3476aa 100644 --- a/packages/pl-fe/src/actions/admin.ts +++ b/packages/pl-fe/src/actions/admin.ts @@ -111,21 +111,19 @@ const approveUser = (accountId: string) => }; const deleteStatus = (statusId: string) => - (dispatch: AppDispatch, getState: () => RootState) => { - return getClient(getState).admin.statuses.deleteStatus(statusId) + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).admin.statuses.deleteStatus(statusId) .then(() => { dispatch(deleteFromTimelines(statusId)); return ({ statusId }); }); - }; const toggleStatusSensitivity = (statusId: string, sensitive: boolean) => - (dispatch: AppDispatch, getState: () => RootState) => { - return getClient(getState).admin.statuses.updateStatus(statusId, { sensitive: !sensitive }) + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).admin.statuses.updateStatus(statusId, { sensitive: !sensitive }) .then((status) => { dispatch(importEntities({ statuses: [status] })); }); - }; const tagUser = (accountId: string, tags: string[]) => (dispatch: AppDispatch, getState: () => RootState) => diff --git a/packages/pl-fe/src/actions/auth.ts b/packages/pl-fe/src/actions/auth.ts index f1af5a7b9..d2a303795 100644 --- a/packages/pl-fe/src/actions/auth.ts +++ b/packages/pl-fe/src/actions/auth.ts @@ -118,7 +118,7 @@ const createAppToken = () => scope: getScopes(getState()), }; - return dispatch(obtainOAuthToken(params)).then((token) => + return obtainOAuthToken(params).then((token) => dispatch({ type: AUTH_APP_AUTHORIZED, app, token }), ); }; @@ -137,7 +137,7 @@ const createUserToken = (username: string, password: string) => scope: getScopes(getState()), }; - return dispatch(obtainOAuthToken(params)) + return obtainOAuthToken(params) .then((token) => dispatch(authLoggedIn(token))); }; @@ -212,14 +212,13 @@ interface AuthAccountRememberSuccessAction { } const rememberAuthAccount = (accountUrl: string) => - (dispatch: AppDispatch, getState: () => RootState) => { - return KVStore.getItemOrError(`authAccount:${accountUrl}`).then(account => { + (dispatch: AppDispatch, getState: () => RootState) => + KVStore.getItemOrError(`authAccount:${accountUrl}`).then(account => { dispatch(importEntities({ accounts: [account] })); dispatch({ type: AUTH_ACCOUNT_REMEMBER_SUCCESS, account, accountUrl }); if (account.id === getState().me) dispatch(fetchMeSuccess(account)); return account; }); - }; const loadCredentials = (token: string, accountUrl: string) => (dispatch: AppDispatch) => dispatch(rememberAuthAccount(accountUrl)) diff --git a/packages/pl-fe/src/actions/emoji-reacts.ts b/packages/pl-fe/src/actions/emoji-reacts.ts index 5d5bb83c3..5531452fb 100644 --- a/packages/pl-fe/src/actions/emoji-reacts.ts +++ b/packages/pl-fe/src/actions/emoji-reacts.ts @@ -8,12 +8,9 @@ import type { Status } from 'pl-api'; import type { AppDispatch, RootState } from 'pl-fe/store'; const EMOJI_REACT_REQUEST = 'EMOJI_REACT_REQUEST' as const; -const EMOJI_REACT_SUCCESS = 'EMOJI_REACT_SUCCESS' as const; const EMOJI_REACT_FAIL = 'EMOJI_REACT_FAIL' as const; const UNEMOJI_REACT_REQUEST = 'UNEMOJI_REACT_REQUEST' as const; -const UNEMOJI_REACT_SUCCESS = 'UNEMOJI_REACT_SUCCESS' as const; -const UNEMOJI_REACT_FAIL = 'UNEMOJI_REACT_FAIL' as const; const noOp = () => () => new Promise(f => f(undefined)); @@ -25,7 +22,6 @@ const emojiReact = (status: Pick, emoji: string, custom?: string) return getClient(getState).statuses.createStatusReaction(status.id, emoji).then((response) => { dispatch(importEntities({ statuses: [response] })); - dispatch(emojiReactSuccess(response, emoji)); }).catch((error) => { dispatch(emojiReactFail(status.id, emoji, error)); }); @@ -39,9 +35,6 @@ const unEmojiReact = (status: Pick, emoji: string) => return getClient(getState).statuses.deleteStatusReaction(status.id, emoji).then(response => { dispatch(importEntities({ statuses: [response] })); - dispatch(unEmojiReactSuccess(response, emoji)); - }).catch(error => { - dispatch(unEmojiReactFail(status.id, emoji, error)); }); }; @@ -52,13 +45,6 @@ const emojiReactRequest = (statusId: string, emoji: string, custom?: string) => custom, }); -const emojiReactSuccess = (status: Status, emoji: string) => ({ - type: EMOJI_REACT_SUCCESS, - status, - statusId: status.id, - emoji, -}); - const emojiReactFail = (statusId: string, emoji: string, error: unknown) => ({ type: EMOJI_REACT_FAIL, statusId, @@ -72,35 +58,15 @@ const unEmojiReactRequest = (statusId: string, emoji: string) => ({ emoji, }); -const unEmojiReactSuccess = (status: Status, emoji: string) => ({ - type: UNEMOJI_REACT_SUCCESS, - status, - statusId: status.id, - emoji, -}); - -const unEmojiReactFail = (statusId: string, emoji: string, error: unknown) => ({ - type: UNEMOJI_REACT_FAIL, - statusId, - emoji, - error, -}); - type EmojiReactsAction = | ReturnType - | ReturnType | ReturnType | ReturnType - | ReturnType - | ReturnType export { EMOJI_REACT_REQUEST, - EMOJI_REACT_SUCCESS, EMOJI_REACT_FAIL, UNEMOJI_REACT_REQUEST, - UNEMOJI_REACT_SUCCESS, - UNEMOJI_REACT_FAIL, emojiReact, unEmojiReact, type EmojiReactsAction, diff --git a/packages/pl-fe/src/actions/external-auth.ts b/packages/pl-fe/src/actions/external-auth.ts index 2885c1e76..2232873d0 100644 --- a/packages/pl-fe/src/actions/external-auth.ts +++ b/packages/pl-fe/src/actions/external-auth.ts @@ -88,7 +88,7 @@ const loginWithCode = (code: string) => code, }; - return dispatch(obtainOAuthToken(params, baseURL)) + return obtainOAuthToken(params, baseURL) .then((token) => dispatch(authLoggedIn(token))) .then(({ access_token }) => dispatch(verifyCredentials(access_token, baseURL))) .then((account) => dispatch(switchAccount(account.id))) diff --git a/packages/pl-fe/src/actions/interactions.ts b/packages/pl-fe/src/actions/interactions.ts index 1d907baf3..33316cc63 100644 --- a/packages/pl-fe/src/actions/interactions.ts +++ b/packages/pl-fe/src/actions/interactions.ts @@ -12,7 +12,6 @@ import type { Status } from 'pl-api'; import type { AppDispatch, RootState } from 'pl-fe/store'; const REBLOG_REQUEST = 'REBLOG_REQUEST' as const; -const REBLOG_SUCCESS = 'REBLOG_SUCCESS' as const; const REBLOG_FAIL = 'REBLOG_FAIL' as const; const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST' as const; @@ -20,40 +19,23 @@ const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS' as const; const FAVOURITE_FAIL = 'FAVOURITE_FAIL' as const; const DISLIKE_REQUEST = 'DISLIKE_REQUEST' as const; -const DISLIKE_SUCCESS = 'DISLIKE_SUCCESS' as const; const DISLIKE_FAIL = 'DISLIKE_FAIL' as const; const UNREBLOG_REQUEST = 'UNREBLOG_REQUEST' as const; -const UNREBLOG_SUCCESS = 'UNREBLOG_SUCCESS' as const; const UNREBLOG_FAIL = 'UNREBLOG_FAIL' as const; const UNFAVOURITE_REQUEST = 'UNFAVOURITE_REQUEST' as const; const UNFAVOURITE_SUCCESS = 'UNFAVOURITE_SUCCESS' as const; -const UNFAVOURITE_FAIL = 'UNFAVOURITE_FAIL' as const; const UNDISLIKE_REQUEST = 'UNDISLIKE_REQUEST' as const; -const UNDISLIKE_SUCCESS = 'UNDISLIKE_SUCCESS' as const; -const UNDISLIKE_FAIL = 'UNDISLIKE_FAIL' as const; -const PIN_REQUEST = 'PIN_REQUEST' as const; const PIN_SUCCESS = 'PIN_SUCCESS' as const; -const PIN_FAIL = 'PIN_FAIL' as const; -const UNPIN_REQUEST = 'UNPIN_REQUEST' as const; const UNPIN_SUCCESS = 'UNPIN_SUCCESS' as const; -const UNPIN_FAIL = 'UNPIN_FAIL' as const; -const BOOKMARK_REQUEST = 'BOOKMARK_REQUEST' as const; const BOOKMARK_SUCCESS = 'BOOKMARKED_SUCCESS' as const; -const BOOKMARK_FAIL = 'BOOKMARKED_FAIL' as const; -const UNBOOKMARK_REQUEST = 'UNBOOKMARKED_REQUEST' as const; const UNBOOKMARK_SUCCESS = 'UNBOOKMARKED_SUCCESS' as const; -const UNBOOKMARK_FAIL = 'UNBOOKMARKED_FAIL' as const; - -const REMOTE_INTERACTION_REQUEST = 'REMOTE_INTERACTION_REQUEST' as const; -const REMOTE_INTERACTION_SUCCESS = 'REMOTE_INTERACTION_SUCCESS' as const; -const REMOTE_INTERACTION_FAIL = 'REMOTE_INTERACTION_FAIL' as const; const noOp = () => new Promise(f => f(undefined)); @@ -75,7 +57,6 @@ const reblog = (status: Pick) => // The reblog API method returns a new status wrapped around the original. In this case we are only // interested in how the original is modified, hence passing it skipping the wrapper if (response.reblog) dispatch(importEntities({ statuses: [response.reblog] })); - dispatch(reblogSuccess(response)); }).catch(error => { dispatch(reblogFail(status.id, error)); }); @@ -87,9 +68,7 @@ const unreblog = (status: Pick) => dispatch(unreblogRequest(status.id)); - return getClient(getState()).statuses.unreblogStatus(status.id).then((status) => { - dispatch(unreblogSuccess(status)); - }).catch(error => { + return getClient(getState()).statuses.unreblogStatus(status.id).catch(error => { dispatch(unreblogFail(status.id, error)); }); }; @@ -107,12 +86,6 @@ const reblogRequest = (statusId: string) => ({ statusId, }); -const reblogSuccess = (status: Status) => ({ - type: REBLOG_SUCCESS, - status, - statusId: status.id, -}); - const reblogFail = (statusId: string, error: unknown) => ({ type: REBLOG_FAIL, statusId, @@ -124,12 +97,6 @@ const unreblogRequest = (statusId: string) => ({ statusId, }); -const unreblogSuccess = (status: Status) => ({ - type: UNREBLOG_SUCCESS, - status, - statusId: status.id, -}); - const unreblogFail = (statusId: string, error: unknown) => ({ type: UNREBLOG_FAIL, statusId, @@ -157,8 +124,6 @@ const unfavourite = (status: Pick) => return getClient(getState()).statuses.unfavouriteStatus(status.id).then((response) => { dispatch(unfavouriteSuccess(response)); - }).catch(error => { - dispatch(unfavouriteFail(status.id, error)); }); }; @@ -198,21 +163,13 @@ const unfavouriteSuccess = (status: Status) => ({ statusId: status.id, }); -const unfavouriteFail = (statusId: string, error: unknown) => ({ - type: UNFAVOURITE_FAIL, - statusId, - error, -}); - const dislike = (status: Pick) => (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; dispatch(dislikeRequest(status.id)); - return getClient(getState).statuses.dislikeStatus(status.id).then((response) => { - dispatch(dislikeSuccess(response)); - }).catch((error) => { + return getClient(getState).statuses.dislikeStatus(status.id).catch((error) => { dispatch(dislikeFail(status.id, error)); }); }; @@ -223,11 +180,7 @@ const undislike = (status: Pick) => dispatch(undislikeRequest(status.id)); - return getClient(getState).statuses.undislikeStatus(status.id).then((response) => { - dispatch(undislikeSuccess(response)); - }).catch(error => { - dispatch(undislikeFail(status.id, error)); - }); + return getClient(getState).statuses.undislikeStatus(status.id); }; const toggleDislike = (status: Pick) => @@ -244,12 +197,6 @@ const dislikeRequest = (statusId: string) => ({ statusId, }); -const dislikeSuccess = (status: Status) => ({ - type: DISLIKE_SUCCESS, - status, - statusId: status.id, -}); - const dislikeFail = (statusId: string, error: unknown) => ({ type: DISLIKE_FAIL, statusId, @@ -261,26 +208,12 @@ const undislikeRequest = (statusId: string) => ({ statusId, }); -const undislikeSuccess = (status: Status) => ({ - type: UNDISLIKE_SUCCESS, - status, - statusId: status.id, -}); - -const undislikeFail = (statusId: string, error: unknown) => ({ - type: UNDISLIKE_FAIL, - statusId, - error, -}); - const bookmark = (status: Pick, folderId?: string) => (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); const features = state.auth.client.features; - dispatch(bookmarkRequest(status.id)); - return getClient(getState()).statuses.bookmarkStatus(status.id, folderId).then((response) => { dispatch(importEntities({ statuses: [response] })); dispatch(bookmarkSuccess(response)); @@ -300,23 +233,16 @@ const bookmark = (status: Pick, folderId?: string) => } toast.success(typeof folderId === 'string' ? messages.folderChanged : messages.bookmarkAdded, opts); - }).catch((error) => { - dispatch(bookmarkFail(status.id, error)); }); }; const unbookmark = (status: Pick) => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch(unbookmarkRequest(status.id)); - - return getClient(getState()).statuses.unbookmarkStatus(status.id).then(response => { + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).statuses.unbookmarkStatus(status.id).then(response => { dispatch(importEntities({ statuses: [response] })); dispatch(unbookmarkSuccess(response)); toast.success(messages.bookmarkRemoved); - }).catch(error => { - dispatch(unbookmarkFail(status.id, error)); }); - }; const toggleBookmark = (status: Pick) => (dispatch: AppDispatch) => { @@ -327,60 +253,29 @@ const toggleBookmark = (status: Pick) => } }; -const bookmarkRequest = (statusId: string) => ({ - type: BOOKMARK_REQUEST, - statusId, -}); - const bookmarkSuccess = (status: Status) => ({ type: BOOKMARK_SUCCESS, status, statusId: status.id, }); -const bookmarkFail = (statusId: string, error: unknown) => ({ - type: BOOKMARK_FAIL, - statusId, - error, -}); - -const unbookmarkRequest = (statusId: string) => ({ - type: UNBOOKMARK_REQUEST, - statusId, -}); - const unbookmarkSuccess = (status: Status) => ({ type: UNBOOKMARK_SUCCESS, status, statusId: status.id, }); -const unbookmarkFail = (statusId: string, error: unknown) => ({ - type: UNBOOKMARK_FAIL, - statusId, - error, -}); - const pin = (status: Pick, accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; - dispatch(pinRequest(status.id, accountId)); - return getClient(getState()).statuses.pinStatus(status.id).then(response => { dispatch(importEntities({ statuses: [response] })); dispatch(pinSuccess(response, accountId)); }).catch(error => { - dispatch(pinFail(status.id, error, accountId)); }); }; -const pinRequest = (statusId: string, accountId: string) => ({ - type: PIN_REQUEST, - statusId, - accountId, -}); - const pinSuccess = (status: Status, accountId: string) => ({ type: PIN_SUCCESS, status, @@ -388,24 +283,13 @@ const pinSuccess = (status: Status, accountId: string) => ({ accountId, }); -const pinFail = (statusId: string, error: unknown, accountId: string) => ({ - type: PIN_FAIL, - statusId, - error, - accountId, -}); - const unpin = (status: Pick, accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; - dispatch(unpinRequest(status.id, accountId)); - return getClient(getState()).statuses.unpinStatus(status.id).then(response => { dispatch(importEntities({ statuses: [response] })); dispatch(unpinSuccess(response, accountId)); - }).catch(error => { - dispatch(unpinFail(status.id, error, accountId)); }); }; @@ -422,12 +306,6 @@ const togglePin = (status: Pick) => } }; -const unpinRequest = (statusId: string, accountId: string) => ({ - type: UNPIN_REQUEST, - statusId, - accountId, -}); - const unpinSuccess = (status: Status, accountId: string) => ({ type: UNPIN_SUCCESS, status, @@ -435,116 +313,45 @@ const unpinSuccess = (status: Status, accountId: string) => ({ accountId, }); -const unpinFail = (statusId: string, error: unknown, accountId: string) => ({ - type: UNPIN_FAIL, - statusId, - error, - accountId, -}); - const remoteInteraction = (ap_id: string, profile: string) => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch(remoteInteractionRequest(ap_id, profile)); - - return getClient(getState).accounts.remoteInteraction(ap_id, profile).then((data) => { - dispatch(remoteInteractionSuccess(ap_id, profile, data.url)); - - return data.url; - }).catch(error => { - dispatch(remoteInteractionFail(ap_id, profile, error)); - throw error; - }); - }; - -const remoteInteractionRequest = (ap_id: string, profile: string) => ({ - type: REMOTE_INTERACTION_REQUEST, - ap_id, - profile, -}); - -const remoteInteractionSuccess = (ap_id: string, profile: string, url: string) => ({ - type: REMOTE_INTERACTION_SUCCESS, - ap_id, - profile, - url, -}); - -const remoteInteractionFail = (ap_id: string, profile: string, error: unknown) => ({ - type: REMOTE_INTERACTION_FAIL, - ap_id, - profile, - error, -}); + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).accounts.remoteInteraction(ap_id, profile).then((data) => data.url); type InteractionsAction = - ReturnType - | ReturnType + | ReturnType | ReturnType | ReturnType - | ReturnType | ReturnType | ReturnType | ReturnType | ReturnType | ReturnType | ReturnType - | ReturnType | ReturnType - | ReturnType | ReturnType | ReturnType - | ReturnType - | ReturnType - | ReturnType | ReturnType - | ReturnType - | ReturnType | ReturnType - | ReturnType - | ReturnType | ReturnType - | ReturnType - | ReturnType | ReturnType - | ReturnType - | ReturnType - | ReturnType - | ReturnType; export { REBLOG_REQUEST, - REBLOG_SUCCESS, REBLOG_FAIL, FAVOURITE_REQUEST, FAVOURITE_SUCCESS, FAVOURITE_FAIL, DISLIKE_REQUEST, - DISLIKE_SUCCESS, DISLIKE_FAIL, UNREBLOG_REQUEST, - UNREBLOG_SUCCESS, UNREBLOG_FAIL, UNFAVOURITE_REQUEST, UNFAVOURITE_SUCCESS, - UNFAVOURITE_FAIL, UNDISLIKE_REQUEST, - UNDISLIKE_SUCCESS, - UNDISLIKE_FAIL, - PIN_REQUEST, PIN_SUCCESS, - PIN_FAIL, - UNPIN_REQUEST, UNPIN_SUCCESS, - UNPIN_FAIL, - BOOKMARK_REQUEST, BOOKMARK_SUCCESS, - BOOKMARK_FAIL, - UNBOOKMARK_REQUEST, UNBOOKMARK_SUCCESS, - UNBOOKMARK_FAIL, - REMOTE_INTERACTION_REQUEST, - REMOTE_INTERACTION_SUCCESS, - REMOTE_INTERACTION_FAIL, reblog, unreblog, toggleReblog, diff --git a/packages/pl-fe/src/actions/lists.ts b/packages/pl-fe/src/actions/lists.ts index e93d04921..8a64992a6 100644 --- a/packages/pl-fe/src/actions/lists.ts +++ b/packages/pl-fe/src/actions/lists.ts @@ -9,13 +9,10 @@ import { importEntities } from './importer'; import type { Account, List, PaginatedResponse } from 'pl-api'; import type { AppDispatch, RootState } from 'pl-fe/store'; -const LIST_FETCH_REQUEST = 'LIST_FETCH_REQUEST' as const; const LIST_FETCH_SUCCESS = 'LIST_FETCH_SUCCESS' as const; const LIST_FETCH_FAIL = 'LIST_FETCH_FAIL' as const; -const LISTS_FETCH_REQUEST = 'LISTS_FETCH_REQUEST' as const; const LISTS_FETCH_SUCCESS = 'LISTS_FETCH_SUCCESS' as const; -const LISTS_FETCH_FAIL = 'LISTS_FETCH_FAIL' as const; const LIST_EDITOR_TITLE_CHANGE = 'LIST_EDITOR_TITLE_CHANGE' as const; const LIST_EDITOR_RESET = 'LIST_EDITOR_RESET' as const; @@ -29,9 +26,7 @@ const LIST_UPDATE_REQUEST = 'LIST_UPDATE_REQUEST' as const; const LIST_UPDATE_SUCCESS = 'LIST_UPDATE_SUCCESS' as const; const LIST_UPDATE_FAIL = 'LIST_UPDATE_FAIL' as const; -const LIST_DELETE_REQUEST = 'LIST_DELETE_REQUEST' as const; const LIST_DELETE_SUCCESS = 'LIST_DELETE_SUCCESS' as const; -const LIST_DELETE_FAIL = 'LIST_DELETE_FAIL' as const; const LIST_ACCOUNTS_FETCH_REQUEST = 'LIST_ACCOUNTS_FETCH_REQUEST' as const; const LIST_ACCOUNTS_FETCH_SUCCESS = 'LIST_ACCOUNTS_FETCH_SUCCESS' as const; @@ -41,13 +36,9 @@ const LIST_EDITOR_SUGGESTIONS_CHANGE = 'LIST_EDITOR_SUGGESTIONS_CHANGE' as const const LIST_EDITOR_SUGGESTIONS_READY = 'LIST_EDITOR_SUGGESTIONS_READY' as const; const LIST_EDITOR_SUGGESTIONS_CLEAR = 'LIST_EDITOR_SUGGESTIONS_CLEAR' as const; -const LIST_EDITOR_ADD_REQUEST = 'LIST_EDITOR_ADD_REQUEST' as const; const LIST_EDITOR_ADD_SUCCESS = 'LIST_EDITOR_ADD_SUCCESS' as const; -const LIST_EDITOR_ADD_FAIL = 'LIST_EDITOR_ADD_FAIL' as const; -const LIST_EDITOR_REMOVE_REQUEST = 'LIST_EDITOR_REMOVE_REQUEST' as const; const LIST_EDITOR_REMOVE_SUCCESS = 'LIST_EDITOR_REMOVE_SUCCESS' as const; -const LIST_EDITOR_REMOVE_FAIL = 'LIST_EDITOR_REMOVE_FAIL' as const; const LIST_ADDER_RESET = 'LIST_ADDER_RESET' as const; const LIST_ADDER_SETUP = 'LIST_ADDER_SETUP' as const; @@ -63,18 +54,11 @@ const fetchList = (listId: string) => (dispatch: AppDispatch, getState: () => Ro return; } - dispatch(fetchListRequest(listId)); - return getClient(getState()).lists.getList(listId) .then((data) => dispatch(fetchListSuccess(data))) .catch(err => dispatch(fetchListFail(listId, err))); }; -const fetchListRequest = (listId: string) => ({ - type: LIST_FETCH_REQUEST, - listId, -}); - const fetchListSuccess = (list: List) => ({ type: LIST_FETCH_SUCCESS, list, @@ -89,27 +73,15 @@ const fetchListFail = (listId: string, error: unknown) => ({ const fetchLists = () => (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; - dispatch(fetchListsRequest()); - return getClient(getState()).lists.getLists() - .then((data) => dispatch(fetchListsSuccess(data))) - .catch(err => dispatch(fetchListsFail(err))); + .then((data) => dispatch(fetchListsSuccess(data))); }; -const fetchListsRequest = () => ({ - type: LISTS_FETCH_REQUEST, -}); - const fetchListsSuccess = (lists: Array) => ({ type: LISTS_FETCH_SUCCESS, lists, }); -const fetchListsFail = (error: unknown) => ({ - type: LISTS_FETCH_FAIL, - error, -}); - const submitListEditor = (shouldReset?: boolean) => (dispatch: AppDispatch, getState: () => RootState) => { const listId = getState().listEditor.listId!; const title = getState().listEditor.title; @@ -208,29 +180,15 @@ const resetListEditor = () => ({ const deleteList = (listId: string) => (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; - dispatch(deleteListRequest(listId)); - return getClient(getState()).lists.deleteList(listId) - .then(() => dispatch(deleteListSuccess(listId))) - .catch(err => dispatch(deleteListFail(listId, err))); + .then(() => dispatch(deleteListSuccess(listId))); }; -const deleteListRequest = (listId: string) => ({ - type: LIST_DELETE_REQUEST, - listId, -}); - const deleteListSuccess = (listId: string) => ({ type: LIST_DELETE_SUCCESS, listId, }); -const deleteListFail = (listId: string, error: unknown) => ({ - type: LIST_DELETE_FAIL, - listId, - error, -}); - const fetchListAccounts = (listId: string) => (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; @@ -291,32 +249,16 @@ const addToListEditor = (accountId: string) => (dispatch: AppDispatch, getState: const addToList = (listId: string, accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; - dispatch(addToListRequest(listId, accountId)); - return getClient(getState()).lists.addListAccounts(listId, [accountId]) - .then(() => dispatch(addToListSuccess(listId, accountId))) - .catch(err => dispatch(addToListFail(listId, accountId, err))); + .then(() => dispatch(addToListSuccess(listId, accountId))); }; -const addToListRequest = (listId: string, accountId: string) => ({ - type: LIST_EDITOR_ADD_REQUEST, - listId, - accountId, -}); - const addToListSuccess = (listId: string, accountId: string) => ({ type: LIST_EDITOR_ADD_SUCCESS, listId, accountId, }); -const addToListFail = (listId: string, accountId: string, error: unknown) => ({ - type: LIST_EDITOR_ADD_FAIL, - listId, - accountId, - error, -}); - const removeFromListEditor = (accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { dispatch(removeFromList(getState().listEditor.listId!, accountId)); }; @@ -324,31 +266,16 @@ const removeFromListEditor = (accountId: string) => (dispatch: AppDispatch, getS const removeFromList = (listId: string, accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; - dispatch(removeFromListRequest(listId, accountId)); - return getClient(getState()).lists.deleteListAccounts(listId, [accountId]) - .then(() => dispatch(removeFromListSuccess(listId, accountId))) - .catch(err => dispatch(removeFromListFail(listId, accountId, err))); + .then(() => dispatch(removeFromListSuccess(listId, accountId))); }; -const removeFromListRequest = (listId: string, accountId: string) => ({ - type: LIST_EDITOR_REMOVE_REQUEST, - listId, - accountId, -}); - const removeFromListSuccess = (listId: string, accountId: string) => ({ type: LIST_EDITOR_REMOVE_SUCCESS, listId, accountId, }); -const removeFromListFail = (listId: string, accountId: string, error: unknown) => ({ - type: LIST_EDITOR_REMOVE_FAIL, - listId, - accountId, - error, -}); const resetListAdder = () => ({ type: LIST_ADDER_RESET, @@ -407,12 +334,9 @@ const removeFromListAdder = (listId: string) => (dispatch: AppDispatch, getState }; type ListsAction = - | ReturnType | ReturnType | ReturnType - | ReturnType | ReturnType - | ReturnType | ListEditorSetupAction | ReturnType | ReturnType @@ -422,21 +346,15 @@ type ListsAction = | ReturnType | ReturnType | ReturnType - | ReturnType | ReturnType - | ReturnType | ReturnType | ReturnType | ReturnType | ReturnType | ReturnType | ReturnType - | ReturnType | ReturnType - | ReturnType - | ReturnType | ReturnType - | ReturnType | ReturnType | ListAdderSetupAction | ReturnType @@ -444,12 +362,9 @@ type ListsAction = | ReturnType; 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, @@ -459,21 +374,15 @@ export { 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, diff --git a/packages/pl-fe/src/actions/markers.ts b/packages/pl-fe/src/actions/markers.ts index 4941ffa89..ce16d6a35 100644 --- a/packages/pl-fe/src/actions/markers.ts +++ b/packages/pl-fe/src/actions/markers.ts @@ -3,66 +3,35 @@ import { getClient } from '../api'; import type { Markers, SaveMarkersParams } from 'pl-api'; import type { AppDispatch, RootState } from 'pl-fe/store'; -const MARKER_FETCH_REQUEST = 'MARKER_FETCH_REQUEST' as const; const MARKER_FETCH_SUCCESS = 'MARKER_FETCH_SUCCESS' as const; -const MARKER_FETCH_FAIL = 'MARKER_FETCH_FAIL' as const; -const MARKER_SAVE_REQUEST = 'MARKER_SAVE_REQUEST' as const; const MARKER_SAVE_SUCCESS = 'MARKER_SAVE_SUCCESS' as const; -const MARKER_SAVE_FAIL = 'MARKER_SAVE_FAIL' as const; const fetchMarker = (timeline: Array) => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: MARKER_FETCH_REQUEST }); - return getClient(getState).timelines.getMarkers(timeline).then((marker) => { + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).timelines.getMarkers(timeline).then((marker) => { dispatch({ type: MARKER_FETCH_SUCCESS, marker }); - }).catch(error => { - dispatch({ type: MARKER_FETCH_FAIL, error }); }); - }; const saveMarker = (marker: SaveMarkersParams) => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: MARKER_SAVE_REQUEST, marker }); - return getClient(getState).timelines.saveMarkers(marker).then((marker) => { + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).timelines.saveMarkers(marker).then((marker) => { dispatch({ type: MARKER_SAVE_SUCCESS, marker }); - }).catch(error => { - dispatch({ type: MARKER_SAVE_FAIL, error }); }); - }; type MarkersAction = - | { - type: typeof MARKER_FETCH_REQUEST; - } | { type: typeof MARKER_FETCH_SUCCESS; marker: Markers; } - | { - type: typeof MARKER_FETCH_FAIL; - error: unknown; - } - | { - type: typeof MARKER_SAVE_REQUEST; - marker: SaveMarkersParams; - } | { type: typeof MARKER_SAVE_SUCCESS; marker: Markers; - } - | { - type: typeof MARKER_SAVE_FAIL; - error: unknown; - } + }; export { - MARKER_FETCH_REQUEST, MARKER_FETCH_SUCCESS, - MARKER_FETCH_FAIL, - MARKER_SAVE_REQUEST, MARKER_SAVE_SUCCESS, - MARKER_SAVE_FAIL, fetchMarker, saveMarker, type MarkersAction, diff --git a/packages/pl-fe/src/actions/me.ts b/packages/pl-fe/src/actions/me.ts index e33e44955..a90874cfc 100644 --- a/packages/pl-fe/src/actions/me.ts +++ b/packages/pl-fe/src/actions/me.ts @@ -13,14 +13,11 @@ import { FE_NAME } from './settings'; import type { CredentialAccount, UpdateCredentialsParams } from 'pl-api'; import type { AppDispatch, RootState } from 'pl-fe/store'; -const ME_FETCH_REQUEST = 'ME_FETCH_REQUEST' as const; const ME_FETCH_SUCCESS = 'ME_FETCH_SUCCESS' as const; const ME_FETCH_FAIL = 'ME_FETCH_FAIL' as const; const ME_FETCH_SKIP = 'ME_FETCH_SKIP' as const; -const ME_PATCH_REQUEST = 'ME_PATCH_REQUEST' as const; const ME_PATCH_SUCCESS = 'ME_PATCH_SUCCESS' as const; -const ME_PATCH_FAIL = 'ME_PATCH_FAIL' as const; const noOp = () => new Promise(f => f(undefined)); @@ -54,7 +51,6 @@ const fetchMe = () => return noOp(); } - dispatch(fetchMeRequest()); return dispatch(loadCredentials(token, accountUrl!)) .catch(error => dispatch(fetchMeFail(error))); }; @@ -81,22 +77,12 @@ const persistAuthAccount = (account: CredentialAccount, params: Record - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch(patchMeRequest()); - - return getClient(getState).settings.updateCredentials(params) + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).settings.updateCredentials(params) .then(response => { persistAuthAccount(response, params); dispatch(patchMeSuccess(response)); - }).catch(error => { - dispatch(patchMeFail(error)); - throw error; }); - }; - -const fetchMeRequest = () => ({ - type: ME_FETCH_REQUEST, -}); const fetchMeSuccess = (account: CredentialAccount) => { setSentryAccount(account); @@ -115,10 +101,6 @@ const fetchMeFail = (error: unknown) => ({ skipAlert: true, }); -const patchMeRequest = () => ({ - type: ME_PATCH_REQUEST, -}); - interface MePatchSuccessAction { type: typeof ME_PATCH_SUCCESS; me: CredentialAccount; @@ -133,29 +115,17 @@ const patchMeSuccess = (me: CredentialAccount) => }); }; -const patchMeFail = (error: unknown) => ({ - type: ME_PATCH_FAIL, - error, - skipAlert: true, -}); - type MeAction = - | ReturnType | ReturnType | ReturnType | MeFetchSkipAction - | ReturnType | MePatchSuccessAction - | ReturnType; export { - ME_FETCH_REQUEST, ME_FETCH_SUCCESS, ME_FETCH_FAIL, ME_FETCH_SKIP, - ME_PATCH_REQUEST, ME_PATCH_SUCCESS, - ME_PATCH_FAIL, fetchMe, patchMe, fetchMeSuccess, diff --git a/packages/pl-fe/src/actions/mfa.ts b/packages/pl-fe/src/actions/mfa.ts index 94f3d97b9..6cb33a273 100644 --- a/packages/pl-fe/src/actions/mfa.ts +++ b/packages/pl-fe/src/actions/mfa.ts @@ -3,117 +3,49 @@ import { getClient } from '../api'; import type { PlApiClient } from 'pl-api'; import type { AppDispatch, RootState } from 'pl-fe/store'; -const MFA_FETCH_REQUEST = 'MFA_FETCH_REQUEST' as const; const MFA_FETCH_SUCCESS = 'MFA_FETCH_SUCCESS' as const; -const MFA_FETCH_FAIL = 'MFA_FETCH_FAIL' as const; -const MFA_BACKUP_CODES_FETCH_REQUEST = 'MFA_BACKUP_CODES_FETCH_REQUEST' as const; -const MFA_BACKUP_CODES_FETCH_SUCCESS = 'MFA_BACKUP_CODES_FETCH_SUCCESS' as const; -const MFA_BACKUP_CODES_FETCH_FAIL = 'MFA_BACKUP_CODES_FETCH_FAIL' as const; - -const MFA_SETUP_REQUEST = 'MFA_SETUP_REQUEST' as const; -const MFA_SETUP_SUCCESS = 'MFA_SETUP_SUCCESS' as const; -const MFA_SETUP_FAIL = 'MFA_SETUP_FAIL' as const; - -const MFA_CONFIRM_REQUEST = 'MFA_CONFIRM_REQUEST' as const; const MFA_CONFIRM_SUCCESS = 'MFA_CONFIRM_SUCCESS' as const; -const MFA_CONFIRM_FAIL = 'MFA_CONFIRM_FAIL' as const; -const MFA_DISABLE_REQUEST = 'MFA_DISABLE_REQUEST' as const; const MFA_DISABLE_SUCCESS = 'MFA_DISABLE_SUCCESS' as const; -const MFA_DISABLE_FAIL = 'MFA_DISABLE_FAIL' as const; const fetchMfa = () => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: MFA_FETCH_REQUEST }); - return getClient(getState).settings.mfa.getMfaSettings().then((data) => { + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).settings.mfa.getMfaSettings().then((data) => { dispatch({ type: MFA_FETCH_SUCCESS, data }); - }).catch(() => { - dispatch({ type: MFA_FETCH_FAIL }); }); - }; const fetchBackupCodes = () => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: MFA_BACKUP_CODES_FETCH_REQUEST }); - return getClient(getState).settings.mfa.getMfaBackupCodes().then((data) => { - dispatch({ type: MFA_BACKUP_CODES_FETCH_SUCCESS, data }); - return data; - }).catch((error: unknown) => { - dispatch({ type: MFA_BACKUP_CODES_FETCH_FAIL }); - throw error; - }); - }; + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).settings.mfa.getMfaBackupCodes(); const setupMfa = (method: 'totp') => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: MFA_SETUP_REQUEST, method }); - return getClient(getState).settings.mfa.getMfaSetup(method).then((data) => { - dispatch({ type: MFA_SETUP_SUCCESS, data }); - return data; - }).catch((error: unknown) => { - dispatch({ type: MFA_SETUP_FAIL }); - throw error; - }); - }; + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).settings.mfa.getMfaSetup(method); const confirmMfa = (method: 'totp', code: string, password: string) => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: MFA_CONFIRM_REQUEST, method, code }); - return getClient(getState).settings.mfa.confirmMfaSetup(method, code, password).then((data) => { + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).settings.mfa.confirmMfaSetup(method, code, password).then((data) => { dispatch({ type: MFA_CONFIRM_SUCCESS, method, code }); return data; - }).catch((error: unknown) => { - dispatch({ type: MFA_CONFIRM_FAIL, method, code, error, skipAlert: true }); - throw error; }); - }; const disableMfa = (method: 'totp', password: string) => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: MFA_DISABLE_REQUEST, method }); - return getClient(getState).settings.mfa.disableMfa(method, password).then((data) => { + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).settings.mfa.disableMfa(method, password).then((data) => { dispatch({ type: MFA_DISABLE_SUCCESS, method }); return data; - }).catch((error: unknown) => { - dispatch({ type: MFA_DISABLE_FAIL, method, skipAlert: true }); - throw error; }); - }; type MfaAction = - | { type: typeof MFA_FETCH_REQUEST } | { type: typeof MFA_FETCH_SUCCESS; data: Awaited)['settings']['mfa']['getMfaSettings']>> } - | { type: typeof MFA_FETCH_FAIL } - | { type: typeof MFA_BACKUP_CODES_FETCH_REQUEST } - | { type: typeof MFA_BACKUP_CODES_FETCH_SUCCESS; data: Awaited)['settings']['mfa']['getMfaBackupCodes']>> } - | { type: typeof MFA_BACKUP_CODES_FETCH_FAIL } - | { type: typeof MFA_SETUP_REQUEST; method: 'totp' } - | { type: typeof MFA_SETUP_SUCCESS; data: Awaited)['settings']['mfa']['getMfaSetup']>> } - | { type: typeof MFA_SETUP_FAIL } - | { type: typeof MFA_CONFIRM_REQUEST; method: 'totp'; code: string } | { type: typeof MFA_CONFIRM_SUCCESS; method: 'totp'; code: string } - | { type: typeof MFA_CONFIRM_FAIL; method: 'totp'; code: string; error: unknown; skipAlert: true } - | { type: typeof MFA_DISABLE_REQUEST; method: 'totp' } | { type: typeof MFA_DISABLE_SUCCESS; method: 'totp' } - | { type: typeof MFA_DISABLE_FAIL; method: 'totp'; skipAlert: true }; export { - MFA_FETCH_REQUEST, MFA_FETCH_SUCCESS, - MFA_FETCH_FAIL, - MFA_BACKUP_CODES_FETCH_REQUEST, - MFA_BACKUP_CODES_FETCH_SUCCESS, - MFA_BACKUP_CODES_FETCH_FAIL, - MFA_SETUP_REQUEST, - MFA_SETUP_SUCCESS, - MFA_SETUP_FAIL, - MFA_CONFIRM_REQUEST, MFA_CONFIRM_SUCCESS, - MFA_CONFIRM_FAIL, - MFA_DISABLE_REQUEST, MFA_DISABLE_SUCCESS, - MFA_DISABLE_FAIL, fetchMfa, fetchBackupCodes, setupMfa, diff --git a/packages/pl-fe/src/actions/oauth.ts b/packages/pl-fe/src/actions/oauth.ts index 652716b62..70b6caf03 100644 --- a/packages/pl-fe/src/actions/oauth.ts +++ b/packages/pl-fe/src/actions/oauth.ts @@ -13,49 +13,20 @@ import { getBaseURL } from 'pl-fe/utils/state'; import type { AppDispatch, RootState } from 'pl-fe/store'; -const OAUTH_TOKEN_CREATE_REQUEST = 'OAUTH_TOKEN_CREATE_REQUEST' as const; -const OAUTH_TOKEN_CREATE_SUCCESS = 'OAUTH_TOKEN_CREATE_SUCCESS' as const; -const OAUTH_TOKEN_CREATE_FAIL = 'OAUTH_TOKEN_CREATE_FAIL' as const; +const obtainOAuthToken = (params: GetTokenParams, baseURL?: string) =>{ + const client = new PlApiClient(baseURL || BuildConfig.BACKEND_URL || ''); -const OAUTH_TOKEN_REVOKE_REQUEST = 'OAUTH_TOKEN_REVOKE_REQUEST' as const; -const OAUTH_TOKEN_REVOKE_SUCCESS = 'OAUTH_TOKEN_REVOKE_SUCCESS' as const; -const OAUTH_TOKEN_REVOKE_FAIL = 'OAUTH_TOKEN_REVOKE_FAIL' as const; - -const obtainOAuthToken = (params: GetTokenParams, baseURL?: string) => - (dispatch: AppDispatch) => { - dispatch({ type: OAUTH_TOKEN_CREATE_REQUEST, params }); - const client = new PlApiClient(baseURL || BuildConfig.BACKEND_URL || ''); - - return client.oauth.getToken(params).then((token) => { - dispatch({ type: OAUTH_TOKEN_CREATE_SUCCESS, params, token }); - return token; - }).catch(error => { - dispatch({ type: OAUTH_TOKEN_CREATE_FAIL, params, error, skipAlert: true }); - throw error; - }); - }; + return client.oauth.getToken(params); +}; const revokeOAuthToken = (params: RevokeTokenParams) => (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: OAUTH_TOKEN_REVOKE_REQUEST, params }); const baseURL = getBaseURL(getState()); const client = new PlApiClient(baseURL || ''); - return client.oauth.revokeToken(params).then((data) => { - dispatch({ type: OAUTH_TOKEN_REVOKE_SUCCESS, params, data }); - return data; - }).catch(error => { - dispatch({ type: OAUTH_TOKEN_REVOKE_FAIL, params, error }); - throw error; - }); + return client.oauth.revokeToken(params); }; export { - OAUTH_TOKEN_CREATE_REQUEST, - OAUTH_TOKEN_CREATE_SUCCESS, - OAUTH_TOKEN_CREATE_FAIL, - OAUTH_TOKEN_REVOKE_REQUEST, - OAUTH_TOKEN_REVOKE_SUCCESS, - OAUTH_TOKEN_REVOKE_FAIL, obtainOAuthToken, revokeOAuthToken, }; diff --git a/packages/pl-fe/src/actions/pl-fe.ts b/packages/pl-fe/src/actions/pl-fe.ts index 6df0cbea6..1072cd805 100644 --- a/packages/pl-fe/src/actions/pl-fe.ts +++ b/packages/pl-fe/src/actions/pl-fe.ts @@ -22,12 +22,11 @@ const getPlFeConfig = createSelector([ ], (plfe) => v.parse(plFeConfigSchema, plfe)); const rememberPlFeConfig = (host: string | null) => - (dispatch: AppDispatch) => { - return KVStore.getItemOrError(`plfe_config:${host}`).then(plFeConfig => { + (dispatch: AppDispatch) => + KVStore.getItemOrError(`plfe_config:${host}`).then(plFeConfig => { dispatch({ type: PLFE_CONFIG_REMEMBER_SUCCESS, host, plFeConfig }); return plFeConfig; }).catch(() => {}); - }; const fetchFrontendConfigurations = () => (dispatch: AppDispatch, getState: () => RootState) => diff --git a/packages/pl-fe/src/actions/scheduled-statuses.ts b/packages/pl-fe/src/actions/scheduled-statuses.ts index c0d27fe3a..e2473419c 100644 --- a/packages/pl-fe/src/actions/scheduled-statuses.ts +++ b/packages/pl-fe/src/actions/scheduled-statuses.ts @@ -13,7 +13,6 @@ const SCHEDULED_STATUSES_EXPAND_FAIL = 'SCHEDULED_STATUSES_EXPAND_FAIL' as const const SCHEDULED_STATUS_CANCEL_REQUEST = 'SCHEDULED_STATUS_CANCEL_REQUEST' as const; const SCHEDULED_STATUS_CANCEL_SUCCESS = 'SCHEDULED_STATUS_CANCEL_SUCCESS' as const; -const SCHEDULED_STATUS_CANCEL_FAIL = 'SCHEDULED_STATUS_CANCEL_FAIL' as const; const fetchScheduledStatuses = () => (dispatch: AppDispatch, getState: () => RootState) => { @@ -46,19 +45,11 @@ interface ScheduledStatusCancelSuccessAction { statusId: string; } -interface ScheduledStatusCancelFailAction { - type: typeof SCHEDULED_STATUS_CANCEL_FAIL; - statusId: string; - error: unknown; -} - const cancelScheduledStatus = (statusId: string) => (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: SCHEDULED_STATUS_CANCEL_REQUEST, statusId }); return getClient(getState()).scheduledStatuses.cancelScheduledStatus(statusId).then(() => { dispatch({ type: SCHEDULED_STATUS_CANCEL_SUCCESS, statusId }); - }).catch(error => { - dispatch({ type: SCHEDULED_STATUS_CANCEL_FAIL, statusId, error }); }); }; @@ -112,7 +103,6 @@ const expandScheduledStatusesFail = (error: unknown) => ({ type ScheduledStatusesAction = | ScheduledStatusCancelRequestAction | ScheduledStatusCancelSuccessAction - | ScheduledStatusCancelFailAction | ReturnType | ReturnType | ReturnType @@ -129,7 +119,6 @@ export { SCHEDULED_STATUSES_EXPAND_FAIL, SCHEDULED_STATUS_CANCEL_REQUEST, SCHEDULED_STATUS_CANCEL_SUCCESS, - SCHEDULED_STATUS_CANCEL_FAIL, fetchScheduledStatuses, cancelScheduledStatus, expandScheduledStatuses, diff --git a/packages/pl-fe/src/actions/security.ts b/packages/pl-fe/src/actions/security.ts index f8a6702a5..16f17e493 100644 --- a/packages/pl-fe/src/actions/security.ts +++ b/packages/pl-fe/src/actions/security.ts @@ -15,176 +15,62 @@ import type { OauthToken } from 'pl-api'; import type { Account } from 'pl-fe/normalizers/account'; import type { AppDispatch, RootState } from 'pl-fe/store'; -const FETCH_TOKENS_REQUEST = 'FETCH_TOKENS_REQUEST' as const; const FETCH_TOKENS_SUCCESS = 'FETCH_TOKENS_SUCCESS' as const; -const FETCH_TOKENS_FAIL = 'FETCH_TOKENS_FAIL' as const; -const REVOKE_TOKEN_REQUEST = 'REVOKE_TOKEN_REQUEST' as const; const REVOKE_TOKEN_SUCCESS = 'REVOKE_TOKEN_SUCCESS' as const; -const REVOKE_TOKEN_FAIL = 'REVOKE_TOKEN_FAIL' as const; - -const RESET_PASSWORD_REQUEST = 'RESET_PASSWORD_REQUEST' as const; -const RESET_PASSWORD_SUCCESS = 'RESET_PASSWORD_SUCCESS' as const; -const RESET_PASSWORD_FAIL = 'RESET_PASSWORD_FAIL' as const; - -const RESET_PASSWORD_CONFIRM_REQUEST = 'RESET_PASSWORD_CONFIRM_REQUEST' as const; -const RESET_PASSWORD_CONFIRM_SUCCESS = 'RESET_PASSWORD_CONFIRM_SUCCESS' as const; -const RESET_PASSWORD_CONFIRM_FAIL = 'RESET_PASSWORD_CONFIRM_FAIL' as const; - -const CHANGE_PASSWORD_REQUEST = 'CHANGE_PASSWORD_REQUEST' as const; -const CHANGE_PASSWORD_SUCCESS = 'CHANGE_PASSWORD_SUCCESS' as const; -const CHANGE_PASSWORD_FAIL = 'CHANGE_PASSWORD_FAIL' as const; - -const CHANGE_EMAIL_REQUEST = 'CHANGE_EMAIL_REQUEST' as const; -const CHANGE_EMAIL_SUCCESS = 'CHANGE_EMAIL_SUCCESS' as const; -const CHANGE_EMAIL_FAIL = 'CHANGE_EMAIL_FAIL' as const; - -const DELETE_ACCOUNT_REQUEST = 'DELETE_ACCOUNT_REQUEST' as const; -const DELETE_ACCOUNT_SUCCESS = 'DELETE_ACCOUNT_SUCCESS' as const; -const DELETE_ACCOUNT_FAIL = 'DELETE_ACCOUNT_FAIL' as const; - -const MOVE_ACCOUNT_REQUEST = 'MOVE_ACCOUNT_REQUEST' as const; -const MOVE_ACCOUNT_SUCCESS = 'MOVE_ACCOUNT_SUCCESS' as const; -const MOVE_ACCOUNT_FAIL = 'MOVE_ACCOUNT_FAIL' as const; const fetchOAuthTokens = () => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: FETCH_TOKENS_REQUEST }); - return getClient(getState).settings.getOauthTokens().then((tokens) => { + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).settings.getOauthTokens().then((tokens) => { dispatch({ type: FETCH_TOKENS_SUCCESS, tokens }); - }).catch((e) => { - dispatch({ type: FETCH_TOKENS_FAIL }); }); - }; const revokeOAuthTokenById = (tokenId: number) => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: REVOKE_TOKEN_REQUEST, tokenId }); - return getClient(getState).settings.deleteOauthToken(tokenId).then(() => { + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).settings.deleteOauthToken(tokenId).then(() => { dispatch({ type: REVOKE_TOKEN_SUCCESS, tokenId }); - }).catch(() => { - dispatch({ type: REVOKE_TOKEN_FAIL, tokenId }); }); - }; const changePassword = (oldPassword: string, newPassword: string) => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: CHANGE_PASSWORD_REQUEST }); - - return getClient(getState).settings.changePassword(oldPassword, newPassword).then(response => { - dispatch({ type: CHANGE_PASSWORD_SUCCESS, response }); - }).catch(error => { - dispatch({ type: CHANGE_PASSWORD_FAIL, error, skipAlert: true }); - throw error; - }); - }; + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).settings.changePassword(oldPassword, newPassword); const resetPassword = (usernameOrEmail: string) => (dispatch: AppDispatch, getState: () => RootState) => { const input = normalizeUsername(usernameOrEmail); - dispatch({ type: RESET_PASSWORD_REQUEST }); - return getClient(getState).settings.resetPassword( input.includes('@') ? input : undefined, input.includes('@') ? undefined : input, - ).then(() => { - dispatch({ type: RESET_PASSWORD_SUCCESS }); - }).catch(error => { - dispatch({ type: RESET_PASSWORD_FAIL, error }); - throw error; - }); + ); }; const changeEmail = (email: string, password: string) => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: CHANGE_EMAIL_REQUEST, email }); - - return getClient(getState).settings.changeEmail(email, password).then(response => { - dispatch({ type: CHANGE_EMAIL_SUCCESS, email, response }); - }).catch(error => { - dispatch({ type: CHANGE_EMAIL_FAIL, email, error, skipAlert: true }); - throw error; - }); - }; + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).settings.changeEmail(email, password); const deleteAccount = (password: string) => (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: CHANGE_PASSWORD_REQUEST }); const account = getLoggedInAccount(getState())!; - dispatch({ type: DELETE_ACCOUNT_REQUEST }); - return getClient(getState).settings.deleteAccount(password).then(response => { - dispatch({ type: DELETE_ACCOUNT_SUCCESS, response }); + return getClient(getState).settings.deleteAccount(password).then(() => { dispatch({ type: AUTH_LOGGED_OUT, account }); toast.success(messages.loggedOut); - }).catch(error => { - dispatch({ type: DELETE_ACCOUNT_FAIL, error, skipAlert: true }); - throw error; }); }; const moveAccount = (targetAccount: string, password: string) => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: MOVE_ACCOUNT_REQUEST }); - return getClient(getState).settings.moveAccount(targetAccount, password).then(response => { - dispatch({ type: MOVE_ACCOUNT_SUCCESS, response }); - }).catch(error => { - dispatch({ type: MOVE_ACCOUNT_FAIL, error, skipAlert: true }); - throw error; - }); - }; + (dispatch: AppDispatch, getState: () => RootState) => + getClient(getState).settings.moveAccount(targetAccount, password); type SecurityAction = - | { type: typeof FETCH_TOKENS_REQUEST } | { type: typeof FETCH_TOKENS_SUCCESS; tokens: Array } - | { type: typeof FETCH_TOKENS_FAIL } - | { type: typeof REVOKE_TOKEN_REQUEST; tokenId: number } | { type: typeof REVOKE_TOKEN_SUCCESS; tokenId: number } - | { type: typeof REVOKE_TOKEN_FAIL; tokenId: number } - | { type: typeof CHANGE_PASSWORD_REQUEST } - | { type: typeof CHANGE_PASSWORD_SUCCESS; response: {} } - | { type: typeof CHANGE_PASSWORD_FAIL; error: unknown; skipAlert: true } - | { type: typeof RESET_PASSWORD_REQUEST } - | { type: typeof RESET_PASSWORD_SUCCESS } - | { type: typeof RESET_PASSWORD_FAIL; error: unknown } - | { type: typeof CHANGE_EMAIL_REQUEST; email: string } - | { type: typeof CHANGE_EMAIL_SUCCESS; email: string; response: {} } - | { type: typeof CHANGE_EMAIL_FAIL; email: string; error: unknown; skipAlert: true } - | { type: typeof CHANGE_PASSWORD_REQUEST } - | { type: typeof DELETE_ACCOUNT_REQUEST } - | { type: typeof DELETE_ACCOUNT_SUCCESS; response: {} } | { type: typeof AUTH_LOGGED_OUT; account: Account } - | { type: typeof DELETE_ACCOUNT_FAIL; error: unknown; skipAlert: true } - | { type: typeof MOVE_ACCOUNT_REQUEST } - | { type: typeof MOVE_ACCOUNT_SUCCESS; response: {} } - | { type: typeof MOVE_ACCOUNT_FAIL; error: unknown; skipAlert: true } export { - FETCH_TOKENS_REQUEST, FETCH_TOKENS_SUCCESS, - FETCH_TOKENS_FAIL, - REVOKE_TOKEN_REQUEST, REVOKE_TOKEN_SUCCESS, - REVOKE_TOKEN_FAIL, - RESET_PASSWORD_REQUEST, - RESET_PASSWORD_SUCCESS, - RESET_PASSWORD_FAIL, - RESET_PASSWORD_CONFIRM_REQUEST, - RESET_PASSWORD_CONFIRM_SUCCESS, - RESET_PASSWORD_CONFIRM_FAIL, - CHANGE_PASSWORD_REQUEST, - CHANGE_PASSWORD_SUCCESS, - CHANGE_PASSWORD_FAIL, - CHANGE_EMAIL_REQUEST, - CHANGE_EMAIL_SUCCESS, - CHANGE_EMAIL_FAIL, - DELETE_ACCOUNT_REQUEST, - DELETE_ACCOUNT_SUCCESS, - DELETE_ACCOUNT_FAIL, - MOVE_ACCOUNT_REQUEST, - MOVE_ACCOUNT_SUCCESS, - MOVE_ACCOUNT_FAIL, fetchOAuthTokens, revokeOAuthTokenById, changePassword, diff --git a/packages/pl-fe/src/features/developers/apps/create.tsx b/packages/pl-fe/src/features/developers/apps/create.tsx index 3c18df142..9d98b515c 100644 --- a/packages/pl-fe/src/features/developers/apps/create.tsx +++ b/packages/pl-fe/src/features/developers/apps/create.tsx @@ -12,7 +12,6 @@ import Input from 'pl-fe/components/ui/input'; import Stack from 'pl-fe/components/ui/stack'; import Text from 'pl-fe/components/ui/text'; import Textarea from 'pl-fe/components/ui/textarea'; -import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch'; import { useOwnAccount } from 'pl-fe/hooks/use-own-account'; import { getBaseURL } from 'pl-fe/utils/accounts'; @@ -35,7 +34,6 @@ type Params = typeof BLANK_PARAMS; const CreateApp: React.FC = () => { const intl = useIntl(); - const dispatch = useAppDispatch(); const { account } = useOwnAccount(); const [app, setApp] = useState | null>(null); @@ -64,7 +62,7 @@ const CreateApp: React.FC = () => { scope: params.scopes, }; - return dispatch(obtainOAuthToken(tokenParams, baseURL)) + return obtainOAuthToken(tokenParams, baseURL) .then(setToken); }; diff --git a/packages/pl-fe/src/features/event/event-discussion.tsx b/packages/pl-fe/src/features/event/event-discussion.tsx index 2d95d0401..b84e55139 100644 --- a/packages/pl-fe/src/features/event/event-discussion.tsx +++ b/packages/pl-fe/src/features/event/event-discussion.tsx @@ -43,9 +43,7 @@ const EventDiscussion: React.FC = ({ params: { statusId: statu const node = useRef(null); - const fetchData = () => { - return dispatch(fetchStatusWithContext(statusId, intl)); - }; + const fetchData = () => dispatch(fetchStatusWithContext(statusId, intl)); useEffect(() => { fetchData().then(() => { diff --git a/packages/pl-fe/src/features/landing-timeline/index.tsx b/packages/pl-fe/src/features/landing-timeline/index.tsx index 25fc67af4..02a3a8c01 100644 --- a/packages/pl-fe/src/features/landing-timeline/index.tsx +++ b/packages/pl-fe/src/features/landing-timeline/index.tsx @@ -29,9 +29,7 @@ const LandingTimeline = () => { dispatch(fetchPublicTimeline({ local: true }, true)); }; - const handleRefresh = () => { - return dispatch(fetchPublicTimeline({ local: true })); - }; + const handleRefresh = () => dispatch(fetchPublicTimeline({ local: true })); useCommunityStream({ enabled: timelineEnabled });