about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/ui/index.js
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-09-06 16:09:57 +0200
committerThibG <thib@sitedethib.com>2018-09-07 20:37:17 +0200
commit0f155af32a330bc8eb79c6e3ccec5331a1e37922 (patch)
treed3d4655cad5942ad56c922354147898567907540 /app/javascript/flavours/glitch/features/ui/index.js
parentd315f1dc02f15b55585a853ac19aefbe6983d87d (diff)
Add notification badge to favicon
Diffstat (limited to 'app/javascript/flavours/glitch/features/ui/index.js')
-rw-r--r--app/javascript/flavours/glitch/features/ui/index.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/features/ui/index.js b/app/javascript/flavours/glitch/features/ui/index.js
index c41436090..3dd894383 100644
--- a/app/javascript/flavours/glitch/features/ui/index.js
+++ b/app/javascript/flavours/glitch/features/ui/index.js
@@ -17,6 +17,7 @@ import { WrappedSwitch, WrappedRoute } from 'flavours/glitch/util/react_router_h
 import UploadArea from './components/upload_area';
 import ColumnsAreaContainer from './containers/columns_area_container';
 import classNames from 'classnames';
+import Favico from 'favico.js';
 import {
   Drawer,
   Status,
@@ -64,6 +65,7 @@ const mapStateToProps = state => ({
   isWide: state.getIn(['local_settings', 'stretch']),
   navbarUnder: state.getIn(['local_settings', 'navbar_under']),
   dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null,
+  unreadNotifications: state.getIn(['notifications', 'unread']),
 });
 
 const keyMap = {
@@ -115,6 +117,7 @@ export default class UI extends React.Component {
     history: PropTypes.object.isRequired,
     intl: PropTypes.object.isRequired,
     dropdownMenuIsOpen: PropTypes.bool,
+    unreadNotifications: PropTypes.number,
   };
 
   state = {
@@ -239,6 +242,8 @@ export default class UI extends React.Component {
       navigator.serviceWorker.addEventListener('message', this.handleServiceWorkerPostMessage);
     }
 
+    this.favicon = new Favico({ animation:"none" });
+
     this.props.dispatch(expandHomeTimeline());
     this.props.dispatch(expandNotifications());
     setTimeout(() => this.props.dispatch(fetchFilters()), 500);
@@ -267,6 +272,11 @@ export default class UI extends React.Component {
     if (![this.props.location.pathname, '/'].includes(prevProps.location.pathname)) {
       this.columnsAreaNode.handleChildrenContentChange();
     }
+    if (this.props.unreadNotifications != prevProps.unreadNotifications) {
+      if (this.favicon) {
+        this.favicon.badge(this.props.unreadNotifications);
+      }
+    }
   }
 
   componentWillUnmount () {