add privated fetch
This commit is contained in:
+49
-40
@@ -15,20 +15,15 @@ import { PlayerComponent } from "components/pages/Stream/components/PlayerCompon
|
||||
import { PlanComponent } from "components/pages/Plan/PlanComponent";
|
||||
|
||||
import { useAppDispatch, useAppSelector } from "hooks/redux";
|
||||
import { fetchCards } from "store/reducers/ActionCreator";
|
||||
import { fetchCards, fetchPrivateCards } from "store/reducers/ActionCreator";
|
||||
import { cardSlice } from "store/reducers/cardSlice";
|
||||
import { sessionSlice } from "store/reducers/sessionSlice";
|
||||
import { languageSlice } from "store/reducers/languageSlice";
|
||||
import { createSession } from "store/reducers/ActionCreator";
|
||||
|
||||
|
||||
import { ICards } from "models/ICards";
|
||||
import { closeStream, load as loadStream } from "utils/app";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const App: React.FC = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
const history = useHistory();
|
||||
@@ -36,58 +31,63 @@ const App: React.FC = () => {
|
||||
const { handleChangeLanguage } = languageSlice.actions;
|
||||
const { cleanErrors } = sessionSlice.actions;
|
||||
|
||||
|
||||
const { cards, currentCard, error } = useAppSelector((state) => state.cardReducer);
|
||||
const { cards, currentCard, error } = useAppSelector(
|
||||
(state) => state.cardReducer
|
||||
);
|
||||
const { currentLang } = useAppSelector((state) => state.languageReducer);
|
||||
const { isLoading } = useAppSelector((state) => state.sessionReducer);
|
||||
const query = useQuery()
|
||||
const query = useQuery();
|
||||
|
||||
const langQuery = query.get('lang')
|
||||
const langQuery = query.get("lang");
|
||||
|
||||
const langArray = ['en', 'ru']
|
||||
const langArray = ["en", "ru"];
|
||||
|
||||
const browserLanguage = window.navigator.language
|
||||
const browserLanguage = window.navigator.language;
|
||||
|
||||
const handleBrowserLanguage = () => {
|
||||
return langArray.includes(browserLanguage)
|
||||
}
|
||||
return langArray.includes(browserLanguage);
|
||||
};
|
||||
|
||||
const handleCookiesLanguage = () => {
|
||||
const language = cookies.get("i18next")
|
||||
return language
|
||||
}
|
||||
const language = cookies.get("i18next");
|
||||
return language;
|
||||
};
|
||||
useEffect(() => {
|
||||
if (langArray.includes(langQuery as string)) {
|
||||
dispatch(handleChangeLanguage(langQuery as string));
|
||||
return
|
||||
return;
|
||||
} else if (handleCookiesLanguage()) {
|
||||
const languageCookies = handleCookiesLanguage();
|
||||
dispatch(handleChangeLanguage(languageCookies as string));
|
||||
return;
|
||||
}
|
||||
else if (handleCookiesLanguage()) {
|
||||
const languageCookies = handleCookiesLanguage()
|
||||
dispatch(handleChangeLanguage(languageCookies as string))
|
||||
return
|
||||
}
|
||||
let isSupported = handleBrowserLanguage()
|
||||
dispatch(handleChangeLanguage(isSupported ? browserLanguage : 'en'));
|
||||
}, [])
|
||||
|
||||
let isSupported = handleBrowserLanguage();
|
||||
dispatch(handleChangeLanguage(isSupported ? browserLanguage : "en"));
|
||||
}, []);
|
||||
|
||||
const handleConnect = (title: string) => {
|
||||
dispatch(createSession(title)).unwrap().then((res) => {
|
||||
dispatch(createSession(title))
|
||||
.unwrap()
|
||||
.then((res) => {
|
||||
history.push(`/stream/${res.session_id}`);
|
||||
}).catch((res) => {
|
||||
})
|
||||
.catch((res) => {
|
||||
alert(res);
|
||||
history.push("/");
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (currentLang) {
|
||||
dispatch(fetchCards(currentLang))
|
||||
const key = new URLSearchParams(history.location.search).get("key");
|
||||
|
||||
if (key) {
|
||||
dispatch(fetchPrivateCards(key));
|
||||
} else {
|
||||
dispatch(fetchCards(currentLang));
|
||||
}
|
||||
}, [currentLang])
|
||||
|
||||
|
||||
}
|
||||
}, [currentLang]);
|
||||
|
||||
const handleCards = (card: ICards) => {
|
||||
dispatch(handleCurrentCard(card));
|
||||
@@ -95,9 +95,9 @@ const App: React.FC = () => {
|
||||
};
|
||||
|
||||
const handleDisconnect = () => {
|
||||
closeStream()
|
||||
history.push('/')
|
||||
}
|
||||
closeStream();
|
||||
history.push("/");
|
||||
};
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -121,7 +121,12 @@ const App: React.FC = () => {
|
||||
<div className="background">
|
||||
<div className="popup-container">
|
||||
<div className="content__container">
|
||||
<SessionStartComponent cleanErrors={cleanErrors} handleConnect={handleConnect} isLoading={isLoading} currentCard={currentCard}></SessionStartComponent>
|
||||
<SessionStartComponent
|
||||
cleanErrors={cleanErrors}
|
||||
handleConnect={handleConnect}
|
||||
isLoading={isLoading}
|
||||
currentCard={currentCard}
|
||||
></SessionStartComponent>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -130,7 +135,11 @@ const App: React.FC = () => {
|
||||
)}
|
||||
</Route>
|
||||
<Route exact path="/stream/:id">
|
||||
<PlayerComponent handleDisconnect={handleDisconnect} loadStream={loadStream} cleanErrors={cleanErrors} ></PlayerComponent>
|
||||
<PlayerComponent
|
||||
handleDisconnect={handleDisconnect}
|
||||
loadStream={loadStream}
|
||||
cleanErrors={cleanErrors}
|
||||
></PlayerComponent>
|
||||
</Route>
|
||||
<Route path="/plan">
|
||||
<Header></Header>
|
||||
|
||||
@@ -1,49 +1,62 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from 'axios';
|
||||
import axios from "axios";
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL: 'https://a1.coord.graff.tech',
|
||||
baseURL: "https://a1.coord.graff.tech",
|
||||
});
|
||||
|
||||
instance.defaults.headers.post['Content-Type'] = 'application/json';
|
||||
|
||||
|
||||
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 } });
|
||||
const { data } = await instance.get("/title/get_for_language/", {
|
||||
params: { start: 0, count: 100, language: language },
|
||||
});
|
||||
return data;
|
||||
} catch (e: any) {
|
||||
const { response } = e
|
||||
const { response } = e;
|
||||
if (!response) {
|
||||
return thunkApi.rejectWithValue('Произошла ошибка, попробуйте позже');
|
||||
|
||||
return thunkApi.rejectWithValue("Произошла ошибка, попробуйте позже");
|
||||
} else {
|
||||
return thunkApi.rejectWithValue(response.data.message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
export const fetchPrivateCards = createAsyncThunk(
|
||||
"cards/FetchAll",
|
||||
async (key: string, thunkApi) => {
|
||||
try {
|
||||
const { data } = await instance.get("/title/get_private/", {
|
||||
params: { key },
|
||||
});
|
||||
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 });
|
||||
const { data } = await instance.post("/session/create", { title });
|
||||
return data;
|
||||
} catch (e: any) {
|
||||
const { response } = e
|
||||
const { response } = e;
|
||||
if (!response) {
|
||||
return thunkApi.rejectWithValue('Произошла ошибка, попробуйте позже');
|
||||
|
||||
return thunkApi.rejectWithValue("Произошла ошибка, попробуйте позже");
|
||||
} else {
|
||||
return thunkApi.rejectWithValue(response.data.message);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,16 +66,16 @@ export const connectSession = createAsyncThunk(
|
||||
"session/Connect",
|
||||
async (code: string, thunkApi) => {
|
||||
try {
|
||||
const { data } = await instance.get('/session/connect', { params: { session_id: code } });
|
||||
const { data } = await instance.get("/session/connect", {
|
||||
params: { session_id: code },
|
||||
});
|
||||
return data;
|
||||
} catch (e: any) {
|
||||
const { response } = e
|
||||
const { response } = e;
|
||||
if (!response) {
|
||||
return thunkApi.rejectWithValue('Произошла ошибка, попробуйте позже');
|
||||
|
||||
return thunkApi.rejectWithValue("Произошла ошибка, попробуйте позже");
|
||||
} else {
|
||||
return thunkApi.rejectWithValue(response.data.message);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1281
-680
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user