@@ -2,16 +2,28 @@ var React = require('react');
22var Reflux = require ( 'reflux' ) ;
33var Loading = require ( 'reloading' ) ;
44var _ = require ( 'underscore' ) ;
5- var remote = window . require ( 'remote' ) ;
6- var shell = remote . require ( 'shell' ) ;
75
86var Actions = require ( '../actions/actions' ) ;
97var NotificationsStore = require ( '../stores/notifications' ) ;
8+ var SearchStore = require ( '../stores/search' ) ;
109var Repository = require ( '../components/repository' ) ;
1110
1211var Notifications = React . createClass ( {
12+ areIn : function ( repoFullName , searchTerm ) {
13+ return repoFullName . toLowerCase ( ) . indexOf ( searchTerm . toLowerCase ( ) ) >= 0 ;
14+ } ,
15+
16+ matchesSearchTerm : function ( obj ) {
17+ var repoFullName = obj [ 0 ] . repository . full_name ;
18+ var searchTerm = this . state . searchTerm . replace ( / ^ \s + / , '' ) . replace ( / \s + $ / , '' ) ;
19+ var searchTerms = searchTerm . split ( / \s + / ) ;
20+
21+ return _ . all ( searchTerms , this . areIn . bind ( null , repoFullName ) ) ;
22+ } ,
23+
1324 mixins : [
1425 Reflux . connect ( NotificationsStore , 'notifications' ) ,
26+ Reflux . connect ( SearchStore , 'searchTerm' ) ,
1527 Reflux . listenTo ( Actions . getNotifications . completed , 'completedNotifications' ) ,
1628 Reflux . listenTo ( Actions . getNotifications . failed , 'failedNotifications' )
1729 ] ,
@@ -45,9 +57,9 @@ var Notifications = React.createClass({
4557 render : function ( ) {
4658 var notifications , errors ;
4759 var wrapperClass = 'container-fluid main-container notifications' ;
60+ var notificationsEmpty = _ . isEmpty ( this . state . notifications ) ;
4861
4962 if ( this . state . errors ) {
50- wrapperClass += ' errored' ;
5163 errors = (
5264 < div >
5365 < h3 > Oops something went wrong.</ h3 >
@@ -56,8 +68,7 @@ var Notifications = React.createClass({
5668 </ div >
5769 ) ;
5870 } else {
59- if ( _ . isEmpty ( this . state . notifications ) ) {
60- wrapperClass += ' all-read' ;
71+ if ( notificationsEmpty ) {
6172 notifications = (
6273 < div >
6374 < h2 > There are no notifications for you.</ h2 >
@@ -66,17 +77,38 @@ var Notifications = React.createClass({
6677 </ div >
6778 ) ;
6879 } else {
69- notifications = (
70- this . state . notifications . map ( function ( obj ) {
71- var repoFullName = obj [ 0 ] . repository . full_name ;
72- return < Repository repo = { obj } repoName = { repoFullName } key = { repoFullName } /> ;
73- } )
74- ) ;
80+ if ( this . state . searchTerm ) {
81+ notifications = _ . filter ( this . state . notifications , this . matchesSearchTerm ) ;
82+ } else {
83+ notifications = this . state . notifications ;
84+ }
85+
86+ if ( notifications . length ) {
87+ notifications = (
88+ notifications . map ( function ( obj ) {
89+ var repoFullName = obj [ 0 ] . repository . full_name ;
90+ return < Repository repo = { obj } repoName = { repoFullName } key = { repoFullName } /> ;
91+ } )
92+ ) ;
93+ } else {
94+ notificationsEmpty = true ;
95+ errors = (
96+ < div >
97+ < h3 > No Search Results.</ h3 >
98+ < h4 > No Organisations or Repositories match your search term.</ h4 >
99+ < img className = 'img-responsive emoji' src = 'images/all-read.png' />
100+ </ div >
101+ ) ;
102+ }
75103 }
76104 }
77105
78106 return (
79- < div className = { wrapperClass } >
107+ < div className = {
108+ wrapperClass +
109+ ( this . state . errors ? ' errored' : '' ) +
110+ ( notificationsEmpty ? ' all-read' : '' )
111+ } >
80112 < Loading className = 'loading-container' shouldShow = { this . state . loading } >
81113 < div className = 'loading-text' > working on it</ div >
82114 </ Loading >
0 commit comments