From a051331680b21f20201a47601d69505a4cfa9e40 Mon Sep 17 00:00:00 2001 From: muhamedsalih-tw <104364298+muhamedsalih-tw@users.noreply.github.com> Date: Sat, 19 Nov 2022 15:21:09 +0530 Subject: Transform service components to ts (#778) --- src/components/services/content/ServiceView.tsx | 192 ++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 src/components/services/content/ServiceView.tsx (limited to 'src/components/services/content/ServiceView.tsx') diff --git a/src/components/services/content/ServiceView.tsx b/src/components/services/content/ServiceView.tsx new file mode 100644 index 000000000..e41184431 --- /dev/null +++ b/src/components/services/content/ServiceView.tsx @@ -0,0 +1,192 @@ +import { Component } from 'react'; +import { autorun, IReactionDisposer } from 'mobx'; +import { observer, inject } from 'mobx-react'; +import classnames from 'classnames'; +import TopBarProgress from 'react-topbar-progress-indicator'; +import ServiceModel from '../../../models/Service'; +import StatusBarTargetUrl from '../../ui/StatusBarTargetUrl'; +import WebviewLoader from '../../ui/WebviewLoader'; +import WebviewCrashHandler from './WebviewCrashHandler'; +import WebviewErrorHandler from './WebviewErrorHandler'; +import ServiceDisabled from './ServiceDisabled'; +import ServiceWebview from './ServiceWebview'; +import WebControlsScreen from '../../../features/webControls/containers/WebControlsScreen'; +import { CUSTOM_WEBSITE_RECIPE_ID } from '../../../config'; +import { RealStores } from '../../../stores'; + +interface IProps { + service: ServiceModel; + setWebviewRef: () => void; + detachService: () => void; + reload: () => void; + edit: () => void; + enable: () => void; + // isActive?: boolean; // TODO - [TECH DEBT][PROP NOT USED IN COMPONENT] check it + stores?: RealStores; + isSpellcheckerEnabled: boolean; +} + +interface IState { + forceRepaint: boolean; + targetUrl: string; + statusBarVisible: boolean; +} + +@inject('stores', 'actions') +@observer +class ServiceView extends Component { + // hibernationTimer = null; // TODO - [TS DEBT] class property not reassigned, need to find its purpose + + autorunDisposer: IReactionDisposer | undefined; + + forceRepaintTimeout: NodeJS.Timeout | undefined; + + constructor(props: IProps) { + super(props); + + this.state = { + forceRepaint: false, + targetUrl: '', + statusBarVisible: false, + }; + } + + componentDidMount() { + this.autorunDisposer = autorun(() => { + if (this.props.service.isActive) { + this.setState({ forceRepaint: true }); + this.forceRepaintTimeout = setTimeout(() => { + this.setState({ forceRepaint: false }); + }, 100); + } + }); + } + + componentWillUnmount() { + this.autorunDisposer!(); + clearTimeout(this.forceRepaintTimeout!); + // clearTimeout(this.hibernationTimer); // TODO - [TS DEBT] class property not reassigned, need to find its purpose + } + + render() { + const { + detachService, + service, + setWebviewRef, + reload, + edit, + enable, + stores, + isSpellcheckerEnabled, + } = this.props; + + const { navigationBarBehaviour, navigationBarManualActive } = + stores!.settings.app; + + const showNavBar = + navigationBarBehaviour === 'always' || + (navigationBarBehaviour === 'custom' && + service.recipe.id === CUSTOM_WEBSITE_RECIPE_ID) || + navigationBarManualActive; + + const webviewClasses = classnames({ + services__webview: true, + 'services__webview-wrapper': true, + 'is-active': service.isActive, + 'services__webview--force-repaint': this.state.forceRepaint, + }); + + const statusBar = this.state.statusBarVisible ? ( + + ) : null; + + return ( +
+ {service.isActive && service.isEnabled && ( + <> + {service.hasCrashed && ( + + )} + {service.isEnabled && + service.isLoading && + service.isFirstLoad && + !service.isHibernating && + !service.isServiceAccessRestricted && ( + + )} + {service.isProgressbarEnabled && + service.isLoadingPage && + !service.isFirstLoad && } + {service.isError && ( + + )} + + )} + {!service.isEnabled ? ( + <> + {service.isActive && ( + + )} + + ) : ( + <> + {!service.isHibernating ? ( + <> + {showNavBar && } + + + ) : ( +
+ + 😴 + +
+
+ This service is currently hibernating. +
+ Try switching services or reloading Ferdium. +
+ )} + + )} + {statusBar} +
+ ); + } +} + +export default ServiceView; -- cgit v1.2.3-70-g09d2