Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { PluginCommands } from 'mol-plugin/command';
import * as React from 'react';
import { PluginComponent } from './base';
export class CameraSnapshots extends PluginComponent<{ }, { }> {
render() {
return <div>
<h3>Camera Snapshots</h3>
<CameraSnapshotControls />
<CameraSnapshotList />
</div>;
}
}
class CameraSnapshotControls extends PluginComponent<{ }, { name: string, description: string }> {
state = { name: '', description: '' };
add = () => {
PluginCommands.Camera.Snapshots.Add.dispatch(this.plugin, this.state);
this.setState({ name: '', description: '' })
}
clear = () => {
PluginCommands.Camera.Snapshots.Clear.dispatch(this.plugin, {});
}
render() {
return <div>
<input type='text' value={this.state.name} placeholder='Name...' style={{ width: '33%', display: 'block', float: 'left' }} onChange={e => this.setState({ name: e.target.value })} />
<input type='text' value={this.state.description} placeholder='Description...' style={{ width: '67%', display: 'block' }} onChange={e => this.setState({ description: e.target.value })} />
<button style={{ float: 'right' }} onClick={this.clear}>Clear</button>
<button onClick={this.add}>Add</button>
</div>;
}
}
class CameraSnapshotList extends PluginComponent<{ }, { }> {
componentDidMount() {
this.subscribe(this.plugin.events.state.cameraSnapshots.changed, () => this.forceUpdate());
}
apply(id: string) {
return () => PluginCommands.Camera.Snapshots.Apply.dispatch(this.plugin, { id });
}
remove(id: string) {
return () => {
PluginCommands.Camera.Snapshots.Remove.dispatch(this.plugin, { id });
}
}
render() {
return <ul style={{ listStyle: 'none' }}>
{this.plugin.state.cameraSnapshots.entries.valueSeq().map(e =><li key={e!.id}>
<button onClick={this.apply(e!.id)}>Set</button>
{e!.name} <small>{e!.description}</small>
<button onClick={this.remove(e!.id)} style={{ float: 'right' }}>X</button>
</li>)}
</ul>;
}
}