Files
pixelstreamingv2/src/store/reducers/ActionCreator.ts
T
2023-03-07 15:59:17 +05:00

70 lines
1.8 KiB
TypeScript

import { createAsyncThunk } from "@reduxjs/toolkit";
import axios from 'axios';
const instance = axios.create({
baseURL: 'https://a1.coord.graff.tech',
});
instance.defaults.headers.post['Content-Type'] = 'application/json';
export const fetchCards = createAsyncThunk(
"cards/FetchAll",
async (language: string, thunkApi) => {
try {
const { data } = await instance.get('/title/get_for_language/', { params: { start: 0, count: 100, language: language } });
return data;
} catch (e: any) {
const { response } = e
if (!response) {
return thunkApi.rejectWithValue('Произошла ошибка, попробуйте позже');
} else {
return thunkApi.rejectWithValue(response.data.message);
}
}
}
);
export const createSession = createAsyncThunk(
"session/Create",
async (title: string, thunkApi) => {
try {
const { data } = await instance.post('/session/create', { title });
return data;
} catch (e: any) {
const { response } = e
if (!response) {
return thunkApi.rejectWithValue('Произошла ошибка, попробуйте позже');
} else {
return thunkApi.rejectWithValue(response.data.message);
}
}
}
);
export const connectSession = createAsyncThunk(
"session/Connect",
async (code: string, thunkApi) => {
try {
const { data } = await instance.get('/session/connect', { params: { session_id: code } });
return data;
} catch (e: any) {
const { response } = e
if (!response) {
return thunkApi.rejectWithValue('Произошла ошибка, попробуйте позже');
} else {
return thunkApi.rejectWithValue(response.data.message);
}
}
}
);