Skip to content

Commit 24f9761

Browse files
author
Vic G
authored
Merge pull request #1526 from ThomasKranitsas/auto-update-notif
Set interval to update notifications
2 parents 5ed22f6 + db96642 commit 24f9761

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/components/NotificationsDropdown/NotificationsDropdownContainer.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ import NotificationsSection from '../NotificationsSection/NotificationsSection'
1212
import NotificationsEmpty from '../NotificationsEmpty/NotificationsEmpty'
1313
import NotificationsDropdownHeader from '../NotificationsDropdownHeader/NotificationsDropdownHeader'
1414
import NotificationsDropdown from './NotificationsDropdown'
15-
import { NOTIFCATIONS_DROPDOWN_PER_SOURCE, NOTIFCATIONS_DROPDOWN_MAX_TOTAL } from '../../config/constants'
15+
import { NOTIFCATIONS_DROPDOWN_PER_SOURCE, NOTIFCATIONS_DROPDOWN_MAX_TOTAL, REFRESH_NOTIFICATIONS_INTERVAL } from '../../config/constants'
1616
import './NotificationsDropdown.scss'
1717

1818
class NotificationsDropdownContainer extends React.Component {
1919

2020
componentDidMount() {
2121
this.props.getNotifications()
22+
this.autoRefreshNotifications = setInterval(() => this.props.getNotifications(), REFRESH_NOTIFICATIONS_INTERVAL)
23+
}
24+
25+
componentWillUnmount() {
26+
clearInterval(this.autoRefreshNotifications)
2227
}
2328

2429
// Make sure the body isn't scrollable when mouse is over the drop-down menu

src/config/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ export const SORT_OPTIONS = [
352352
]
353353

354354
// Notifications
355+
export const REFRESH_NOTIFICATIONS_INTERVAL = 1000 * 60 * 1 // 1 minute interval
355356
export const NOTIFCATIONS_DROPDOWN_PER_SOURCE = 2
356357
export const NOTIFCATIONS_DROPDOWN_MAX_TOTAL = 10
357358

@@ -366,4 +367,4 @@ export const SCROLL_TO_DURATION = 500 // ms
366367
export const MAX_USERNAME_LENGTH = 15
367368
export const EMAIL_AVAILABILITY_CHECK_DEBOUNCE = 300 /* in ms */
368369
export const PASSWORD_MIN_LENGTH = 8
369-
export const PASSWORD_REG_EXP = /^(?=.*[a-z])(?=.*[^a-z]).+$/i
370+
export const PASSWORD_REG_EXP = /^(?=.*[a-z])(?=.*[^a-z]).+$/i

src/routes/notifications/containers/NotificationsContainer.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ import NotificationsEmpty from '../../../components/NotificationsEmpty/Notificat
1515
import spinnerWhileLoading from '../../../components/LoadingSpinner'
1616
import { getNotificationsFilters, splitNotificationsBySources, filterReadNotifications } from '../helpers/notifications'
1717
import { requiresAuthentication } from '../../../components/AuthenticatedComponent'
18+
import { REFRESH_NOTIFICATIONS_INTERVAL } from '../../../config/constants'
1819
import './NotificationsContainer.scss'
1920

2021
class NotificationsContainer extends React.Component {
2122
componentDidMount() {
2223
document.title = 'Notifications - TopCoder'
2324
this.props.getNotifications()
25+
this.autoRefreshNotifications = setInterval(() => this.props.getNotifications(), REFRESH_NOTIFICATIONS_INTERVAL)
26+
}
27+
28+
componentWillUnmount() {
29+
clearInterval(this.autoRefreshNotifications)
2430
}
2531

2632
render() {

0 commit comments

Comments
 (0)