import { observable } from 'mobx'; import { observer } from 'mobx-react'; import * as React from 'react'; import ReactLoading from 'react-loading'; import { Doc } from '../../../fields/Doc'; import { StrCast } from '../../../fields/Types'; import { ViewBoxAnnotatableComponent } from '../DocComponent'; import { FieldView, FieldViewProps } from './FieldView'; import './LoadingBox.scss'; /** * LoadingBox Class represents a placeholder doc for documents that are currently * being uploaded to the server and being fetched by the client. The LoadingBox doc is then used to * generate the actual type of doc that is required once the document has been successfully uploaded. * * Design considerations: * We are using the docToFiles map in Documents to keep track of all files being uploaded in one session of the client. * If the file is not found we assume an error has occurred with the file upload, e.g. it has been interrupted by a client refresh * or network issues. The docToFiles essentially gets reset everytime the page is refreshed. * * TODOs: * 1) ability to query server to retrieve files that already exist if users upload duplicate files. * 2) ability to restart upload if there is an error * 3) detect network error and notify the user * 4 )if file upload gets interrupted, it still gets uploaded to the server if there are no network interruptions which leads to unused space. this could be * handled with (1) * 5) Fixing the stacking view bug * 6) Fixing the CSS * * @author naafiyan */ @observer export class LoadingBox extends ViewBoxAnnotatableComponent() { public static LayoutString(fieldKey: string) { return FieldView.LayoutString(LoadingBox, fieldKey); } componentDidMount() { if (!Doc.CurrentlyLoading || !Doc.CurrentlyLoading.includes(this.rootDoc)) { this.rootDoc.isLoading = false; this.rootDoc.errorMessage = 'Upload was interrupted, please try again'; } } render() { return (

{this.rootDoc.isLoading ? 'Loading (can take several minutes):' : StrCast(this.rootDoc.errorMessage, 'Error Loading File:')}

{StrCast(this.rootDoc.title)} {!this.rootDoc.isLoading ? null : }
); } }