Feat: notification center polling, prevent page moving when opening it

This commit is contained in:
csrapr 2021-02-15 16:09:07 +00:00 committed by Josh Harvey
parent dee7dde195
commit b89ba7d939
3 changed files with 16 additions and 5 deletions

View file

@ -53,7 +53,9 @@ const CLEAR_ALL_NOTIFICATIONS = gql`
const NotificationCenter = ({ close, notifyUnread }) => { const NotificationCenter = ({ close, notifyUnread }) => {
const classes = useStyles() const classes = useStyles()
const { data, loading } = useQuery(GET_NOTIFICATIONS) const { data, loading } = useQuery(GET_NOTIFICATIONS, {
pollInterval: 60000
})
const [showingUnread, setShowingUnread] = useState(false) const [showingUnread, setShowingUnread] = useState(false)
const machines = R.compose( const machines = R.compose(
R.map(R.prop('name')), R.map(R.prop('name')),

View file

@ -4,7 +4,8 @@ import Popper from '@material-ui/core/Popper'
import { makeStyles } from '@material-ui/core/styles' import { makeStyles } from '@material-ui/core/styles'
import classnames from 'classnames' import classnames from 'classnames'
import gql from 'graphql-tag' import gql from 'graphql-tag'
import React, { memo, useState } from 'react' import * as R from 'ramda'
import React, { memo, useState, useEffect } from 'react'
import { NavLink, useHistory } from 'react-router-dom' import { NavLink, useHistory } from 'react-router-dom'
import NotificationCenter from 'src/components/NotificationCenter' import NotificationCenter from 'src/components/NotificationCenter'
@ -56,14 +57,22 @@ const Subheader = ({ item, classes }) => {
) )
} }
const notNil = R.compose(R.not, R.isNil)
const Header = memo(({ tree }) => { const Header = memo(({ tree }) => {
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const [anchorEl, setAnchorEl] = React.useState(null) const [anchorEl, setAnchorEl] = React.useState(null)
const [active, setActive] = useState() const [active, setActive] = useState()
const { data, refetch } = useQuery(HAS_UNREAD) const { data, refetch } = useQuery(HAS_UNREAD, { pollInterval: 60000 })
const hasUnread = data?.hasUnreadNotifications ?? false const [hasUnread, setHasUnread] = useState(false)
const history = useHistory() const history = useHistory()
const classes = useStyles() const classes = useStyles()
useEffect(() => {
if (data?.hasUnreadNotifications) return setHasUnread(true)
// if not true, make sure it's false and not undefined
if (notNil(data?.hasUnreadNotifications)) return setHasUnread(false)
}, [data])
const onPaired = machine => { const onPaired = machine => {
setOpen(false) setOpen(false)

View file

@ -13,7 +13,7 @@ export default {
}, },
'.root-notifcenter-open': { '.root-notifcenter-open': {
// for when notification center is open // for when notification center is open
overflowY: 'scroll', overflowY: 'auto',
position: 'absolute', position: 'absolute',
top: 0, top: 0,
bottom: 0, bottom: 0,