@@ -23,7 +25,7 @@ const SettingsPage = (): JSX.Element => {
Movies
- {GlobalInfos.isTVShowEnabled() ? (
+ {features.TVShowEnabled ? (
TV Shows
@@ -37,7 +39,7 @@ const SettingsPage = (): JSX.Element => {
- {GlobalInfos.isTVShowEnabled() ? (
+ {features.TVShowEnabled ? (
diff --git a/src/pages/TVShowPage/TVShowPage.tsx b/src/pages/TVShowPage/TVShowPage.tsx
index eee8d71..2465ca1 100644
--- a/src/pages/TVShowPage/TVShowPage.tsx
+++ b/src/pages/TVShowPage/TVShowPage.tsx
@@ -72,7 +72,7 @@ export default function (): JSX.Element {
return (
-
+
diff --git a/src/utils/Api.ts b/src/utils/Api.ts
index cf3a0a6..1f30e16 100644
--- a/src/utils/Api.ts
+++ b/src/utils/Api.ts
@@ -1,4 +1,3 @@
-import GlobalInfos from './GlobalInfos';
import {cookie} from './context/Cookie';
const APIPREFIX: string = '/api/';
@@ -84,13 +83,7 @@ function generalAPICall(
}
} else if (response.status === 400) {
// Bad Request --> invalid token
- console.log('loading Password page.');
- // load password page
- if (GlobalInfos.loadPasswordPage) {
- GlobalInfos.loadPasswordPage(() => {
- callAPI(apinode, fd, callback, errorcallback);
- });
- }
+ console.log('bad request todo sth here');
} else {
console.log('Error: ' + response.statusText);
if (errorcallback) {
diff --git a/src/utils/GlobalInfos.ts b/src/utils/GlobalInfos.ts
index 170a479..70f7495 100644
--- a/src/utils/GlobalInfos.ts
+++ b/src/utils/GlobalInfos.ts
@@ -49,6 +49,7 @@ class StaticInfos {
/**
* set the current videopath
* @param vidpath videopath with beginning and ending slash
+ * @param tvshowpath
*/
setVideoPaths(vidpath: string, tvshowpath: string): void {
this.videopath = vidpath;
@@ -68,27 +69,6 @@ class StaticInfos {
getTVShowPath(): string {
return this.tvshowpath;
}
-
- /**
- * load the Password page manually
- */
- loadPasswordPage: ((callback?: () => void) => void) | undefined = undefined;
-
- setTVShowsEnabled(TVShowEnabled: boolean): void {
- this.TVShowsEnabled = TVShowEnabled;
- }
-
- isTVShowEnabled(): boolean {
- return this.TVShowsEnabled;
- }
-
- setFullDeleteEnabled(FullDeleteEnabled: boolean): void {
- this.fullDeleteable = FullDeleteEnabled;
- }
-
- isVideoFulldeleteable(): boolean {
- return this.fullDeleteable;
- }
}
export default new StaticInfos();
diff --git a/src/utils/context/FeatureContext.tsx b/src/utils/context/FeatureContext.tsx
new file mode 100644
index 0000000..88c084a
--- /dev/null
+++ b/src/utils/context/FeatureContext.tsx
@@ -0,0 +1,32 @@
+import React, {FunctionComponent, useState} from 'react';
+
+export interface FeatureContextType {
+ setTVShowEnabled: (enabled: boolean) => void;
+ TVShowEnabled: boolean;
+ setVideosFullyDeleteable: (fullyDeletable: boolean) => void;
+ VideosFullyDeleteable: boolean;
+}
+
+/**
+ * A global context providing a way to interact with user login states
+ */
+export const FeatureContext = React.createContext({
+ setTVShowEnabled: (_) => {},
+ TVShowEnabled: false,
+ setVideosFullyDeleteable: (_) => {},
+ VideosFullyDeleteable: false
+});
+
+export const FeatureContextProvider: FunctionComponent = (props): JSX.Element => {
+ const [tvshowenabled, settvshowenabled] = useState(false);
+ const [fullydeletablevids, setfullydeleteable] = useState(false);
+
+ const value: FeatureContextType = {
+ VideosFullyDeleteable: fullydeletablevids,
+ TVShowEnabled: tvshowenabled,
+ setTVShowEnabled: (e) => settvshowenabled(e),
+ setVideosFullyDeleteable: (e) => setfullydeleteable(e)
+ };
+
+ return {props.children};
+};
diff --git a/src/utils/context/LoginContextProvider.tsx b/src/utils/context/LoginContextProvider.tsx
index 144441b..1c5d418 100644
--- a/src/utils/context/LoginContextProvider.tsx
+++ b/src/utils/context/LoginContextProvider.tsx
@@ -5,18 +5,21 @@ import {cookie} from './Cookie';
import {APINode, callAPI} from '../Api';
import {SettingsTypes} from '../../types/ApiTypes';
import GlobalInfos from '../GlobalInfos';
+import {FeatureContext} from './FeatureContext';
export const LoginContextProvider: FunctionComponent = (props): JSX.Element => {
let initialLoginState = LoginState.LoggedIn;
let initialUserPerm = LoginPerm.User;
+ const features = useContext(FeatureContext);
+
const t = cookie.Load();
// we are already logged in so we can set the token and redirect to dashboard
if (t !== null) {
initialLoginState = LoginState.LoggedIn;
}
- const initialAPICall = (): void => {
+ useEffect(() => {
// this is the first api call so if it fails we know there is no connection to backend
callAPI(
APINode.Settings,
@@ -27,9 +30,9 @@ export const LoginContextProvider: FunctionComponent = (props): JSX.Element => {
GlobalInfos.setVideoPaths(result.VideoPath, result.TVShowPath);
- GlobalInfos.setTVShowsEnabled(result.TVShowEnabled);
- GlobalInfos.setFullDeleteEnabled(result.FullDeleteEnabled);
- //
+ features.setTVShowEnabled(result.TVShowEnabled);
+ features.setVideosFullyDeleteable(result.FullDeleteEnabled);
+
// this.setState({
// mediacentername: result.MediacenterName
// });
@@ -42,11 +45,7 @@ export const LoginContextProvider: FunctionComponent = (props): JSX.Element => {
setLoginState(LoginState.LoggedOut);
}
);
- };
-
- useEffect(() => {
- initialAPICall();
- }, []);
+ }, [features]);
const [loginState, setLoginState] = useState(initialLoginState);
const [permission, setPermission] = useState(initialUserPerm);