pl-fe: remove unused actions

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk 2024-12-05 14:00:01 +01:00
parent ea8c07676e
commit c41b613cca
16 changed files with 60 additions and 671 deletions

View file

@ -111,21 +111,19 @@ const approveUser = (accountId: string) =>
}; };
const deleteStatus = (statusId: string) => const deleteStatus = (statusId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
return getClient(getState).admin.statuses.deleteStatus(statusId) getClient(getState).admin.statuses.deleteStatus(statusId)
.then(() => { .then(() => {
dispatch(deleteFromTimelines(statusId)); dispatch(deleteFromTimelines(statusId));
return ({ statusId }); return ({ statusId });
}); });
};
const toggleStatusSensitivity = (statusId: string, sensitive: boolean) => const toggleStatusSensitivity = (statusId: string, sensitive: boolean) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
return getClient(getState).admin.statuses.updateStatus(statusId, { sensitive: !sensitive }) getClient(getState).admin.statuses.updateStatus(statusId, { sensitive: !sensitive })
.then((status) => { .then((status) => {
dispatch(importEntities({ statuses: [status] })); dispatch(importEntities({ statuses: [status] }));
}); });
};
const tagUser = (accountId: string, tags: string[]) => const tagUser = (accountId: string, tags: string[]) =>
(dispatch: AppDispatch, getState: () => RootState) => (dispatch: AppDispatch, getState: () => RootState) =>

View file

@ -118,7 +118,7 @@ const createAppToken = () =>
scope: getScopes(getState()), scope: getScopes(getState()),
}; };
return dispatch(obtainOAuthToken(params)).then((token) => return obtainOAuthToken(params).then((token) =>
dispatch<AuthAppAuthorizedAction>({ type: AUTH_APP_AUTHORIZED, app, token }), dispatch<AuthAppAuthorizedAction>({ type: AUTH_APP_AUTHORIZED, app, token }),
); );
}; };
@ -137,7 +137,7 @@ const createUserToken = (username: string, password: string) =>
scope: getScopes(getState()), scope: getScopes(getState()),
}; };
return dispatch(obtainOAuthToken(params)) return obtainOAuthToken(params)
.then((token) => dispatch(authLoggedIn(token))); .then((token) => dispatch(authLoggedIn(token)));
}; };
@ -212,14 +212,13 @@ interface AuthAccountRememberSuccessAction {
} }
const rememberAuthAccount = (accountUrl: string) => const rememberAuthAccount = (accountUrl: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
return KVStore.getItemOrError(`authAccount:${accountUrl}`).then(account => { KVStore.getItemOrError(`authAccount:${accountUrl}`).then(account => {
dispatch(importEntities({ accounts: [account] })); dispatch(importEntities({ accounts: [account] }));
dispatch<AuthAccountRememberSuccessAction>({ type: AUTH_ACCOUNT_REMEMBER_SUCCESS, account, accountUrl }); dispatch<AuthAccountRememberSuccessAction>({ type: AUTH_ACCOUNT_REMEMBER_SUCCESS, account, accountUrl });
if (account.id === getState().me) dispatch(fetchMeSuccess(account)); if (account.id === getState().me) dispatch(fetchMeSuccess(account));
return account; return account;
}); });
};
const loadCredentials = (token: string, accountUrl: string) => const loadCredentials = (token: string, accountUrl: string) =>
(dispatch: AppDispatch) => dispatch(rememberAuthAccount(accountUrl)) (dispatch: AppDispatch) => dispatch(rememberAuthAccount(accountUrl))

View file

@ -8,12 +8,9 @@ import type { Status } from 'pl-api';
import type { AppDispatch, RootState } from 'pl-fe/store'; import type { AppDispatch, RootState } from 'pl-fe/store';
const EMOJI_REACT_REQUEST = 'EMOJI_REACT_REQUEST' as const; 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 EMOJI_REACT_FAIL = 'EMOJI_REACT_FAIL' as const;
const UNEMOJI_REACT_REQUEST = 'UNEMOJI_REACT_REQUEST' 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)); const noOp = () => () => new Promise(f => f(undefined));
@ -25,7 +22,6 @@ const emojiReact = (status: Pick<Status, 'id'>, emoji: string, custom?: string)
return getClient(getState).statuses.createStatusReaction(status.id, emoji).then((response) => { return getClient(getState).statuses.createStatusReaction(status.id, emoji).then((response) => {
dispatch(importEntities({ statuses: [response] })); dispatch(importEntities({ statuses: [response] }));
dispatch(emojiReactSuccess(response, emoji));
}).catch((error) => { }).catch((error) => {
dispatch(emojiReactFail(status.id, emoji, error)); dispatch(emojiReactFail(status.id, emoji, error));
}); });
@ -39,9 +35,6 @@ const unEmojiReact = (status: Pick<Status, 'id'>, emoji: string) =>
return getClient(getState).statuses.deleteStatusReaction(status.id, emoji).then(response => { return getClient(getState).statuses.deleteStatusReaction(status.id, emoji).then(response => {
dispatch(importEntities({ statuses: [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, custom,
}); });
const emojiReactSuccess = (status: Status, emoji: string) => ({
type: EMOJI_REACT_SUCCESS,
status,
statusId: status.id,
emoji,
});
const emojiReactFail = (statusId: string, emoji: string, error: unknown) => ({ const emojiReactFail = (statusId: string, emoji: string, error: unknown) => ({
type: EMOJI_REACT_FAIL, type: EMOJI_REACT_FAIL,
statusId, statusId,
@ -72,35 +58,15 @@ const unEmojiReactRequest = (statusId: string, emoji: string) => ({
emoji, 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 = type EmojiReactsAction =
| ReturnType<typeof emojiReactRequest> | ReturnType<typeof emojiReactRequest>
| ReturnType<typeof emojiReactSuccess>
| ReturnType<typeof emojiReactFail> | ReturnType<typeof emojiReactFail>
| ReturnType<typeof unEmojiReactRequest> | ReturnType<typeof unEmojiReactRequest>
| ReturnType<typeof unEmojiReactSuccess>
| ReturnType<typeof unEmojiReactFail>
export { export {
EMOJI_REACT_REQUEST, EMOJI_REACT_REQUEST,
EMOJI_REACT_SUCCESS,
EMOJI_REACT_FAIL, EMOJI_REACT_FAIL,
UNEMOJI_REACT_REQUEST, UNEMOJI_REACT_REQUEST,
UNEMOJI_REACT_SUCCESS,
UNEMOJI_REACT_FAIL,
emojiReact, emojiReact,
unEmojiReact, unEmojiReact,
type EmojiReactsAction, type EmojiReactsAction,

View file

@ -88,7 +88,7 @@ const loginWithCode = (code: string) =>
code, code,
}; };
return dispatch(obtainOAuthToken(params, baseURL)) return obtainOAuthToken(params, baseURL)
.then((token) => dispatch(authLoggedIn(token))) .then((token) => dispatch(authLoggedIn(token)))
.then(({ access_token }) => dispatch(verifyCredentials(access_token, baseURL))) .then(({ access_token }) => dispatch(verifyCredentials(access_token, baseURL)))
.then((account) => dispatch(switchAccount(account.id))) .then((account) => dispatch(switchAccount(account.id)))

View file

@ -12,7 +12,6 @@ import type { Status } from 'pl-api';
import type { AppDispatch, RootState } from 'pl-fe/store'; import type { AppDispatch, RootState } from 'pl-fe/store';
const REBLOG_REQUEST = 'REBLOG_REQUEST' as const; const REBLOG_REQUEST = 'REBLOG_REQUEST' as const;
const REBLOG_SUCCESS = 'REBLOG_SUCCESS' as const;
const REBLOG_FAIL = 'REBLOG_FAIL' as const; const REBLOG_FAIL = 'REBLOG_FAIL' as const;
const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST' 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 FAVOURITE_FAIL = 'FAVOURITE_FAIL' as const;
const DISLIKE_REQUEST = 'DISLIKE_REQUEST' as const; const DISLIKE_REQUEST = 'DISLIKE_REQUEST' as const;
const DISLIKE_SUCCESS = 'DISLIKE_SUCCESS' as const;
const DISLIKE_FAIL = 'DISLIKE_FAIL' as const; const DISLIKE_FAIL = 'DISLIKE_FAIL' as const;
const UNREBLOG_REQUEST = 'UNREBLOG_REQUEST' as const; const UNREBLOG_REQUEST = 'UNREBLOG_REQUEST' as const;
const UNREBLOG_SUCCESS = 'UNREBLOG_SUCCESS' as const;
const UNREBLOG_FAIL = 'UNREBLOG_FAIL' as const; const UNREBLOG_FAIL = 'UNREBLOG_FAIL' as const;
const UNFAVOURITE_REQUEST = 'UNFAVOURITE_REQUEST' as const; const UNFAVOURITE_REQUEST = 'UNFAVOURITE_REQUEST' as const;
const UNFAVOURITE_SUCCESS = 'UNFAVOURITE_SUCCESS' 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_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_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_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_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_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)); const noOp = () => new Promise(f => f(undefined));
@ -75,7 +57,6 @@ const reblog = (status: Pick<Status, 'id'>) =>
// The reblog API method returns a new status wrapped around the original. In this case we are only // 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 // interested in how the original is modified, hence passing it skipping the wrapper
if (response.reblog) dispatch(importEntities({ statuses: [response.reblog] })); if (response.reblog) dispatch(importEntities({ statuses: [response.reblog] }));
dispatch(reblogSuccess(response));
}).catch(error => { }).catch(error => {
dispatch(reblogFail(status.id, error)); dispatch(reblogFail(status.id, error));
}); });
@ -87,9 +68,7 @@ const unreblog = (status: Pick<Status, 'id'>) =>
dispatch(unreblogRequest(status.id)); dispatch(unreblogRequest(status.id));
return getClient(getState()).statuses.unreblogStatus(status.id).then((status) => { return getClient(getState()).statuses.unreblogStatus(status.id).catch(error => {
dispatch(unreblogSuccess(status));
}).catch(error => {
dispatch(unreblogFail(status.id, error)); dispatch(unreblogFail(status.id, error));
}); });
}; };
@ -107,12 +86,6 @@ const reblogRequest = (statusId: string) => ({
statusId, statusId,
}); });
const reblogSuccess = (status: Status) => ({
type: REBLOG_SUCCESS,
status,
statusId: status.id,
});
const reblogFail = (statusId: string, error: unknown) => ({ const reblogFail = (statusId: string, error: unknown) => ({
type: REBLOG_FAIL, type: REBLOG_FAIL,
statusId, statusId,
@ -124,12 +97,6 @@ const unreblogRequest = (statusId: string) => ({
statusId, statusId,
}); });
const unreblogSuccess = (status: Status) => ({
type: UNREBLOG_SUCCESS,
status,
statusId: status.id,
});
const unreblogFail = (statusId: string, error: unknown) => ({ const unreblogFail = (statusId: string, error: unknown) => ({
type: UNREBLOG_FAIL, type: UNREBLOG_FAIL,
statusId, statusId,
@ -157,8 +124,6 @@ const unfavourite = (status: Pick<Status, 'id'>) =>
return getClient(getState()).statuses.unfavouriteStatus(status.id).then((response) => { return getClient(getState()).statuses.unfavouriteStatus(status.id).then((response) => {
dispatch(unfavouriteSuccess(response)); dispatch(unfavouriteSuccess(response));
}).catch(error => {
dispatch(unfavouriteFail(status.id, error));
}); });
}; };
@ -198,21 +163,13 @@ const unfavouriteSuccess = (status: Status) => ({
statusId: status.id, statusId: status.id,
}); });
const unfavouriteFail = (statusId: string, error: unknown) => ({
type: UNFAVOURITE_FAIL,
statusId,
error,
});
const dislike = (status: Pick<Status, 'id'>) => const dislike = (status: Pick<Status, 'id'>) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return; if (!isLoggedIn(getState)) return;
dispatch(dislikeRequest(status.id)); dispatch(dislikeRequest(status.id));
return getClient(getState).statuses.dislikeStatus(status.id).then((response) => { return getClient(getState).statuses.dislikeStatus(status.id).catch((error) => {
dispatch(dislikeSuccess(response));
}).catch((error) => {
dispatch(dislikeFail(status.id, error)); dispatch(dislikeFail(status.id, error));
}); });
}; };
@ -223,11 +180,7 @@ const undislike = (status: Pick<Status, 'id'>) =>
dispatch(undislikeRequest(status.id)); dispatch(undislikeRequest(status.id));
return getClient(getState).statuses.undislikeStatus(status.id).then((response) => { return getClient(getState).statuses.undislikeStatus(status.id);
dispatch(undislikeSuccess(response));
}).catch(error => {
dispatch(undislikeFail(status.id, error));
});
}; };
const toggleDislike = (status: Pick<Status, 'id' | 'disliked'>) => const toggleDislike = (status: Pick<Status, 'id' | 'disliked'>) =>
@ -244,12 +197,6 @@ const dislikeRequest = (statusId: string) => ({
statusId, statusId,
}); });
const dislikeSuccess = (status: Status) => ({
type: DISLIKE_SUCCESS,
status,
statusId: status.id,
});
const dislikeFail = (statusId: string, error: unknown) => ({ const dislikeFail = (statusId: string, error: unknown) => ({
type: DISLIKE_FAIL, type: DISLIKE_FAIL,
statusId, statusId,
@ -261,26 +208,12 @@ const undislikeRequest = (statusId: string) => ({
statusId, 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<Status, 'id'>, folderId?: string) => const bookmark = (status: Pick<Status, 'id'>, folderId?: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const state = getState(); const state = getState();
const features = state.auth.client.features; const features = state.auth.client.features;
dispatch(bookmarkRequest(status.id));
return getClient(getState()).statuses.bookmarkStatus(status.id, folderId).then((response) => { return getClient(getState()).statuses.bookmarkStatus(status.id, folderId).then((response) => {
dispatch(importEntities({ statuses: [response] })); dispatch(importEntities({ statuses: [response] }));
dispatch(bookmarkSuccess(response)); dispatch(bookmarkSuccess(response));
@ -300,23 +233,16 @@ const bookmark = (status: Pick<Status, 'id'>, folderId?: string) =>
} }
toast.success(typeof folderId === 'string' ? messages.folderChanged : messages.bookmarkAdded, opts); toast.success(typeof folderId === 'string' ? messages.folderChanged : messages.bookmarkAdded, opts);
}).catch((error) => {
dispatch(bookmarkFail(status.id, error));
}); });
}; };
const unbookmark = (status: Pick<Status, 'id'>) => const unbookmark = (status: Pick<Status, 'id'>) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch(unbookmarkRequest(status.id)); getClient(getState).statuses.unbookmarkStatus(status.id).then(response => {
return getClient(getState()).statuses.unbookmarkStatus(status.id).then(response => {
dispatch(importEntities({ statuses: [response] })); dispatch(importEntities({ statuses: [response] }));
dispatch(unbookmarkSuccess(response)); dispatch(unbookmarkSuccess(response));
toast.success(messages.bookmarkRemoved); toast.success(messages.bookmarkRemoved);
}).catch(error => {
dispatch(unbookmarkFail(status.id, error));
}); });
};
const toggleBookmark = (status: Pick<Status, 'id' | 'bookmarked'>) => const toggleBookmark = (status: Pick<Status, 'id' | 'bookmarked'>) =>
(dispatch: AppDispatch) => { (dispatch: AppDispatch) => {
@ -327,60 +253,29 @@ const toggleBookmark = (status: Pick<Status, 'id' | 'bookmarked'>) =>
} }
}; };
const bookmarkRequest = (statusId: string) => ({
type: BOOKMARK_REQUEST,
statusId,
});
const bookmarkSuccess = (status: Status) => ({ const bookmarkSuccess = (status: Status) => ({
type: BOOKMARK_SUCCESS, type: BOOKMARK_SUCCESS,
status, status,
statusId: status.id, 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) => ({ const unbookmarkSuccess = (status: Status) => ({
type: UNBOOKMARK_SUCCESS, type: UNBOOKMARK_SUCCESS,
status, status,
statusId: status.id, statusId: status.id,
}); });
const unbookmarkFail = (statusId: string, error: unknown) => ({
type: UNBOOKMARK_FAIL,
statusId,
error,
});
const pin = (status: Pick<Status, 'id'>, accountId: string) => const pin = (status: Pick<Status, 'id'>, accountId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return; if (!isLoggedIn(getState)) return;
dispatch(pinRequest(status.id, accountId));
return getClient(getState()).statuses.pinStatus(status.id).then(response => { return getClient(getState()).statuses.pinStatus(status.id).then(response => {
dispatch(importEntities({ statuses: [response] })); dispatch(importEntities({ statuses: [response] }));
dispatch(pinSuccess(response, accountId)); dispatch(pinSuccess(response, accountId));
}).catch(error => { }).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) => ({ const pinSuccess = (status: Status, accountId: string) => ({
type: PIN_SUCCESS, type: PIN_SUCCESS,
status, status,
@ -388,24 +283,13 @@ const pinSuccess = (status: Status, accountId: string) => ({
accountId, accountId,
}); });
const pinFail = (statusId: string, error: unknown, accountId: string) => ({
type: PIN_FAIL,
statusId,
error,
accountId,
});
const unpin = (status: Pick<Status, 'id'>, accountId: string) => const unpin = (status: Pick<Status, 'id'>, accountId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return; if (!isLoggedIn(getState)) return;
dispatch(unpinRequest(status.id, accountId));
return getClient(getState()).statuses.unpinStatus(status.id).then(response => { return getClient(getState()).statuses.unpinStatus(status.id).then(response => {
dispatch(importEntities({ statuses: [response] })); dispatch(importEntities({ statuses: [response] }));
dispatch(unpinSuccess(response, accountId)); dispatch(unpinSuccess(response, accountId));
}).catch(error => {
dispatch(unpinFail(status.id, error, accountId));
}); });
}; };
@ -422,12 +306,6 @@ const togglePin = (status: Pick<Status, 'id' | 'pinned'>) =>
} }
}; };
const unpinRequest = (statusId: string, accountId: string) => ({
type: UNPIN_REQUEST,
statusId,
accountId,
});
const unpinSuccess = (status: Status, accountId: string) => ({ const unpinSuccess = (status: Status, accountId: string) => ({
type: UNPIN_SUCCESS, type: UNPIN_SUCCESS,
status, status,
@ -435,116 +313,45 @@ const unpinSuccess = (status: Status, accountId: string) => ({
accountId, accountId,
}); });
const unpinFail = (statusId: string, error: unknown, accountId: string) => ({
type: UNPIN_FAIL,
statusId,
error,
accountId,
});
const remoteInteraction = (ap_id: string, profile: string) => const remoteInteraction = (ap_id: string, profile: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch(remoteInteractionRequest(ap_id, profile)); getClient(getState).accounts.remoteInteraction(ap_id, profile).then((data) => data.url);
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,
});
type InteractionsAction = type InteractionsAction =
ReturnType<typeof reblogRequest> | ReturnType<typeof reblogRequest>
| ReturnType<typeof reblogSuccess>
| ReturnType<typeof reblogFail> | ReturnType<typeof reblogFail>
| ReturnType<typeof unreblogRequest> | ReturnType<typeof unreblogRequest>
| ReturnType<typeof unreblogSuccess>
| ReturnType<typeof unreblogFail> | ReturnType<typeof unreblogFail>
| ReturnType<typeof favouriteRequest> | ReturnType<typeof favouriteRequest>
| ReturnType<typeof favouriteSuccess> | ReturnType<typeof favouriteSuccess>
| ReturnType<typeof favouriteFail> | ReturnType<typeof favouriteFail>
| ReturnType<typeof unfavouriteRequest> | ReturnType<typeof unfavouriteRequest>
| ReturnType<typeof unfavouriteSuccess> | ReturnType<typeof unfavouriteSuccess>
| ReturnType<typeof unfavouriteFail>
| ReturnType<typeof dislikeRequest> | ReturnType<typeof dislikeRequest>
| ReturnType<typeof dislikeSuccess>
| ReturnType<typeof dislikeFail> | ReturnType<typeof dislikeFail>
| ReturnType<typeof undislikeRequest> | ReturnType<typeof undislikeRequest>
| ReturnType<typeof undislikeSuccess>
| ReturnType<typeof undislikeFail>
| ReturnType<typeof bookmarkRequest>
| ReturnType<typeof bookmarkSuccess> | ReturnType<typeof bookmarkSuccess>
| ReturnType<typeof bookmarkFail>
| ReturnType<typeof unbookmarkRequest>
| ReturnType<typeof unbookmarkSuccess> | ReturnType<typeof unbookmarkSuccess>
| ReturnType<typeof unbookmarkFail>
| ReturnType<typeof pinRequest>
| ReturnType<typeof pinSuccess> | ReturnType<typeof pinSuccess>
| ReturnType<typeof pinFail>
| ReturnType<typeof unpinRequest>
| ReturnType<typeof unpinSuccess> | ReturnType<typeof unpinSuccess>
| ReturnType<typeof unpinFail>
| ReturnType<typeof remoteInteractionRequest>
| ReturnType<typeof remoteInteractionSuccess>
| ReturnType<typeof remoteInteractionFail>;
export { export {
REBLOG_REQUEST, REBLOG_REQUEST,
REBLOG_SUCCESS,
REBLOG_FAIL, REBLOG_FAIL,
FAVOURITE_REQUEST, FAVOURITE_REQUEST,
FAVOURITE_SUCCESS, FAVOURITE_SUCCESS,
FAVOURITE_FAIL, FAVOURITE_FAIL,
DISLIKE_REQUEST, DISLIKE_REQUEST,
DISLIKE_SUCCESS,
DISLIKE_FAIL, DISLIKE_FAIL,
UNREBLOG_REQUEST, UNREBLOG_REQUEST,
UNREBLOG_SUCCESS,
UNREBLOG_FAIL, UNREBLOG_FAIL,
UNFAVOURITE_REQUEST, UNFAVOURITE_REQUEST,
UNFAVOURITE_SUCCESS, UNFAVOURITE_SUCCESS,
UNFAVOURITE_FAIL,
UNDISLIKE_REQUEST, UNDISLIKE_REQUEST,
UNDISLIKE_SUCCESS,
UNDISLIKE_FAIL,
PIN_REQUEST,
PIN_SUCCESS, PIN_SUCCESS,
PIN_FAIL,
UNPIN_REQUEST,
UNPIN_SUCCESS, UNPIN_SUCCESS,
UNPIN_FAIL,
BOOKMARK_REQUEST,
BOOKMARK_SUCCESS, BOOKMARK_SUCCESS,
BOOKMARK_FAIL,
UNBOOKMARK_REQUEST,
UNBOOKMARK_SUCCESS, UNBOOKMARK_SUCCESS,
UNBOOKMARK_FAIL,
REMOTE_INTERACTION_REQUEST,
REMOTE_INTERACTION_SUCCESS,
REMOTE_INTERACTION_FAIL,
reblog, reblog,
unreblog, unreblog,
toggleReblog, toggleReblog,

View file

@ -9,13 +9,10 @@ import { importEntities } from './importer';
import type { Account, List, PaginatedResponse } from 'pl-api'; import type { Account, List, PaginatedResponse } from 'pl-api';
import type { AppDispatch, RootState } from 'pl-fe/store'; 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_SUCCESS = 'LIST_FETCH_SUCCESS' as const;
const LIST_FETCH_FAIL = 'LIST_FETCH_FAIL' 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_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_TITLE_CHANGE = 'LIST_EDITOR_TITLE_CHANGE' as const;
const LIST_EDITOR_RESET = 'LIST_EDITOR_RESET' 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_SUCCESS = 'LIST_UPDATE_SUCCESS' as const;
const LIST_UPDATE_FAIL = 'LIST_UPDATE_FAIL' 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_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_REQUEST = 'LIST_ACCOUNTS_FETCH_REQUEST' as const;
const LIST_ACCOUNTS_FETCH_SUCCESS = 'LIST_ACCOUNTS_FETCH_SUCCESS' 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_READY = 'LIST_EDITOR_SUGGESTIONS_READY' as const;
const LIST_EDITOR_SUGGESTIONS_CLEAR = 'LIST_EDITOR_SUGGESTIONS_CLEAR' 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_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_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_RESET = 'LIST_ADDER_RESET' as const;
const LIST_ADDER_SETUP = 'LIST_ADDER_SETUP' as const; const LIST_ADDER_SETUP = 'LIST_ADDER_SETUP' as const;
@ -63,18 +54,11 @@ const fetchList = (listId: string) => (dispatch: AppDispatch, getState: () => Ro
return; return;
} }
dispatch(fetchListRequest(listId));
return getClient(getState()).lists.getList(listId) return getClient(getState()).lists.getList(listId)
.then((data) => dispatch(fetchListSuccess(data))) .then((data) => dispatch(fetchListSuccess(data)))
.catch(err => dispatch(fetchListFail(listId, err))); .catch(err => dispatch(fetchListFail(listId, err)));
}; };
const fetchListRequest = (listId: string) => ({
type: LIST_FETCH_REQUEST,
listId,
});
const fetchListSuccess = (list: List) => ({ const fetchListSuccess = (list: List) => ({
type: LIST_FETCH_SUCCESS, type: LIST_FETCH_SUCCESS,
list, list,
@ -89,27 +73,15 @@ const fetchListFail = (listId: string, error: unknown) => ({
const fetchLists = () => (dispatch: AppDispatch, getState: () => RootState) => { const fetchLists = () => (dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return; if (!isLoggedIn(getState)) return;
dispatch(fetchListsRequest());
return getClient(getState()).lists.getLists() return getClient(getState()).lists.getLists()
.then((data) => dispatch(fetchListsSuccess(data))) .then((data) => dispatch(fetchListsSuccess(data)));
.catch(err => dispatch(fetchListsFail(err)));
}; };
const fetchListsRequest = () => ({
type: LISTS_FETCH_REQUEST,
});
const fetchListsSuccess = (lists: Array<List>) => ({ const fetchListsSuccess = (lists: Array<List>) => ({
type: LISTS_FETCH_SUCCESS, type: LISTS_FETCH_SUCCESS,
lists, lists,
}); });
const fetchListsFail = (error: unknown) => ({
type: LISTS_FETCH_FAIL,
error,
});
const submitListEditor = (shouldReset?: boolean) => (dispatch: AppDispatch, getState: () => RootState) => { const submitListEditor = (shouldReset?: boolean) => (dispatch: AppDispatch, getState: () => RootState) => {
const listId = getState().listEditor.listId!; const listId = getState().listEditor.listId!;
const title = getState().listEditor.title; const title = getState().listEditor.title;
@ -208,29 +180,15 @@ const resetListEditor = () => ({
const deleteList = (listId: string) => (dispatch: AppDispatch, getState: () => RootState) => { const deleteList = (listId: string) => (dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return; if (!isLoggedIn(getState)) return;
dispatch(deleteListRequest(listId));
return getClient(getState()).lists.deleteList(listId) return getClient(getState()).lists.deleteList(listId)
.then(() => dispatch(deleteListSuccess(listId))) .then(() => dispatch(deleteListSuccess(listId)));
.catch(err => dispatch(deleteListFail(listId, err)));
}; };
const deleteListRequest = (listId: string) => ({
type: LIST_DELETE_REQUEST,
listId,
});
const deleteListSuccess = (listId: string) => ({ const deleteListSuccess = (listId: string) => ({
type: LIST_DELETE_SUCCESS, type: LIST_DELETE_SUCCESS,
listId, listId,
}); });
const deleteListFail = (listId: string, error: unknown) => ({
type: LIST_DELETE_FAIL,
listId,
error,
});
const fetchListAccounts = (listId: string) => (dispatch: AppDispatch, getState: () => RootState) => { const fetchListAccounts = (listId: string) => (dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return; 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) => { const addToList = (listId: string, accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return; if (!isLoggedIn(getState)) return;
dispatch(addToListRequest(listId, accountId));
return getClient(getState()).lists.addListAccounts(listId, [accountId]) return getClient(getState()).lists.addListAccounts(listId, [accountId])
.then(() => dispatch(addToListSuccess(listId, accountId))) .then(() => dispatch(addToListSuccess(listId, accountId)));
.catch(err => dispatch(addToListFail(listId, accountId, err)));
}; };
const addToListRequest = (listId: string, accountId: string) => ({
type: LIST_EDITOR_ADD_REQUEST,
listId,
accountId,
});
const addToListSuccess = (listId: string, accountId: string) => ({ const addToListSuccess = (listId: string, accountId: string) => ({
type: LIST_EDITOR_ADD_SUCCESS, type: LIST_EDITOR_ADD_SUCCESS,
listId, listId,
accountId, 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) => { const removeFromListEditor = (accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => {
dispatch(removeFromList(getState().listEditor.listId!, accountId)); 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) => { const removeFromList = (listId: string, accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return; if (!isLoggedIn(getState)) return;
dispatch(removeFromListRequest(listId, accountId));
return getClient(getState()).lists.deleteListAccounts(listId, [accountId]) return getClient(getState()).lists.deleteListAccounts(listId, [accountId])
.then(() => dispatch(removeFromListSuccess(listId, accountId))) .then(() => dispatch(removeFromListSuccess(listId, accountId)));
.catch(err => dispatch(removeFromListFail(listId, accountId, err)));
}; };
const removeFromListRequest = (listId: string, accountId: string) => ({
type: LIST_EDITOR_REMOVE_REQUEST,
listId,
accountId,
});
const removeFromListSuccess = (listId: string, accountId: string) => ({ const removeFromListSuccess = (listId: string, accountId: string) => ({
type: LIST_EDITOR_REMOVE_SUCCESS, type: LIST_EDITOR_REMOVE_SUCCESS,
listId, listId,
accountId, accountId,
}); });
const removeFromListFail = (listId: string, accountId: string, error: unknown) => ({
type: LIST_EDITOR_REMOVE_FAIL,
listId,
accountId,
error,
});
const resetListAdder = () => ({ const resetListAdder = () => ({
type: LIST_ADDER_RESET, type: LIST_ADDER_RESET,
@ -407,12 +334,9 @@ const removeFromListAdder = (listId: string) => (dispatch: AppDispatch, getState
}; };
type ListsAction = type ListsAction =
| ReturnType<typeof fetchListRequest>
| ReturnType<typeof fetchListSuccess> | ReturnType<typeof fetchListSuccess>
| ReturnType<typeof fetchListFail> | ReturnType<typeof fetchListFail>
| ReturnType<typeof fetchListsRequest>
| ReturnType<typeof fetchListsSuccess> | ReturnType<typeof fetchListsSuccess>
| ReturnType<typeof fetchListsFail>
| ListEditorSetupAction | ListEditorSetupAction
| ReturnType<typeof changeListEditorTitle> | ReturnType<typeof changeListEditorTitle>
| ReturnType<typeof createListRequest> | ReturnType<typeof createListRequest>
@ -422,21 +346,15 @@ type ListsAction =
| ReturnType<typeof updateListSuccess> | ReturnType<typeof updateListSuccess>
| ReturnType<typeof updateListFail> | ReturnType<typeof updateListFail>
| ReturnType<typeof resetListEditor> | ReturnType<typeof resetListEditor>
| ReturnType<typeof deleteListRequest>
| ReturnType<typeof deleteListSuccess> | ReturnType<typeof deleteListSuccess>
| ReturnType<typeof deleteListFail>
| ReturnType<typeof fetchListAccountsRequest> | ReturnType<typeof fetchListAccountsRequest>
| ReturnType<typeof fetchListAccountsSuccess> | ReturnType<typeof fetchListAccountsSuccess>
| ReturnType<typeof fetchListAccountsFail> | ReturnType<typeof fetchListAccountsFail>
| ReturnType<typeof fetchListSuggestionsReady> | ReturnType<typeof fetchListSuggestionsReady>
| ReturnType<typeof clearListSuggestions> | ReturnType<typeof clearListSuggestions>
| ReturnType<typeof changeListSuggestions> | ReturnType<typeof changeListSuggestions>
| ReturnType<typeof addToListRequest>
| ReturnType<typeof addToListSuccess> | ReturnType<typeof addToListSuccess>
| ReturnType<typeof addToListFail>
| ReturnType<typeof removeFromListRequest>
| ReturnType<typeof removeFromListSuccess> | ReturnType<typeof removeFromListSuccess>
| ReturnType<typeof removeFromListFail>
| ReturnType<typeof resetListAdder> | ReturnType<typeof resetListAdder>
| ListAdderSetupAction | ListAdderSetupAction
| ReturnType<typeof fetchAccountListsRequest> | ReturnType<typeof fetchAccountListsRequest>
@ -444,12 +362,9 @@ type ListsAction =
| ReturnType<typeof fetchAccountListsFail>; | ReturnType<typeof fetchAccountListsFail>;
export { export {
LIST_FETCH_REQUEST,
LIST_FETCH_SUCCESS, LIST_FETCH_SUCCESS,
LIST_FETCH_FAIL, LIST_FETCH_FAIL,
LISTS_FETCH_REQUEST,
LISTS_FETCH_SUCCESS, LISTS_FETCH_SUCCESS,
LISTS_FETCH_FAIL,
LIST_EDITOR_TITLE_CHANGE, LIST_EDITOR_TITLE_CHANGE,
LIST_EDITOR_RESET, LIST_EDITOR_RESET,
LIST_EDITOR_SETUP, LIST_EDITOR_SETUP,
@ -459,21 +374,15 @@ export {
LIST_UPDATE_REQUEST, LIST_UPDATE_REQUEST,
LIST_UPDATE_SUCCESS, LIST_UPDATE_SUCCESS,
LIST_UPDATE_FAIL, LIST_UPDATE_FAIL,
LIST_DELETE_REQUEST,
LIST_DELETE_SUCCESS, LIST_DELETE_SUCCESS,
LIST_DELETE_FAIL,
LIST_ACCOUNTS_FETCH_REQUEST, LIST_ACCOUNTS_FETCH_REQUEST,
LIST_ACCOUNTS_FETCH_SUCCESS, LIST_ACCOUNTS_FETCH_SUCCESS,
LIST_ACCOUNTS_FETCH_FAIL, LIST_ACCOUNTS_FETCH_FAIL,
LIST_EDITOR_SUGGESTIONS_CHANGE, LIST_EDITOR_SUGGESTIONS_CHANGE,
LIST_EDITOR_SUGGESTIONS_READY, LIST_EDITOR_SUGGESTIONS_READY,
LIST_EDITOR_SUGGESTIONS_CLEAR, LIST_EDITOR_SUGGESTIONS_CLEAR,
LIST_EDITOR_ADD_REQUEST,
LIST_EDITOR_ADD_SUCCESS, LIST_EDITOR_ADD_SUCCESS,
LIST_EDITOR_ADD_FAIL,
LIST_EDITOR_REMOVE_REQUEST,
LIST_EDITOR_REMOVE_SUCCESS, LIST_EDITOR_REMOVE_SUCCESS,
LIST_EDITOR_REMOVE_FAIL,
LIST_ADDER_RESET, LIST_ADDER_RESET,
LIST_ADDER_SETUP, LIST_ADDER_SETUP,
LIST_ADDER_LISTS_FETCH_REQUEST, LIST_ADDER_LISTS_FETCH_REQUEST,

View file

@ -3,66 +3,35 @@ import { getClient } from '../api';
import type { Markers, SaveMarkersParams } from 'pl-api'; import type { Markers, SaveMarkersParams } from 'pl-api';
import type { AppDispatch, RootState } from 'pl-fe/store'; 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_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_SUCCESS = 'MARKER_SAVE_SUCCESS' as const;
const MARKER_SAVE_FAIL = 'MARKER_SAVE_FAIL' as const;
const fetchMarker = (timeline: Array<string>) => const fetchMarker = (timeline: Array<string>) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<MarkersAction>({ type: MARKER_FETCH_REQUEST }); getClient(getState).timelines.getMarkers(timeline).then((marker) => {
return getClient(getState).timelines.getMarkers(timeline).then((marker) => {
dispatch<MarkersAction>({ type: MARKER_FETCH_SUCCESS, marker }); dispatch<MarkersAction>({ type: MARKER_FETCH_SUCCESS, marker });
}).catch(error => {
dispatch<MarkersAction>({ type: MARKER_FETCH_FAIL, error });
}); });
};
const saveMarker = (marker: SaveMarkersParams) => const saveMarker = (marker: SaveMarkersParams) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<MarkersAction>({ type: MARKER_SAVE_REQUEST, marker }); getClient(getState).timelines.saveMarkers(marker).then((marker) => {
return getClient(getState).timelines.saveMarkers(marker).then((marker) => {
dispatch<MarkersAction>({ type: MARKER_SAVE_SUCCESS, marker }); dispatch<MarkersAction>({ type: MARKER_SAVE_SUCCESS, marker });
}).catch(error => {
dispatch<MarkersAction>({ type: MARKER_SAVE_FAIL, error });
}); });
};
type MarkersAction = type MarkersAction =
| {
type: typeof MARKER_FETCH_REQUEST;
}
| { | {
type: typeof MARKER_FETCH_SUCCESS; type: typeof MARKER_FETCH_SUCCESS;
marker: Markers; marker: Markers;
} }
| {
type: typeof MARKER_FETCH_FAIL;
error: unknown;
}
| {
type: typeof MARKER_SAVE_REQUEST;
marker: SaveMarkersParams;
}
| { | {
type: typeof MARKER_SAVE_SUCCESS; type: typeof MARKER_SAVE_SUCCESS;
marker: Markers; marker: Markers;
} };
| {
type: typeof MARKER_SAVE_FAIL;
error: unknown;
}
export { export {
MARKER_FETCH_REQUEST,
MARKER_FETCH_SUCCESS, MARKER_FETCH_SUCCESS,
MARKER_FETCH_FAIL,
MARKER_SAVE_REQUEST,
MARKER_SAVE_SUCCESS, MARKER_SAVE_SUCCESS,
MARKER_SAVE_FAIL,
fetchMarker, fetchMarker,
saveMarker, saveMarker,
type MarkersAction, type MarkersAction,

View file

@ -13,14 +13,11 @@ import { FE_NAME } from './settings';
import type { CredentialAccount, UpdateCredentialsParams } from 'pl-api'; import type { CredentialAccount, UpdateCredentialsParams } from 'pl-api';
import type { AppDispatch, RootState } from 'pl-fe/store'; 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_SUCCESS = 'ME_FETCH_SUCCESS' as const;
const ME_FETCH_FAIL = 'ME_FETCH_FAIL' as const; const ME_FETCH_FAIL = 'ME_FETCH_FAIL' as const;
const ME_FETCH_SKIP = 'ME_FETCH_SKIP' 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_SUCCESS = 'ME_PATCH_SUCCESS' as const;
const ME_PATCH_FAIL = 'ME_PATCH_FAIL' as const;
const noOp = () => new Promise(f => f(undefined)); const noOp = () => new Promise(f => f(undefined));
@ -54,7 +51,6 @@ const fetchMe = () =>
return noOp(); return noOp();
} }
dispatch(fetchMeRequest());
return dispatch(loadCredentials(token, accountUrl!)) return dispatch(loadCredentials(token, accountUrl!))
.catch(error => dispatch(fetchMeFail(error))); .catch(error => dispatch(fetchMeFail(error)));
}; };
@ -81,22 +77,12 @@ const persistAuthAccount = (account: CredentialAccount, params: Record<string, a
}; };
const patchMe = (params: UpdateCredentialsParams) => const patchMe = (params: UpdateCredentialsParams) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch(patchMeRequest()); getClient(getState).settings.updateCredentials(params)
return getClient(getState).settings.updateCredentials(params)
.then(response => { .then(response => {
persistAuthAccount(response, params); persistAuthAccount(response, params);
dispatch(patchMeSuccess(response)); dispatch(patchMeSuccess(response));
}).catch(error => {
dispatch(patchMeFail(error));
throw error;
}); });
};
const fetchMeRequest = () => ({
type: ME_FETCH_REQUEST,
});
const fetchMeSuccess = (account: CredentialAccount) => { const fetchMeSuccess = (account: CredentialAccount) => {
setSentryAccount(account); setSentryAccount(account);
@ -115,10 +101,6 @@ const fetchMeFail = (error: unknown) => ({
skipAlert: true, skipAlert: true,
}); });
const patchMeRequest = () => ({
type: ME_PATCH_REQUEST,
});
interface MePatchSuccessAction { interface MePatchSuccessAction {
type: typeof ME_PATCH_SUCCESS; type: typeof ME_PATCH_SUCCESS;
me: CredentialAccount; me: CredentialAccount;
@ -133,29 +115,17 @@ const patchMeSuccess = (me: CredentialAccount) =>
}); });
}; };
const patchMeFail = (error: unknown) => ({
type: ME_PATCH_FAIL,
error,
skipAlert: true,
});
type MeAction = type MeAction =
| ReturnType<typeof fetchMeRequest>
| ReturnType<typeof fetchMeSuccess> | ReturnType<typeof fetchMeSuccess>
| ReturnType<typeof fetchMeFail> | ReturnType<typeof fetchMeFail>
| MeFetchSkipAction | MeFetchSkipAction
| ReturnType<typeof patchMeRequest>
| MePatchSuccessAction | MePatchSuccessAction
| ReturnType<typeof patchMeFail>;
export { export {
ME_FETCH_REQUEST,
ME_FETCH_SUCCESS, ME_FETCH_SUCCESS,
ME_FETCH_FAIL, ME_FETCH_FAIL,
ME_FETCH_SKIP, ME_FETCH_SKIP,
ME_PATCH_REQUEST,
ME_PATCH_SUCCESS, ME_PATCH_SUCCESS,
ME_PATCH_FAIL,
fetchMe, fetchMe,
patchMe, patchMe,
fetchMeSuccess, fetchMeSuccess,

View file

@ -3,117 +3,49 @@ import { getClient } from '../api';
import type { PlApiClient } from 'pl-api'; import type { PlApiClient } from 'pl-api';
import type { AppDispatch, RootState } from 'pl-fe/store'; 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_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_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_SUCCESS = 'MFA_DISABLE_SUCCESS' as const;
const MFA_DISABLE_FAIL = 'MFA_DISABLE_FAIL' as const;
const fetchMfa = () => const fetchMfa = () =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<MfaAction>({ type: MFA_FETCH_REQUEST }); getClient(getState).settings.mfa.getMfaSettings().then((data) => {
return getClient(getState).settings.mfa.getMfaSettings().then((data) => {
dispatch<MfaAction>({ type: MFA_FETCH_SUCCESS, data }); dispatch<MfaAction>({ type: MFA_FETCH_SUCCESS, data });
}).catch(() => {
dispatch<MfaAction>({ type: MFA_FETCH_FAIL });
}); });
};
const fetchBackupCodes = () => const fetchBackupCodes = () =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<MfaAction>({ type: MFA_BACKUP_CODES_FETCH_REQUEST }); getClient(getState).settings.mfa.getMfaBackupCodes();
return getClient(getState).settings.mfa.getMfaBackupCodes().then((data) => {
dispatch<MfaAction>({ type: MFA_BACKUP_CODES_FETCH_SUCCESS, data });
return data;
}).catch((error: unknown) => {
dispatch<MfaAction>({ type: MFA_BACKUP_CODES_FETCH_FAIL });
throw error;
});
};
const setupMfa = (method: 'totp') => const setupMfa = (method: 'totp') =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<MfaAction>({ type: MFA_SETUP_REQUEST, method }); getClient(getState).settings.mfa.getMfaSetup(method);
return getClient(getState).settings.mfa.getMfaSetup(method).then((data) => {
dispatch<MfaAction>({ type: MFA_SETUP_SUCCESS, data });
return data;
}).catch((error: unknown) => {
dispatch<MfaAction>({ type: MFA_SETUP_FAIL });
throw error;
});
};
const confirmMfa = (method: 'totp', code: string, password: string) => const confirmMfa = (method: 'totp', code: string, password: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<MfaAction>({ type: MFA_CONFIRM_REQUEST, method, code }); getClient(getState).settings.mfa.confirmMfaSetup(method, code, password).then((data) => {
return getClient(getState).settings.mfa.confirmMfaSetup(method, code, password).then((data) => {
dispatch<MfaAction>({ type: MFA_CONFIRM_SUCCESS, method, code }); dispatch<MfaAction>({ type: MFA_CONFIRM_SUCCESS, method, code });
return data; return data;
}).catch((error: unknown) => {
dispatch<MfaAction>({ type: MFA_CONFIRM_FAIL, method, code, error, skipAlert: true });
throw error;
}); });
};
const disableMfa = (method: 'totp', password: string) => const disableMfa = (method: 'totp', password: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<MfaAction>({ type: MFA_DISABLE_REQUEST, method }); getClient(getState).settings.mfa.disableMfa(method, password).then((data) => {
return getClient(getState).settings.mfa.disableMfa(method, password).then((data) => {
dispatch<MfaAction>({ type: MFA_DISABLE_SUCCESS, method }); dispatch<MfaAction>({ type: MFA_DISABLE_SUCCESS, method });
return data; return data;
}).catch((error: unknown) => {
dispatch<MfaAction>({ type: MFA_DISABLE_FAIL, method, skipAlert: true });
throw error;
}); });
};
type MfaAction = type MfaAction =
| { type: typeof MFA_FETCH_REQUEST }
| { type: typeof MFA_FETCH_SUCCESS; data: Awaited<ReturnType<(InstanceType<typeof PlApiClient>)['settings']['mfa']['getMfaSettings']>> } | { type: typeof MFA_FETCH_SUCCESS; data: Awaited<ReturnType<(InstanceType<typeof PlApiClient>)['settings']['mfa']['getMfaSettings']>> }
| { type: typeof MFA_FETCH_FAIL }
| { type: typeof MFA_BACKUP_CODES_FETCH_REQUEST }
| { type: typeof MFA_BACKUP_CODES_FETCH_SUCCESS; data: Awaited<ReturnType<(InstanceType<typeof PlApiClient>)['settings']['mfa']['getMfaBackupCodes']>> }
| { type: typeof MFA_BACKUP_CODES_FETCH_FAIL }
| { type: typeof MFA_SETUP_REQUEST; method: 'totp' }
| { type: typeof MFA_SETUP_SUCCESS; data: Awaited<ReturnType<(InstanceType<typeof PlApiClient>)['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_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_SUCCESS; method: 'totp' }
| { type: typeof MFA_DISABLE_FAIL; method: 'totp'; skipAlert: true };
export { export {
MFA_FETCH_REQUEST,
MFA_FETCH_SUCCESS, 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_SUCCESS,
MFA_CONFIRM_FAIL,
MFA_DISABLE_REQUEST,
MFA_DISABLE_SUCCESS, MFA_DISABLE_SUCCESS,
MFA_DISABLE_FAIL,
fetchMfa, fetchMfa,
fetchBackupCodes, fetchBackupCodes,
setupMfa, setupMfa,

View file

@ -13,49 +13,20 @@ import { getBaseURL } from 'pl-fe/utils/state';
import type { AppDispatch, RootState } from 'pl-fe/store'; import type { AppDispatch, RootState } from 'pl-fe/store';
const OAUTH_TOKEN_CREATE_REQUEST = 'OAUTH_TOKEN_CREATE_REQUEST' as const; const obtainOAuthToken = (params: GetTokenParams, baseURL?: string) =>{
const OAUTH_TOKEN_CREATE_SUCCESS = 'OAUTH_TOKEN_CREATE_SUCCESS' as const; const client = new PlApiClient(baseURL || BuildConfig.BACKEND_URL || '');
const OAUTH_TOKEN_CREATE_FAIL = 'OAUTH_TOKEN_CREATE_FAIL' as const;
const OAUTH_TOKEN_REVOKE_REQUEST = 'OAUTH_TOKEN_REVOKE_REQUEST' as const; return client.oauth.getToken(params);
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;
});
};
const revokeOAuthToken = (params: RevokeTokenParams) => const revokeOAuthToken = (params: RevokeTokenParams) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: OAUTH_TOKEN_REVOKE_REQUEST, params });
const baseURL = getBaseURL(getState()); const baseURL = getBaseURL(getState());
const client = new PlApiClient(baseURL || ''); const client = new PlApiClient(baseURL || '');
return client.oauth.revokeToken(params).then((data) => { return client.oauth.revokeToken(params);
dispatch({ type: OAUTH_TOKEN_REVOKE_SUCCESS, params, data });
return data;
}).catch(error => {
dispatch({ type: OAUTH_TOKEN_REVOKE_FAIL, params, error });
throw error;
});
}; };
export { 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, obtainOAuthToken,
revokeOAuthToken, revokeOAuthToken,
}; };

View file

@ -22,12 +22,11 @@ const getPlFeConfig = createSelector([
], (plfe) => v.parse(plFeConfigSchema, plfe)); ], (plfe) => v.parse(plFeConfigSchema, plfe));
const rememberPlFeConfig = (host: string | null) => const rememberPlFeConfig = (host: string | null) =>
(dispatch: AppDispatch) => { (dispatch: AppDispatch) =>
return KVStore.getItemOrError(`plfe_config:${host}`).then(plFeConfig => { KVStore.getItemOrError(`plfe_config:${host}`).then(plFeConfig => {
dispatch({ type: PLFE_CONFIG_REMEMBER_SUCCESS, host, plFeConfig }); dispatch({ type: PLFE_CONFIG_REMEMBER_SUCCESS, host, plFeConfig });
return plFeConfig; return plFeConfig;
}).catch(() => {}); }).catch(() => {});
};
const fetchFrontendConfigurations = () => const fetchFrontendConfigurations = () =>
(dispatch: AppDispatch, getState: () => RootState) => (dispatch: AppDispatch, getState: () => RootState) =>

View file

@ -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_REQUEST = 'SCHEDULED_STATUS_CANCEL_REQUEST' as const;
const SCHEDULED_STATUS_CANCEL_SUCCESS = 'SCHEDULED_STATUS_CANCEL_SUCCESS' 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 = () => const fetchScheduledStatuses = () =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
@ -46,19 +45,11 @@ interface ScheduledStatusCancelSuccessAction {
statusId: string; statusId: string;
} }
interface ScheduledStatusCancelFailAction {
type: typeof SCHEDULED_STATUS_CANCEL_FAIL;
statusId: string;
error: unknown;
}
const cancelScheduledStatus = (statusId: string) => const cancelScheduledStatus = (statusId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
dispatch<ScheduledStatusCancelRequestAction>({ type: SCHEDULED_STATUS_CANCEL_REQUEST, statusId }); dispatch<ScheduledStatusCancelRequestAction>({ type: SCHEDULED_STATUS_CANCEL_REQUEST, statusId });
return getClient(getState()).scheduledStatuses.cancelScheduledStatus(statusId).then(() => { return getClient(getState()).scheduledStatuses.cancelScheduledStatus(statusId).then(() => {
dispatch<ScheduledStatusCancelSuccessAction>({ type: SCHEDULED_STATUS_CANCEL_SUCCESS, statusId }); dispatch<ScheduledStatusCancelSuccessAction>({ type: SCHEDULED_STATUS_CANCEL_SUCCESS, statusId });
}).catch(error => {
dispatch<ScheduledStatusCancelFailAction>({ type: SCHEDULED_STATUS_CANCEL_FAIL, statusId, error });
}); });
}; };
@ -112,7 +103,6 @@ const expandScheduledStatusesFail = (error: unknown) => ({
type ScheduledStatusesAction = type ScheduledStatusesAction =
| ScheduledStatusCancelRequestAction | ScheduledStatusCancelRequestAction
| ScheduledStatusCancelSuccessAction | ScheduledStatusCancelSuccessAction
| ScheduledStatusCancelFailAction
| ReturnType<typeof fetchScheduledStatusesRequest> | ReturnType<typeof fetchScheduledStatusesRequest>
| ReturnType<typeof fetchScheduledStatusesSuccess> | ReturnType<typeof fetchScheduledStatusesSuccess>
| ReturnType<typeof fetchScheduledStatusesFail> | ReturnType<typeof fetchScheduledStatusesFail>
@ -129,7 +119,6 @@ export {
SCHEDULED_STATUSES_EXPAND_FAIL, SCHEDULED_STATUSES_EXPAND_FAIL,
SCHEDULED_STATUS_CANCEL_REQUEST, SCHEDULED_STATUS_CANCEL_REQUEST,
SCHEDULED_STATUS_CANCEL_SUCCESS, SCHEDULED_STATUS_CANCEL_SUCCESS,
SCHEDULED_STATUS_CANCEL_FAIL,
fetchScheduledStatuses, fetchScheduledStatuses,
cancelScheduledStatus, cancelScheduledStatus,
expandScheduledStatuses, expandScheduledStatuses,

View file

@ -15,176 +15,62 @@ import type { OauthToken } from 'pl-api';
import type { Account } from 'pl-fe/normalizers/account'; import type { Account } from 'pl-fe/normalizers/account';
import type { AppDispatch, RootState } from 'pl-fe/store'; 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_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_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 = () => const fetchOAuthTokens = () =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<SecurityAction>({ type: FETCH_TOKENS_REQUEST }); getClient(getState).settings.getOauthTokens().then((tokens) => {
return getClient(getState).settings.getOauthTokens().then((tokens) => {
dispatch<SecurityAction>({ type: FETCH_TOKENS_SUCCESS, tokens }); dispatch<SecurityAction>({ type: FETCH_TOKENS_SUCCESS, tokens });
}).catch((e) => {
dispatch<SecurityAction>({ type: FETCH_TOKENS_FAIL });
}); });
};
const revokeOAuthTokenById = (tokenId: number) => const revokeOAuthTokenById = (tokenId: number) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<SecurityAction>({ type: REVOKE_TOKEN_REQUEST, tokenId }); getClient(getState).settings.deleteOauthToken(tokenId).then(() => {
return getClient(getState).settings.deleteOauthToken(tokenId).then(() => {
dispatch<SecurityAction>({ type: REVOKE_TOKEN_SUCCESS, tokenId }); dispatch<SecurityAction>({ type: REVOKE_TOKEN_SUCCESS, tokenId });
}).catch(() => {
dispatch<SecurityAction>({ type: REVOKE_TOKEN_FAIL, tokenId });
}); });
};
const changePassword = (oldPassword: string, newPassword: string) => const changePassword = (oldPassword: string, newPassword: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<SecurityAction>({ type: CHANGE_PASSWORD_REQUEST }); getClient(getState).settings.changePassword(oldPassword, newPassword);
return getClient(getState).settings.changePassword(oldPassword, newPassword).then(response => {
dispatch<SecurityAction>({ type: CHANGE_PASSWORD_SUCCESS, response });
}).catch(error => {
dispatch<SecurityAction>({ type: CHANGE_PASSWORD_FAIL, error, skipAlert: true });
throw error;
});
};
const resetPassword = (usernameOrEmail: string) => const resetPassword = (usernameOrEmail: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const input = normalizeUsername(usernameOrEmail); const input = normalizeUsername(usernameOrEmail);
dispatch<SecurityAction>({ type: RESET_PASSWORD_REQUEST });
return getClient(getState).settings.resetPassword( return getClient(getState).settings.resetPassword(
input.includes('@') ? input : undefined, input.includes('@') ? input : undefined,
input.includes('@') ? undefined : input, input.includes('@') ? undefined : input,
).then(() => { );
dispatch<SecurityAction>({ type: RESET_PASSWORD_SUCCESS });
}).catch(error => {
dispatch<SecurityAction>({ type: RESET_PASSWORD_FAIL, error });
throw error;
});
}; };
const changeEmail = (email: string, password: string) => const changeEmail = (email: string, password: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<SecurityAction>({ type: CHANGE_EMAIL_REQUEST, email }); getClient(getState).settings.changeEmail(email, password);
return getClient(getState).settings.changeEmail(email, password).then(response => {
dispatch<SecurityAction>({ type: CHANGE_EMAIL_SUCCESS, email, response });
}).catch(error => {
dispatch<SecurityAction>({ type: CHANGE_EMAIL_FAIL, email, error, skipAlert: true });
throw error;
});
};
const deleteAccount = (password: string) => const deleteAccount = (password: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
dispatch<SecurityAction>({ type: CHANGE_PASSWORD_REQUEST });
const account = getLoggedInAccount(getState())!; const account = getLoggedInAccount(getState())!;
dispatch<SecurityAction>({ type: DELETE_ACCOUNT_REQUEST }); return getClient(getState).settings.deleteAccount(password).then(() => {
return getClient(getState).settings.deleteAccount(password).then(response => {
dispatch<SecurityAction>({ type: DELETE_ACCOUNT_SUCCESS, response });
dispatch<SecurityAction>({ type: AUTH_LOGGED_OUT, account }); dispatch<SecurityAction>({ type: AUTH_LOGGED_OUT, account });
toast.success(messages.loggedOut); toast.success(messages.loggedOut);
}).catch(error => {
dispatch<SecurityAction>({ type: DELETE_ACCOUNT_FAIL, error, skipAlert: true });
throw error;
}); });
}; };
const moveAccount = (targetAccount: string, password: string) => const moveAccount = (targetAccount: string, password: string) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) =>
dispatch<SecurityAction>({ type: MOVE_ACCOUNT_REQUEST }); getClient(getState).settings.moveAccount(targetAccount, password);
return getClient(getState).settings.moveAccount(targetAccount, password).then(response => {
dispatch<SecurityAction>({ type: MOVE_ACCOUNT_SUCCESS, response });
}).catch(error => {
dispatch<SecurityAction>({ type: MOVE_ACCOUNT_FAIL, error, skipAlert: true });
throw error;
});
};
type SecurityAction = type SecurityAction =
| { type: typeof FETCH_TOKENS_REQUEST }
| { type: typeof FETCH_TOKENS_SUCCESS; tokens: Array<OauthToken> } | { type: typeof FETCH_TOKENS_SUCCESS; tokens: Array<OauthToken> }
| { type: typeof FETCH_TOKENS_FAIL }
| { type: typeof REVOKE_TOKEN_REQUEST; tokenId: number }
| { type: typeof REVOKE_TOKEN_SUCCESS; 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 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 { export {
FETCH_TOKENS_REQUEST,
FETCH_TOKENS_SUCCESS, FETCH_TOKENS_SUCCESS,
FETCH_TOKENS_FAIL,
REVOKE_TOKEN_REQUEST,
REVOKE_TOKEN_SUCCESS, 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, fetchOAuthTokens,
revokeOAuthTokenById, revokeOAuthTokenById,
changePassword, changePassword,

View file

@ -12,7 +12,6 @@ import Input from 'pl-fe/components/ui/input';
import Stack from 'pl-fe/components/ui/stack'; import Stack from 'pl-fe/components/ui/stack';
import Text from 'pl-fe/components/ui/text'; import Text from 'pl-fe/components/ui/text';
import Textarea from 'pl-fe/components/ui/textarea'; 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 { useOwnAccount } from 'pl-fe/hooks/use-own-account';
import { getBaseURL } from 'pl-fe/utils/accounts'; import { getBaseURL } from 'pl-fe/utils/accounts';
@ -35,7 +34,6 @@ type Params = typeof BLANK_PARAMS;
const CreateApp: React.FC = () => { const CreateApp: React.FC = () => {
const intl = useIntl(); const intl = useIntl();
const dispatch = useAppDispatch();
const { account } = useOwnAccount(); const { account } = useOwnAccount();
const [app, setApp] = useState<Record<string, any> | null>(null); const [app, setApp] = useState<Record<string, any> | null>(null);
@ -64,7 +62,7 @@ const CreateApp: React.FC = () => {
scope: params.scopes, scope: params.scopes,
}; };
return dispatch(obtainOAuthToken(tokenParams, baseURL)) return obtainOAuthToken(tokenParams, baseURL)
.then(setToken); .then(setToken);
}; };

View file

@ -43,9 +43,7 @@ const EventDiscussion: React.FC<IEventDiscussion> = ({ params: { statusId: statu
const node = useRef<HTMLDivElement>(null); const node = useRef<HTMLDivElement>(null);
const fetchData = () => { const fetchData = () => dispatch(fetchStatusWithContext(statusId, intl));
return dispatch(fetchStatusWithContext(statusId, intl));
};
useEffect(() => { useEffect(() => {
fetchData().then(() => { fetchData().then(() => {

View file

@ -29,9 +29,7 @@ const LandingTimeline = () => {
dispatch(fetchPublicTimeline({ local: true }, true)); dispatch(fetchPublicTimeline({ local: true }, true));
}; };
const handleRefresh = () => { const handleRefresh = () => dispatch(fetchPublicTimeline({ local: true }));
return dispatch(fetchPublicTimeline({ local: true }));
};
useCommunityStream({ enabled: timelineEnabled }); useCommunityStream({ enabled: timelineEnabled });