Skip to content

Commit

Permalink
Add notification badge to mobile menu icon
Browse files Browse the repository at this point in the history
Maybe the user count badge will be annoying to have included
in the total, probably no one even knows what it’s for…
maybe should be a separate indicator.
  • Loading branch information
backspace committed Dec 2, 2018
1 parent 36deb93 commit 9a708a5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 38 deletions.
35 changes: 0 additions & 35 deletions app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,12 @@
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
import Controller from '@ember/controller';

import ObjectProxy from '@ember/object/proxy';
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
let ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin);

export default Controller.extend({
sidebar: service(),
session: service(),
store: service(),
userSocket: service(),

userCount: computed('userSocket.present.length', function () {
const count = this.get('userSocket.present.length');

if (count > 1) {
return count;
} else {
return undefined;
}
}),

postsRequest: computed(function () {
return ObjectPromiseProxy.create({
promise: this.get('store').findAll('post').then(posts => {
return {
posts
};
})
});
}),

unreadCount: computed('[email protected]', function () {
let posts = this.get('postsRequest.posts')

if (posts) {
return posts.filterBy('unread').length;
} else {
return 0;
}
}),

actions: {
logout() {
this.get('session').invalidate();
Expand Down
45 changes: 44 additions & 1 deletion app/services/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
import Service from '@ember/service';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';

import ObjectProxy from '@ember/object/proxy';
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
let ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin);

export default Service.extend({
open: false
store: service(),
userSocket: service(),

open: false,

userCount: computed('userSocket.present.length', function () {
const count = this.get('userSocket.present.length');

if (count > 1) {
return count;
} else {
return 0;
}
}),

postsRequest: computed(function () {
return ObjectPromiseProxy.create({
promise: this.get('store').findAll('post').then(posts => {
return {
posts
};
})
});
}),

unreadCount: computed('[email protected]', function () {
let posts = this.get('postsRequest.posts')

if (posts) {
return posts.filterBy('unread').length;
} else {
return 0;
}
}),

notificationCount: computed('userCount', 'unreadCount', function() {
return this.get('userCount') + this.get('unreadCount');
}),
});
13 changes: 13 additions & 0 deletions app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ md-toolbar {
box-shadow: none;
}
}

.count {
border-radius: 10px;
background: white;
color: color($color-indigo, '600');
font-size: 50%;
text-align: center;
width: 12px;
height: 12px;
position: absolute;
top: 10px;
left: 32px;
}
}

md-sidenav {
Expand Down
4 changes: 2 additions & 2 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
{{#paper-item}}
{{#link-to 'log'}}<span class='log'>
<span>Log</span>
{{#if unreadCount}}<span class='count' title='How many unread posts you have'>{{unreadCount}}</span>{{/if}}
{{#if sidebar.unreadCount}}<span class='count' title='How many unread posts you have'>{{sidebar.unreadCount}}</span>{{/if}}
</span>{{/link-to}}
{{/paper-item}}
{{#paper-item}}
{{#link-to 'users'}}<span class='users'>
<span>Users</span>
{{#if userCount}}<span class='count' title='How many users are connected'>{{userCount}}</span>{{/if}}
{{#if sidebar.userCount}}<span class='count' title='How many users are connected'>{{sidebar.userCount}}</span>{{/if}}
</span>{{/link-to}}
{{/paper-item}}
{{paper-divider}}
Expand Down
3 changes: 3 additions & 0 deletions app/templates/components/toolbar-header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
{{#paper-button iconButton=true onClick=(action 'toggleSidebar') class='hide-gt-sm'}}
{{paper-icon "menu"}}
{{/paper-button}}
{{#if sidebar.notificationCount}}
<span class='count hide-gt-sm' title='Check on {{pluralize sidebar.notificationCount 'notification'}}'>{{sidebar.notificationCount}}</span>
{{/if}}
<h2>{{title}}</h2>
{{#paper-chips readOnly=true content=chips as |item|}}<span title='{{item.title}}'>{{item.label}}</span>{{/paper-chips}}
<span class='flex'></span>
Expand Down

0 comments on commit 9a708a5

Please sign in to comment.