Simplify EventStream handling

This commit is contained in:
Deluan
2023-05-17 11:22:36 -04:00
parent 6bee4ed147
commit 4296741ec0
5 changed files with 47 additions and 90 deletions
+21 -1
View File
@@ -1,5 +1,11 @@
import * as React from 'react'
import { Children, cloneElement, isValidElement, useState } from 'react'
import {
Children,
cloneElement,
isValidElement,
useEffect,
useState,
} from 'react'
import PropTypes from 'prop-types'
import { useTranslate, useGetIdentity } from 'react-admin'
import {
@@ -16,6 +22,9 @@ import {
import { makeStyles } from '@material-ui/core/styles'
import AccountCircle from '@material-ui/icons/AccountCircle'
import config from '../config'
import authProvider from '../authProvider'
import { startEventStream } from '../eventStream'
import { useDispatch } from 'react-redux'
const useStyles = makeStyles((theme) => ({
user: {},
@@ -40,8 +49,19 @@ const UserMenu = (props) => {
const translate = useTranslate()
const { loaded, identity } = useGetIdentity()
const classes = useStyles(props)
const dispatch = useDispatch()
const { children, label, icon, logout } = props
useEffect(() => {
if (config.devActivityPanel) {
authProvider
.checkAuth()
.then(() => startEventStream(dispatch))
.catch(() => {})
}
}, [])
if (!logout && !children) return null
const open = Boolean(anchorEl)