diff --git a/frontend/src/js/dialog/wb-browse-dialog-collection-content.js b/frontend/src/js/dialog/wb-browse-dialog-collection-content.js index e69de29..b58ac2d 100644 --- a/frontend/src/js/dialog/wb-browse-dialog-collection-content.js +++ b/frontend/src/js/dialog/wb-browse-dialog-collection-content.js @@ -0,0 +1,11 @@ +import { h, Component } from 'preact'; + +class WBBrowseDialogCollectionContent extends Component { + render() { + return ( +
WBBrowseDialogCollectionContent
+ ); + } +} + +export default WBBrowseDialogCollectionContent; diff --git a/frontend/src/js/dialog/wb-browse-dialog-collection-list.js b/frontend/src/js/dialog/wb-browse-dialog-collection-list.js index e69de29..3f83c5b 100644 --- a/frontend/src/js/dialog/wb-browse-dialog-collection-list.js +++ b/frontend/src/js/dialog/wb-browse-dialog-collection-list.js @@ -0,0 +1,11 @@ +import { h, Component } from 'preact'; + +class WBBrowseDialogCollectionList extends Component { + render() { + return ( +
WBBrowseDialogCollectionList
+ ); + } +} + +export default WBBrowseDialogCollectionList; diff --git a/frontend/src/js/dialog/wb-browse-dialog-user-list.js b/frontend/src/js/dialog/wb-browse-dialog-user-list.js new file mode 100644 index 0000000..ed9ad21 --- /dev/null +++ b/frontend/src/js/dialog/wb-browse-dialog-user-list.js @@ -0,0 +1,11 @@ +import { h, Component } from 'preact'; + +class WBBrowseDialogUserList extends Component { + render() { + return ( +
WBBrowseDialogUserList
+ ); + } +} + +export default WBBrowseDialogUserList; diff --git a/frontend/src/js/dialog/wb-browse-dialog.js b/frontend/src/js/dialog/wb-browse-dialog.js index bddecec..af53033 100644 --- a/frontend/src/js/dialog/wb-browse-dialog.js +++ b/frontend/src/js/dialog/wb-browse-dialog.js @@ -1,94 +1,152 @@ import { h, Component } from 'preact'; import WBBrowseDialogProjectList from 'wb-browse-dialog-project-list'; import WBBrowseDialogCollectionList from 'wb-browse-dialog-project-list'; +import WBBrowseDialogCollectionContent from 'wb-browse-dialog-collection-content'; +import WBBrowseDialogUserList from 'wb-browse-dialog-user-list'; import linkState from 'linkstate'; import { Router } from 'preact-router'; import { createHashHistory } from 'history'; +// +// internal URLs look like this +// +// /browse-dialog/browse/( owner-uuid )/( project-page )/( text-search ) +// /browse-dialog/users//( users-page )/( text-search ) +// /browse-dialog/shared-with-me//( project-page )/( collection-page )/( text-search ) +// /browse-dialog/content/( collection-uuid )//( content-page )/( text-search ) +// +// general pattern therefore: +// /browse-dialog/( mode )/( uuid )/( top-page )/( bottom-page )/( text-search ) +// +// props: +// selectMany: Boolean +// selectWhat: [ 'file', 'directory' ] +// +// state: +// selected: Array of UUID +// textSearch: string +// textSearchInput: string +// + class WBBrowseDialog extends Component { constructor(...args) { super(...args); this.state.history = []; - this.state.history_1 = createHashHistory(); + this.state.selected = {}; + this.state.selectedOrder = []; + const { currentUser } = this.props.app.state; + this.navigate('/browse-dialog/browse/' + currentUser.uuid, false); } - resetSearch() { + navigateBack() { + if (this.history.length === 0) + return; + const url = this.history.pop(); + navigate(url, false); + } + + navigate(url, history=true) { + if (history) + this.history.push(this.state.currentUrl); + let [ _1, _2, mode, uuid, topPage, bottomPage, textSearch ] = url.split('/'); + topPage = parseInt(topPage, 10) || 0; + bottomPage = parseInt(bottomPage, 10) || 0; this.setState({ - 'textSearch': null, - 'textSearchInput': null + 'currentUrl': url, + mode, uuid, topPage, bottomPage, textSearch }); } - pushHistory(child) { - const { history, textSearch } = this.state; - history.push([ child, { textSearch } ]); - this.state.history = history.slice(history.length - 1000); + select(uuid) { + let { selected, selectedOrder } = this.state; + if (uuid in selected) { + const n = selectedOrder.indexOf(uuid); + selectedOrder = selected.splice(n, n + 1); + } + selected[uuid] = true; + selectedOrder.push(uuid); + this.setState({ + selected, selectedOrder + }); } - popHistory() { - if (this.history.length === 0) + deselect(uuid) { + let { selected, selectedOrder } = this.state; + if (!(uuid in selected)) return; - const entry = history.pop(); - this.setState(entry[1]); - entry[0].popHistory(); + const n = selectedOrder.indexOf(uuid); + selectedOrder = selected.splice(n, n + 1); + delete selected[uuid]; + this.setState({ + selected, selectedOrder + }); } - render({ app, id }, { mode, textSearch, textSearchInput, history, history_1 }) { + resetSelection() { + this.setState({ + 'selected': {}, + 'selectedOrder': [] + }); + } + + render({ app, id, selectMany, selectWhat }, { currentUrl, mode, uuid, topPage, bottomPage, textSearch }) { return (