use thunk to get targetName

This commit is contained in:
felinae98
2022-10-09 21:09:17 +08:00
parent af002ad3e5
commit 8db0ed3fe1
2 changed files with 21 additions and 16 deletions
@@ -1,15 +1,19 @@
import { RootState, store } from '../../app/store';
import { AppThunk } from '../../app/store';
import { baseUrl } from '../../utils/urls';
export default async function getTargetName(platformName: string, target: string) {
const url = `${baseUrl}target_name?platformName=${platformName}&target=${target}`;
const state = store.getState() as RootState;
const authToken = state.auth.token;
const res = await fetch(url, {
headers: {
Authorization: `Bearer ${authToken}`,
},
});
const resObj = await res.json();
return resObj.targetName as string;
}
// eslint-disable-next-line
export const getTargetName =
(platformName: string, target: string): AppThunk<Promise<string>> => async (_, getState) => {
const url = `${baseUrl}target_name?platformName=${platformName}&target=${target}`;
const state = getState();
const authToken = state.auth.token;
const res = await fetch(url, {
headers: {
Authorization: `Bearer ${authToken}`,
},
});
const resObj = await res.json();
return resObj.targetName as string;
};
export default getTargetName;