From b79c796b0dfe28d8e06eec004998439fea836760 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 26 Dec 2019 16:04:58 +0100 Subject: init category list --- .../modules/biggan/views/biggan.categoryList.js | 107 +++++++++++++++++++++ app/client/modules/biggan/views/biggan.live.js | 30 +++--- 2 files changed, 122 insertions(+), 15 deletions(-) create mode 100644 app/client/modules/biggan/views/biggan.categoryList.js (limited to 'app/client') diff --git a/app/client/modules/biggan/views/biggan.categoryList.js b/app/client/modules/biggan/views/biggan.categoryList.js new file mode 100644 index 0000000..4285f3f --- /dev/null +++ b/app/client/modules/biggan/views/biggan.categoryList.js @@ -0,0 +1,107 @@ +import { h, Component } from 'preact' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import { + Loading +} from '../../../common/' + +import * as liveActions from '../../../live/live.actions' +import * as bigganTasks from '../biggan.tasks' +import * as bigganActions from '../biggan.actions' + +const ALL_CATEGORIES = 'inversion/categories/biggan_all.json' + +class CategoryList extends Component { + state = { + loading: true, + categories: {}, + q: "", + fn: "", + } + + constructor(props) { + this.loadCategories(ALL_CATEGORIES) + } + + loadCategories(fn) { + this.setState({ loading: true, fn }) + actions.socket + .read_file({ module, fn }) + .then(({ name, buf }) => { + this.setState({ + categories: String.fromCharCode.apply(null, new Uint8Array(buf)), + loading: false, + }) + }) + } + + loadCategory(index) { + actions.live.send_command('loadCategory', str(index)) + } + + render() { + const { loading, q } = this.state + if (loading) { + return
+ } + return ( +
+ this.setState({ q: e.target.value })} /> +
+ {this.renderGroup("inanimate")} + {this.renderGroup("animate")} +
+
+ ) + } + + renderGroup(groupName) { + const { categories, q } = this.state + const qRegexp = new Regexp(q || ".*") + const group = categories[group_name] + const groups = Object.keys(group).map(key => { + const category = group[key] + const categoryGroup = Object.keys(category).map(categoryName => { + if (!categoryName.match(qRegexp)) { + return null + } + return ( + this.loadCategory(category[categoryName])}> + {categoryName} + } + ) + }).filter(g => !! g) + return !categoryGroup.length ? null : ( +
+

{category}

+ {categoryGroup} +
+ ) + }).filter(g => !! g) + if (!groups.length) { + return null + } + return ( +
+

{groupName}

+ {groups} +
+ ) + } +} + +const mapStateToProps = state => ({ + opt: state.live.opt, + frame: state.live.frame, + biggan: state.module.biggan, +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + actions: { + live: bindActionCreators(liveActions, dispatch), + socket: bindActionCreators(socketActions, dispatch), + } +}) + +export default connect(mapStateToProps, mapDispatchToProps)(BigGANCategoryList) diff --git a/app/client/modules/biggan/views/biggan.live.js b/app/client/modules/biggan/views/biggan.live.js index fd6b12d..20cffe8 100644 --- a/app/client/modules/biggan/views/biggan.live.js +++ b/app/client/modules/biggan/views/biggan.live.js @@ -36,7 +36,7 @@ class BigGANLive extends Component { // return // } return ( -
+
@@ -139,20 +139,20 @@ class BigGANLive extends Component { >{i18n.gpu.interrupt} ) } - if (! this.props.opt.processing) { - return ( -
- - -
- ) - } + // if (! this.props.opt.processing) { + // return ( + //
+ // + // + //
+ // ) + // } return (