Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WebsiteScreen.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // @flow
  2. import * as React from 'react';
  3. import {StackNavigationProp} from '@react-navigation/stack';
  4. import WebViewScreen from '../../components/Screens/WebViewScreen';
  5. import AvailableWebsites from '../../constants/AvailableWebsites';
  6. import BasicLoadingScreen from '../../components/Screens/BasicLoadingScreen';
  7. type PropsType = {
  8. navigation: StackNavigationProp,
  9. route: {params: {host: string, path: string | null, title: string}},
  10. };
  11. const ENABLE_MOBILE_STRING = `<meta name="viewport" content="width=device-width, initial-scale=1.0">`;
  12. const AVAILABLE_ROOMS_STYLE = `<style>body,body>.container2{padding-top:0;width:100%}b,body>.container2>h1,body>.container2>h3,br,header{display:none}.table-bordered td,.table-bordered th{border:none;border-right:1px solid #dee2e6;border-bottom:1px solid #dee2e6}.table{padding:0;margin:0;width:200%;max-width:200%;display:block}tbody{display:block;width:100%}thead{display:block;width:100%}.table tbody tr,tbody tr[bgcolor],thead tr{width:100%;display:inline-flex}.table tbody td,.table thead td[colspan]{padding:0;flex:1;height:50px;margin:0}.table tbody td[bgcolor=white],.table thead td,.table>tbody>tr>td:nth-child(1){flex:0 0 150px;height:50px}</style>`;
  13. const BIB_STYLE = `<style>.hero-unit,.navbar,footer{display:none}.hero-unit-form,.hero-unit2,.hero-unit3{background-color:#fff;box-shadow:none;padding:0;margin:0}.hero-unit-form h4{font-size:2rem;line-height:2rem}.btn{font-size:1.5rem;line-height:1.5rem;padding:20px}.btn-danger{background-image:none;background-color:#be1522}.table{font-size:.8rem}.table td{padding:0;height:18.2333px;border:none;border-bottom:1px solid #c1c1c1}.table td[style="max-width:55px;"]{max-width:110px!important}.table-bordered{min-width:50px}th{height:50px}.table-bordered{border-collapse:collapse}</style>`;
  14. const BIB_BACK_BUTTON =
  15. `<div style='width: 100%; display: flex'>` +
  16. `<a style='margin: auto' href='${AvailableWebsites.websites.BIB}'>` +
  17. `<button id='customBackButton' class='btn btn-primary'>Retour</button>` +
  18. `</a>` +
  19. `</div>`;
  20. class WebsiteScreen extends React.Component<PropsType> {
  21. fullUrl: string;
  22. injectedJS: {[key: string]: string};
  23. customPaddingFunctions: {[key: string]: (padding: string) => string};
  24. host: string;
  25. constructor(props: PropsType) {
  26. super(props);
  27. props.navigation.addListener('focus', this.onScreenFocus);
  28. this.injectedJS = {};
  29. this.customPaddingFunctions = {};
  30. this.injectedJS[AvailableWebsites.websites.AVAILABLE_ROOMS] =
  31. `document.querySelector('head').innerHTML += '${ENABLE_MOBILE_STRING}';` +
  32. `document.querySelector('head').innerHTML += '${AVAILABLE_ROOMS_STYLE}'; true;`;
  33. this.injectedJS[AvailableWebsites.websites.BIB] =
  34. `document.querySelector('head').innerHTML += '${ENABLE_MOBILE_STRING}';` +
  35. `document.querySelector('head').innerHTML += '${BIB_STYLE}';` +
  36. `if ($(".hero-unit-form").length > 0 && $("#customBackButton").length === 0)` +
  37. `$(".hero-unit-form").append("${BIB_BACK_BUTTON}");true;`;
  38. this.customPaddingFunctions[AvailableWebsites.websites.BLUEMIND] = (
  39. padding: string,
  40. ): string => {
  41. return (
  42. `$('head').append('${ENABLE_MOBILE_STRING}');` +
  43. `$('.minwidth').css('top', ${padding}` +
  44. `$('#mailview-bottom').css('min-height', 500);`
  45. );
  46. };
  47. this.customPaddingFunctions[AvailableWebsites.websites.WIKETUD] = (
  48. padding: string,
  49. ): string => {
  50. return (
  51. `$('#p-logo-text').css('top', 10 + ${padding});` +
  52. `$('#site-navigation h2').css('top', 10 + ${padding});` +
  53. `$('#site-tools h2').css('top', 10 + ${padding});` +
  54. `$('#user-tools h2').css('top', 10 + ${padding});`
  55. );
  56. };
  57. }
  58. onScreenFocus = () => {
  59. this.handleNavigationParams();
  60. };
  61. /**
  62. *
  63. */
  64. handleNavigationParams() {
  65. const {route, navigation} = this.props;
  66. if (route.params != null) {
  67. this.host = route.params.host;
  68. let {path} = route.params;
  69. const {title} = route.params;
  70. if (this.host != null && path != null) {
  71. path = path.replace(this.host, '');
  72. this.fullUrl = this.host + path;
  73. } else this.fullUrl = this.host;
  74. if (title != null) navigation.setOptions({title});
  75. }
  76. }
  77. render(): React.Node {
  78. const {navigation} = this.props;
  79. let injectedJavascript = '';
  80. let customPadding = null;
  81. if (this.host != null && this.injectedJS[this.host] != null)
  82. injectedJavascript = this.injectedJS[this.host];
  83. if (this.host != null && this.customPaddingFunctions[this.host] != null)
  84. customPadding = this.customPaddingFunctions[this.host];
  85. if (this.fullUrl != null) {
  86. return (
  87. <WebViewScreen
  88. navigation={navigation}
  89. url={this.fullUrl}
  90. customJS={injectedJavascript}
  91. customPaddingFunction={customPadding}
  92. />
  93. );
  94. }
  95. return <BasicLoadingScreen />;
  96. }
  97. }
  98. export default WebsiteScreen;