/*
* Copyright (c) 2019 - 2020 Arnaud Vergnet.
*
* This file is part of Campus INSAT.
*
* Campus INSAT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Campus INSAT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Campus INSAT. If not, see .
*/
import * as React from 'react';
import { StackNavigationProp } from '@react-navigation/stack';
import WebViewScreen from '../../components/Screens/WebViewScreen';
import AvailableWebsites from '../../constants/AvailableWebsites';
import BasicLoadingScreen from '../../components/Screens/BasicLoadingScreen';
type Props = {
navigation: StackNavigationProp;
route: { params: { host: string; path: string | null; title: string } };
};
type State = {
url: string;
};
const ENABLE_MOBILE_STRING =
'';
const AVAILABLE_ROOMS_STYLE =
'';
const BIB_STYLE =
'';
const BIB_BACK_BUTTON =
"';
class WebsiteScreen extends React.Component {
injectedJS: { [key: string]: string };
customPaddingFunctions: { [key: string]: (padding: number) => string };
host: string;
constructor(props: Props) {
super(props);
this.state = {
url: '',
};
this.host = '';
props.navigation.addListener('focus', this.onScreenFocus);
this.injectedJS = {};
this.customPaddingFunctions = {};
this.injectedJS[AvailableWebsites.websites.AVAILABLE_ROOMS] =
`document.querySelector('head').innerHTML += '${ENABLE_MOBILE_STRING}';` +
`document.querySelector('head').innerHTML += '${AVAILABLE_ROOMS_STYLE}'; true;`;
this.injectedJS[AvailableWebsites.websites.BIB] =
`document.querySelector('head').innerHTML += '${ENABLE_MOBILE_STRING}';` +
`document.querySelector('head').innerHTML += '${BIB_STYLE}';` +
'if ($(".hero-unit-form").length > 0 && $("#customBackButton").length === 0)' +
`$(".hero-unit-form").append("${BIB_BACK_BUTTON}");true;`;
this.customPaddingFunctions[AvailableWebsites.websites.BLUEMIND] = (
padding: number
): string => {
return (
`$('head').append('${ENABLE_MOBILE_STRING}');` +
`$('.minwidth').css('top', ${padding}` +
"$('#mailview-bottom').css('min-height', 500);"
);
};
this.customPaddingFunctions[AvailableWebsites.websites.WIKETUD] = (
padding: number
): string => {
return (
`$('#p-logo-text').css('top', 10 + ${padding});` +
`$('#site-navigation h2').css('top', 10 + ${padding});` +
`$('#site-tools h2').css('top', 10 + ${padding});` +
`$('#user-tools h2').css('top', 10 + ${padding});`
);
};
}
onScreenFocus = () => {
this.handleNavigationParams();
};
/**
*
*/
handleNavigationParams() {
const { route, navigation } = this.props;
if (route.params != null) {
console.log(route.params);
this.host = route.params.host;
let { path } = route.params;
const { title } = route.params;
let fullUrl = '';
if (this.host != null && path != null) {
path = path.replace(this.host, '');
fullUrl = this.host + path;
} else {
fullUrl = this.host;
}
this.setState({ url: fullUrl });
if (title != null) {
navigation.setOptions({ title });
}
}
}
render() {
let injectedJavascript = '';
let customPadding = null;
if (this.host != null && this.injectedJS[this.host] != null) {
injectedJavascript = this.injectedJS[this.host];
}
if (this.host != null && this.customPaddingFunctions[this.host] != null) {
customPadding = this.customPaddingFunctions[this.host];
}
if (this.state.url) {
return (
);
}
return ;
}
}
export default WebsiteScreen;