1
1
import React from 'react' ;
2
+ import { useEffect } from 'react' ;
2
3
import PropTypes from 'prop-types' ;
3
4
import { Link , useLocation , useParams } from 'react-router-dom' ;
4
5
import { useOnline } from 'rooks' ;
@@ -177,7 +178,7 @@ function handleRefreshSource({ event, source, setLoadingState, setNavExpanded, r
177
178
} ) ;
178
179
}
179
180
180
- export function EntriesPage ( { entries, hasMore, loadingState, setLoadingState, selectedEntry, expandedEntries, setNavExpanded, navSourcesExpanded, reload } ) {
181
+ export function EntriesPage ( { entries, hasMore, loadingState, setLoadingState, selectedEntry, expandedEntries, setNavExpanded, navSourcesExpanded, reload, unreadItemsCount , setTitle } ) {
181
182
const allowedToUpdate = useAllowedToUpdate ( ) ;
182
183
const allowedToWrite = useAllowedToWrite ( ) ;
183
184
const configuration = React . useContext ( ConfigurationContext ) ;
@@ -190,6 +191,18 @@ export function EntriesPage({ entries, hasMore, loadingState, setLoadingState, s
190
191
return queryString . get ( 'search' ) ?? '' ;
191
192
} , [ location . search ] ) ;
192
193
194
+ useEffect ( ( ) => {
195
+ if ( unreadItemsCount > 0 ) {
196
+ setTitle ( configuration . htmlTitle + ' (' + unreadItemsCount + ')' ) ;
197
+ } else {
198
+ setTitle ( configuration . htmlTitle ) ;
199
+ }
200
+
201
+ return ( ) => {
202
+ setTitle ( null ) ;
203
+ } ;
204
+ } , [ configuration . htmlTitle , setTitle , unreadItemsCount ] ) ;
205
+
193
206
const params = useParams ( ) ;
194
207
const currentTag = params . category ?. startsWith ( 'tag-' ) ? params . category . replace ( / ^ t a g - / , '' ) : null ;
195
208
const currentSource = params . category ?. startsWith ( 'source-' ) ? parseInt ( params . category . replace ( / ^ s o u r c e - / , '' ) , 10 ) : null ;
@@ -417,6 +430,8 @@ EntriesPage.propTypes = {
417
430
setNavExpanded : PropTypes . func . isRequired ,
418
431
navSourcesExpanded : PropTypes . bool . isRequired ,
419
432
reload : PropTypes . func . isRequired ,
433
+ setTitle : PropTypes . func . isRequired ,
434
+ unreadItemsCount : PropTypes . number . isRequired ,
420
435
} ;
421
436
422
437
const initialState = {
@@ -1018,6 +1033,8 @@ export default class StateHolder extends React.Component {
1018
1033
setNavExpanded = { this . props . setNavExpanded }
1019
1034
navSourcesExpanded = { this . props . navSourcesExpanded }
1020
1035
reload = { this . reload }
1036
+ setTitle = { this . props . setTitle }
1037
+ unreadItemsCount = { this . props . unreadItemsCount }
1021
1038
/>
1022
1039
) ;
1023
1040
}
@@ -1029,4 +1046,6 @@ StateHolder.propTypes = {
1029
1046
match : PropTypes . object . isRequired ,
1030
1047
setNavExpanded : PropTypes . func . isRequired ,
1031
1048
navSourcesExpanded : PropTypes . bool . isRequired ,
1049
+ setTitle : PropTypes . func . isRequired ,
1050
+ unreadItemsCount : PropTypes . number . isRequired ,
1032
1051
} ;
0 commit comments