aboutsummaryrefslogtreecommitdiffstats
path: root/src/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js52
1 files changed, 41 insertions, 11 deletions
diff --git a/src/index.js b/src/index.js
index ba50149..b32054e 100644
--- a/src/index.js
+++ b/src/index.js
@@ -2,8 +2,8 @@ import 'preact/debug';
import 'core-js/stable';
import 'regenerator-runtime/runtime';
import * as jsonld from 'jsonld';
-import { h, Component, render } from 'preact';
-import { Discussion } from './ui';
+import { h, Fragment, Component, render } from 'preact';
+import { Discussion, Selection } from './ui';
const context = [
'https://www.w3.org/ns/activitystreams',
@@ -154,6 +154,27 @@ class GraphContainer extends Component {
}
}
+class SelectionContainer extends Component {
+ state = {
+ selection: [],
+ };
+
+ toggle = (id) => {
+ const { selection } = this.state;
+ if (selection.indexOf(id) < 0)
+ this.setState({ selection: [ ...selection, id ] });
+ else
+ this.setState({ selection: selection.filter(i => i !== id) });
+ }
+
+ render() {
+ return this.props.render({
+ ...this.state,
+ toggleSelected: this.toggle,
+ });
+ }
+}
+
class CollapseContainer extends Component {
state = {};
@@ -193,17 +214,26 @@ const search = new URLSearchParams(window.location.search);
const graph = search.has('graph') ? search.get('graph') : 'lib/graph.json';
const app = (
<GraphContainer graph={graph} render={({ name, items }) => (
- <CollapseContainer
- items={items}
- render={({ collapsed, toggleCollapsed }) => (
- <Discussion
- name={name}
+ <SelectionContainer render={({ selection, toggleSelected }) => (
+ <>
+ <CollapseContainer
items={items}
- collapsed={collapsed}
- toggleCollapsed={toggleCollapsed}
+ render={({ collapsed, toggleCollapsed }) => (
+ <Discussion
+ name={name}
+ items={items}
+ collapsed={collapsed}
+ toggleCollapsed={toggleCollapsed}
+ toggleSelected={toggleSelected}
+ />
+ )}
+ />
+ <Selection
+ items={selection.map(id => items[id])}
+ toggleSelected={toggleSelected}
/>
- )}
- />
+ </>
+ )} />
)} />
);
render(app, document.body);