link fe: base sidebar on link-listen-hook

Instead of on associations, which may contain collections we're no
longer interested in.
This commit is contained in:
Fang 2020-03-25 22:45:47 +01:00
parent 5f94fe0cf4
commit e028d6eacf
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
6 changed files with 62 additions and 8 deletions

View File

@ -21,8 +21,9 @@ export class ChannelsSidebar extends Component {
});
const channelItems =
Object.keys(props.associations).map((path) => {
[...props.listening].map((path) => {
const meta = props.associations[path];
if (!meta) return null;
const selected = (props.selected === path);
const linkCount = !!props.links[path] ? props.links[path].totalItems : 0;
const unseenCount = !!props.links[path]

View File

@ -54,7 +54,8 @@ export class Root extends Component {
groups={groups}
rightPanelHide={true}
sidebarShown={state.sidebarShown}
links={links}>
links={links}
listening={state.listening}>
<div className="h-100 w-100 overflow-x-hidden bg-white bg-gray0-d dn db-ns">
<div className="pl3 pr3 pt2 dt pb3 w-100 h-100">
<p className="f8 pt3 gray2 w-100 h-100 dtc v-mid tc">
@ -75,7 +76,8 @@ export class Root extends Component {
groups={groups}
rightPanelHide={true}
sidebarShown={state.sidebarShown}
links={links}>
links={links}
listening={state.listening}>
<NewScreen
associations={associations}
groups={groups}
@ -89,6 +91,7 @@ export class Root extends Component {
<Route exact path="/~link/join/:resource"
render={ (props) => {
const resourcePath = '/' + props.match.params.resource;
api.joinCollection(resourcePath);
props.history.push(makeRoutePath(resourcePath));
}}
/>
@ -111,7 +114,8 @@ export class Root extends Component {
selected={resourcePath}
rightPanelHide={true}
sidebarShown={state.sidebarShown}
links={links}>
links={links}
listening={state.listening}>
<MemberScreen
sidebarShown={state.sidebarShown}
resource={resource}
@ -148,7 +152,8 @@ export class Root extends Component {
rightPanelHide={true}
sidebarShown={state.sidebarShown}
popout={popout}
links={links}>
links={links}
listening={state.listening}>
<SettingsScreen
sidebarShown={state.sidebarShown}
resource={resource}
@ -200,7 +205,8 @@ export class Root extends Component {
sidebarShown={state.sidebarShown}
sidebarHideMobile={true}
popout={popout}
links={links}>
links={links}
listening={state.listening}>
<Links
{...props}
contacts={contactDetails}
@ -254,7 +260,8 @@ export class Root extends Component {
sidebarShown={state.sidebarShown}
sidebarHideMobile={true}
popout={popout}
links={links}>
links={links}
listening={state.listening}>
<LinkDetail
{...props}
resource={resource}

View File

@ -31,7 +31,8 @@ export class Skeleton extends Component {
groups={this.props.groups}
selected={this.props.selected}
sidebarShown={this.props.sidebarShown}
links={this.props.links}/>
links={this.props.links}
listening={this.props.listening}/>
<div className={"h-100 w-100 flex-auto" + rightPanelHide} style={{
flexGrow: 1,
}}>

View File

@ -0,0 +1,34 @@
import _ from 'lodash';
export class ListenUpdateReducer {
reduce(json, state) {
let data = _.get(json, 'link-listen-update', false);
if (data) {
this.listening(data, state);
this.watch(data, state);
this.leave(data, state);
}
}
listening(json, state) {
let data = _.get(json, 'listening', false);
if (data) {
state.listening = new Set(data);
}
}
watch(json, state) {
let data = _.get(json, 'watch', false);
if (data) {
state.listening.add(data);
}
}
leave(json, state) {
let data = _.get(json, 'leave', false);
if (data) {
state.listening.delete(data);
}
}
}

View File

@ -5,6 +5,7 @@ import { PermissionUpdateReducer } from '/reducers/permission-update';
import { MetadataReducer } from '/reducers/metadata-update.js';
import { InviteUpdateReducer } from '/reducers/invite-update';
import { LinkUpdateReducer } from '/reducers/link-update';
import { ListenUpdateReducer } from '/reducers/listen-update';
import { LocalReducer } from '/reducers/local.js';
import _ from 'lodash';
@ -20,6 +21,7 @@ class Store {
},
invites: {},
links: {},
listening: new Set(),
comments: {},
seen: {},
permissions: {},
@ -35,6 +37,7 @@ class Store {
this.inviteUpdateReducer = new InviteUpdateReducer();
this.localReducer = new LocalReducer();
this.linkUpdateReducer = new LinkUpdateReducer();
this.listenUpdateReducer = new ListenUpdateReducer();
this.setState = () => {};
}
@ -59,6 +62,7 @@ class Store {
this.inviteUpdateReducer.reduce(json, this.state);
this.localReducer.reduce(json, this.state);
this.linkUpdateReducer.reduce(json, this.state);
this.listenUpdateReducer.reduce(json, this.state);
this.setState(this.state);
}

View File

@ -36,6 +36,13 @@ export class Subscription {
this.handleQuitAndResubscribe.bind(this)
);
// open a subscription for what collections we're listening to
api.bind('/listening', 'PUT', api.authTokens.ship, 'link-listen-hook',
this.handleEvent.bind(this),
this.handleError.bind(this),
this.handleQuitAndResubscribe.bind(this)
);
// open a subscription for all submissions
api.getPage('', 0);