redux-thunk#ThunkAction TypeScript Examples
The following examples show how to use
redux-thunk#ThunkAction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: saveStats.ts From client with MIT License | 6 votes |
saveStats: ActionCreator<ThunkAction<
void,
AppState,
any,
Action
>> = form => async dispatch => {
dispatch({ type: SET_CHARACTER_LOADER, payload: true });
try {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/user/character/stats',
form
);
dispatch(getChars());
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_CHARACTER_LOADER, payload: false });
}
Example #2
Source File: buyVIP.ts From client with MIT License | 6 votes |
buyVIP: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
vipDays: number
) => async dispatch => {
dispatch({ type: SET_ACCOUNT_LOADER, payload: true });
try {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/user/account/vip',
{
vipDays
}
);
dispatch({ type: SET_ACCOUNT_INFO, payload: data.info });
dispatch({ type: SET_CREDITS, payload: data.credits });
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #3
Source File: changePassword.ts From client with MIT License | 6 votes |
changePassword: ActionCreator<ThunkAction<
void,
AppState,
any,
Action
>> = (form: Form) => async dispatch => {
dispatch({ type: SET_ACCOUNT_LOADER, payload: true });
try {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/user/account/password',
form
);
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #4
Source File: exchangeOnline.ts From client with MIT License | 6 votes |
exchangeOnline: ActionCreator<ThunkAction<
void,
AppState,
any,
Action
>> = () => async dispatch => {
dispatch({ type: SET_ACCOUNT_LOADER, payload: true });
try {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/user/account/online'
);
dispatch({ type: SET_ONLINE, payload: data.status });
dispatch({ type: SET_CREDITS, payload: data.credits });
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #5
Source File: getLogs.ts From client with MIT License | 6 votes |
getLogs: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
page,
perPage,
category
) => async dispatch => {
dispatch({ type: SET_ACCOUNT_LOADER, payload: true });
try {
const { data } = await axios.get(
process.env.REACT_APP_API_URI +
`/user/account/logs?page=${page}&perPage=${perPage}` +
(category ? `&category=${category}` : '')
);
dispatch({ type: SET_LOGS, payload: data });
} catch (error) {
notice(error);
}
dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #6
Source File: getOnline.ts From client with MIT License | 6 votes |
getLogs: ActionCreator<ThunkAction<
void,
AppState,
any,
Action
>> = () => async dispatch => {
dispatch({ type: SET_ACCOUNT_LOADER, payload: true });
try {
const { data } = await axios.get(
process.env.REACT_APP_API_URI + '/user/account/online'
);
dispatch({ type: SET_ONLINE, payload: data });
} catch (error) {
notice(error);
}
dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #7
Source File: getVIP.ts From client with MIT License | 6 votes |
getVIP: ActionCreator<ThunkAction<
void,
AppState,
any,
Action
>> = () => async dispatch => {
dispatch({ type: SET_ACCOUNT_LOADER, payload: true });
try {
const { data } = await axios.get(
process.env.REACT_APP_API_URI + '/user/account/vip'
);
dispatch({ type: SET_ACCOUNT_INFO, payload: data });
} catch (error) {
notice(error);
}
dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #8
Source File: updateConfig.ts From client with MIT License | 6 votes |
updateConfig: ActionCreator<ThunkAction<
Promise<any>,
AppState,
any,
Action
>> = (configName, updated) => async dispatch => {
dispatch({ type: SET_ADMIN_LOADER, payload: true });
try {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/admin/config',
{
configName,
updated
}
);
await dispatch(getConfig());
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_ADMIN_LOADER, payload: false });
}
Example #9
Source File: changeClass.ts From client with MIT License | 6 votes |
changeClass: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
name: string,
newClass: number
) => async dispatch => {
dispatch({ type: SET_CHARACTER_LOADER, payload: true });
try {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/user/character/class',
{ name, newClass }
);
dispatch(getChars());
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_CHARACTER_LOADER, payload: false });
}
Example #10
Source File: changeName.ts From client with MIT License | 6 votes |
changeName: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
name: string,
newName: string
) => async dispatch => {
dispatch({ type: SET_CHARACTER_LOADER, payload: true });
try {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/user/character/name',
{ name, newName }
);
dispatch(getChars());
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_CHARACTER_LOADER, payload: false });
}
Example #11
Source File: getChars.ts From client with MIT License | 6 votes |
getChars: ActionCreator<ThunkAction<
void,
AppState,
any,
Action
>> = () => async dispatch => {
dispatch({ type: SET_CHARACTER_LOADER, payload: true });
try {
const { data } = await axios.get(
process.env.REACT_APP_API_URI + '/user/character'
);
dispatch({ type: SET_CHARACTERS, payload: data });
} catch (error) {}
dispatch({ type: SET_CHARACTER_LOADER, payload: false });
}
Example #12
Source File: reset.ts From client with MIT License | 6 votes |
reset: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
name: string
) => async dispatch => {
dispatch({ type: SET_CHARACTER_LOADER, payload: true });
try {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/user/character/reset',
{ name }
);
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_CHARACTER_LOADER, payload: false });
}
Example #13
Source File: getTop5Guilds.ts From client with MIT License | 6 votes |
getCharacters: ActionCreator<ThunkAction<
Promise<any>,
AppState,
any,
Action
>> = () => async dispatch => {
try {
const { data } = await axios.get(
process.env.REACT_APP_API_URI + '/guilds?limit=5'
);
dispatch({
type: data ? GET_RANK_5GUILDS : GET_RANK_5GUILDS_FAILED,
payload: data
});
} catch (error) {
dispatch({
type: GET_RANK_5GUILDS_FAILED
});
}
}
Example #14
Source File: buyItem.ts From client with MIT License | 6 votes |
buyItem: ActionCreator<ThunkAction<
Promise<any>,
AppState,
any,
Action
>> = (itemId, page, total) => async dispatch => {
dispatch({ type: SET_MODAL_LOADER, payload: true });
try {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/user/extra/market',
{ itemId }
);
dispatch({ type: RESOURCES_UPDATE, payload: data.resources });
dispatch(getMarketItems(page, total));
dispatch(getLatest(page, total));
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_MODAL_LOADER, payload: false });
}
Example #15
Source File: deposit.ts From client with MIT License | 6 votes |
depositResources: ActionCreator<ThunkAction<
Promise<any>,
AppState,
any,
Action
>> = (resources?: Resource[]) => async dispatch => {
dispatch({ type: SET_EXTRA_LOADER, payload: true });
try {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/user/extra/resources/deposit',
{ deposits: resources }
);
const updated: any = {
...data.resources,
list: data.resources.resources
};
delete updated.resources;
dispatch({ type: WAREHOUSE_UPDATE, payload: data.items });
dispatch({ type: RESOURCES_UPDATE, payload: updated });
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_EXTRA_LOADER, payload: false });
}
Example #16
Source File: getMarketItems.ts From client with MIT License | 6 votes |
getMarketItems: ActionCreator<ThunkAction<
Promise<any>,
AppState,
any,
Action
>> = (page = 1, perPage = 20) => async dispatch => {
dispatch({ type: SET_EXTRA_LOADER, payload: true });
try {
const { data } = await axios.get(
process.env.REACT_APP_API_URI +
`/others/market?page=${page}&perPage=${perPage}`
);
dispatch({ type: SET_MARKET_ITEMS, payload: data });
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_EXTRA_LOADER, payload: false });
}
Example #17
Source File: moveItem.ts From client with MIT License | 6 votes |
moveItem: ActionCreator<ThunkAction<
Promise<any>,
AppState,
any,
Action
>> = ({ itemSlot, newSlot, from, to }) => async dispatch => {
dispatch({ type: SET_EXTRA_LOADER, payload: true });
try {
if (from !== to || (from === to && from !== 'storage')) {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/user/extra/storage/moveitem',
{
itemSlot,
newSlot,
from,
to
}
);
dispatch({ type: WAREHOUSE_UPDATE, payload: data.warehouse });
dispatch({ type: STORAGE_UPDATE, payload: data.storage });
}
} catch (error) {
notice(error);
}
dispatch({ type: SET_EXTRA_LOADER, payload: false });
}
Example #18
Source File: unlockWarehouse.ts From client with MIT License | 6 votes |
unlockWarehouse: ActionCreator<ThunkAction<
Promise<any>,
AppState,
any,
Action
>> = password => async dispatch => {
try {
dispatch({ type: WAREHOUSE_UNLOCK });
} catch (error) {
notice(error);
}
}
Example #19
Source File: withdraw.ts From client with MIT License | 6 votes |
depositResources: ActionCreator<ThunkAction<
Promise<any>,
AppState,
any,
Action
>> = (resources: Resource[]) => async dispatch => {
dispatch({ type: SET_EXTRA_LOADER, payload: true });
try {
const { data } = await axios.patch(
process.env.REACT_APP_API_URI + '/user/extra/resources/withdraw',
{ withdraws: resources }
);
const updated: any = {
...data.resources,
list: data.resources.resources
};
delete updated.resources;
dispatch({ type: WAREHOUSE_UPDATE, payload: data.items });
dispatch({ type: RESOURCES_UPDATE, payload: updated });
notice(data);
} catch (error) {
notice(error);
}
dispatch({ type: SET_EXTRA_LOADER, payload: false });
}
Example #20
Source File: login.ts From client with MIT License | 6 votes |
userLogin: ActionCreator<ThunkAction<
Promise<any>,
AppState,
any,
Action
>> = ({ username, password }, history) => async dispatch => {
dispatch({ type: SET_LOGIN_LOADER, payload: true });
try {
const { data } = await axios.post(
process.env.REACT_APP_API_URI + '/user/account/auth',
{ username, password }
);
localStorage.nyxToken = data.jwt_token;
axios.defaults.headers.common.nyxAuthToken = data.jwt_token;
dispatch({ type: LOGIN, payload: data });
notice(data);
if (!window.location.pathname.includes('/user/')) {
history.push('/user/account/logs');
}
} catch (error) {
dispatch({ type: LOGIN_FAILED });
notice(error);
}
dispatch({ type: SET_LOGIN_LOADER, payload: false });
}
Example #21
Source File: logout.ts From client with MIT License | 6 votes |
userLogout: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
history: any
) => dispatch => {
delete localStorage.nyxToken;
dispatch({
type: LOGOUT
});
history.push('/');
}
Example #22
Source File: verification.ts From client with MIT License | 6 votes |
userVerification: ActionCreator<ThunkAction<
Promise<any>,
AppState,
any,
Action
>> = () => async dispatch => {
try {
if (localStorage.nyxToken) {
const { data } = await axios.post(
process.env.REACT_APP_API_URI + '/user/account/verify'
);
dispatch({
type: LOGIN,
payload: data
});
} else {
dispatch({
type: LOGIN_FAILED
});
}
} catch (error) {
dispatch({
type: LOGOUT
});
dispatch({
type: LOGIN_FAILED
});
}
}
Example #23
Source File: ProtofileManagerActions.tsx From Protoman with MIT License | 6 votes |
export function buildProtofiles(
collectionName: string,
filepaths: string[],
rootPath?: string,
onFix?: () => void,
): ThunkAction<Promise<void>, AppState, unknown, AnyAction> {
return async (dispatch): Promise<void> => {
if (filepaths) {
dispatch({ type: BUILD_PROTOFILES, collectionName, filepaths });
try {
await Promise.all(filepaths.map(isReadable));
const ctx = await buildContext(filepaths, rootPath);
dispatch({ type: BUILD_PROTOFILES_SUCCESS, collectionName, ctx });
dispatch({ type: SET_PROTOFILES, collectionName, filepaths, rootPath });
} catch (err) {
dispatch({ type: BUILD_PROTOFILES_FAILURE, collectionName, err });
if (onFix) {
message.warn(
<BuildFailureWarning
collectionName={collectionName}
onFix={(): void => {
message.destroy();
onFix();
}}
/>,
5,
);
}
}
}
};
}
Example #24
Source File: FlowViewActions.ts From Protoman with MIT License | 6 votes |
export function sendRequest(
collectionName: string,
flowName: string,
builder: RequestBuilder,
env: Env,
ctx: ProtoCtx,
): ThunkAction<Promise<void>, AppState, unknown, AnyAction> {
return async (dispatch): Promise<void> => {
dispatch({ type: SEND_REQUEST, collectionName, flowName });
try {
const rd = await toRequestDescriptor(builder, env, ctx);
const response = await makeRequest(rd, ctx);
dispatch({ type: SET_RESPONSE, collectionName, flowName, response });
} catch (err) {
dispatch({ type: SET_REQUEST_ERROR, collectionName, flowName, err });
}
};
}
Example #25
Source File: status.ts From shadowsocks-electron with GNU General Public License v3.0 | 6 votes |
startClientAction =
(config: Config | undefined, settings: Settings, warningTitle: string, warningBody: string):
ThunkAction<void, RootState, unknown, AnyAction> => {
return (dispatch) => {
dispatch(setStatus('waiting', true));
MessageChannel.invoke('main', 'service:main', {
action: 'startClient',
params: {
config,
settings
}
}).then(rsp => {
dispatch(setStatus('waiting', false));
dispatch(getConnectionStatusAction());
if (rsp.code === 600 && rsp.result.isInUse) {
MessageChannel.invoke('main', 'service:desktop', {
action: 'openNotification',
params: {
title: warningTitle,
body: warningBody
}
});
}
});
}
}
Example #26
Source File: enqueueSnackbar.tsx From multisig-react with MIT License | 6 votes |
enqueueSnackbar = (
notification: Notification,
key?: string | number,
onClick?: () => void,
): ThunkAction<string | number, AppReduxState, undefined, AnyAction> => (dispatch: Dispatch) => {
key = notification.key || new Date().getTime() + Math.random()
const newNotification = {
...notification,
key,
options: {
...notification.options,
onClick,
// eslint-disable-next-line react/display-name
action: (actionKey) => (
<IconButton onClick={() => dispatch(closeSnackbarAction({ key: actionKey }))}>
<IconClose />
</IconButton>
),
},
}
dispatch(addSnackbar(newNotification))
return key
}
Example #27
Source File: config.ts From shadowsocks-electron with GNU General Public License v3.0 | 6 votes |
restoreConfigurationFromFile =
(info: { success: string, error: { [key: string]: string } }): ThunkAction<void, RootState, unknown, AnyAction> => {
return (dispatch) => {
MessageChannel.invoke('main', 'service:desktop', {
action: 'restoreConfigurationFromFile',
params: {}
})
.then((rsp) => {
if (rsp.code === 200) {
dispatch(enqueueSnackbar(info.success, { variant: "success" }));
dispatch(wipeConfig());
if (rsp.result.config?.length) {
rsp.result.config.forEach((conf: Config) => {
dispatch(addConfig(conf.id, conf))
});
}
if (rsp.result.settings) {
dispatch(overrideSetting(rsp.result.settings));
}
} else {
dispatch(enqueueSnackbar(info.error[rsp.code] ?? info.error.default, { variant: "warning" }));
}
});
}
}
Example #28
Source File: config.ts From shadowsocks-electron with GNU General Public License v3.0 | 6 votes |
updateSubscription = (id: string, url: string, info: { error: string, success: string }): ThunkAction<void, RootState, unknown, AnyAction> => {
return (dispatch) => {
dispatch(setStatus('waiting', true));
MessageChannel.invoke('main', 'service:main', {
action: 'parseClipboardText',
params: {
text: url,
type: 'subscription'
}
})
.then((rsp) => {
setTimeout(() => dispatch(setStatus('waiting', false)), 1e3);
if (rsp.code === 200) {
if (rsp.result?.result?.length) {
dispatch({
type: UPDATE_SUBSCRIPTION,
id: id,
config: {
name: rsp.result.name || 'new subscription',
servers: (rsp.result.result as Config[]).map(server => {
server.id = uuid();
return server;
}),
}
});
return dispatch(enqueueSnackbar(info.success, { variant: 'success' }));
}
}
dispatch(enqueueSnackbar(info.error, { variant: 'error' }));
});
}
}
Example #29
Source File: config.ts From shadowsocks-electron with GNU General Public License v3.0 | 6 votes |
parseClipboardText = (text: string | null, type: ClipboardParseType, info: { success: string, error: string }): ThunkAction<void, RootState, unknown, AnyAction> => {
return (dispatch) => {
dispatch(setStatus('waiting', true));
MessageChannel.invoke('main', 'service:main', {
action: 'parseClipboardText',
params: {
text,
type
}
})
.then((rsp) => {
setTimeout(() => dispatch(setStatus('waiting', false)), 1e3);
if (rsp.code === 200) {
if ((type === 'subscription')) {
if (rsp.result?.result?.length) {
dispatch(addSubscription(uuid(), rsp.result.url, {
name: rsp.result.name || 'new subscription',
servers: (rsp.result.result as Config[]).map(server => {
server.id = uuid();
return server;
}),
}))
return dispatch(enqueueSnackbar(info.success, { variant: 'success' }));
}
} else {
if (rsp.result?.length) {
dispatch(addConfig(uuid(), rsp.result[0]));
return dispatch(enqueueSnackbar(info.success, { variant: 'success' }));
}
}
}
return dispatch(enqueueSnackbar(info.error, { variant: 'error' }));
});
}
}