Skip to content

Commit 7eb33d9

Browse files
Stop polling if not on messages screen
1 parent 3d48b3f commit 7eb33d9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/components/MessageComponents/Messages/Messages.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,27 @@ function formatDate(dateMilliseconds) {
3232
return strDate + " "+strTime
3333
}
3434

35-
36-
3735
const Messages = props => {
3836
// NOTE on React Hook: useState is used by React Hooks to create state variables and
3937
// setter function for component
4038
const { msgAlert } = props
4139
const [messages, setMessages] = useState([])
4240

4341
function pollForNotifications() {
42+
43+
if (window.location.href.match(/messages$/) === null) {
44+
return
45+
}
4446
getMessageNotifications(props) // returns promise to get messages
4547
.then((error,res) => {
4648
getMessages(props) // returns promise to get messages
4749
.then(res => {
48-
4950
setMessages(res.data)
5051
setTimeout(pollForNotifications,3000)
5152
})
5253
})
5354
.catch((error,res) => {
55+
console.log(window.location)
5456
setTimeout(pollForNotifications,3000)
5557
// displayUnexpectedFailure(msgAlert, error, 'fetching')
5658
})

0 commit comments

Comments
 (0)