app.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import * as React from 'react'
  7. import { StructureView } from '../structure-view';
  8. import { App } from '../app';
  9. import { Viewport } from './viewport';
  10. import { StructureViewComponent } from './structure-view';
  11. // export function FileInput (props: {
  12. // accept: string
  13. // onChange: (v: FileList | null) => void,
  14. // }) {
  15. // return <input
  16. // accept={props.accept || '*.*'}
  17. // type='file'
  18. // onChange={e => props.onChange.call(null, e.target.files)}
  19. // />
  20. // }
  21. export interface AppProps {
  22. app: App
  23. }
  24. export interface AppState {
  25. structureView: StructureView | null
  26. }
  27. export class AppComponent extends React.Component<AppProps, AppState> {
  28. state = {
  29. structureView: this.props.app.structureView,
  30. }
  31. componentDidMount() {
  32. this.props.app.pdbIdLoaded.subscribe((structureView) => {
  33. this.setState({
  34. structureView: this.props.app.structureView
  35. })
  36. })
  37. }
  38. render() {
  39. const { structureView } = this.state
  40. return <div style={{width: '100%', height: '100%'}}>
  41. <div style={{left: '0px', right: '350px', height: '100%', position: 'absolute'}}>
  42. <Viewport app={this.props.app} />
  43. </div>
  44. <div style={{width: '330px', paddingLeft: '10px', paddingRight: '10px', right: '0px', height: '100%', position: 'absolute', overflow: 'auto'}}>
  45. <div style={{marginTop: '10px'}}>
  46. <span>Load PDB ID </span>
  47. <input
  48. type='text'
  49. onKeyDown={e => {
  50. if (e.keyCode === 13) {
  51. const value = e.currentTarget.value.trim()
  52. if (value) {
  53. this.props.app.loadPdbId(value)
  54. }
  55. }
  56. }}
  57. />
  58. </div>
  59. <div>
  60. <span>Load CIF file </span>
  61. <input
  62. accept='*.cif'
  63. type='file'
  64. onChange={e => {
  65. if (e.target.files) this.props.app.loadCifFile(e.target.files[0])
  66. }}
  67. />
  68. </div>
  69. <hr/>
  70. <div style={{marginBottom: '10px'}}>
  71. {structureView ? <StructureViewComponent structureView={structureView} /> : ''}
  72. </div>
  73. </div>
  74. </div>;
  75. }
  76. }