Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#316 Fix cursor visibility on monitor fullscreen view #319

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/client/monitor/Monitor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export function Monitor({fullScreen, requestFullScreen}: MonitorProps): ReactEle

const [loaded, setLoaded] = useState(false)
const [projects, setProjects] = useState<Projects>([])
const [monitorClassNames, setMonitorClassNames] = useState({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to store all of this as state. You only really need to keep track of the inactive boolean. Also doing this means the fullscreen style will never get toggled, as the state is only initialised on the first render using the fullscreen boolean.

[styles.monitor]: true,
[styles.inactive]: true,
[styles.fullscreen]: fullScreen
})

useEffect(() => {
requestFullScreen(true)
Expand Down Expand Up @@ -65,12 +70,14 @@ export function Monitor({fullScreen, requestFullScreen}: MonitorProps): ReactEle
const traysAdded = !isEmpty(trays)
const success = isEmpty(projects)

const monitorClassNames = cn(styles.monitor, {
[styles.fullscreen]: fullScreen
})
document.onmousemove = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using document.onmousemove is bad, it breaks React encapsulation meaning the handler isn't going to be cleaned up when the component unmounts. Which means a ton of warnings would be generated on every other page as you'd be trying to update state on an unmounted component!

setMonitorClassNames({
...monitorClassNames, [styles.inactive]: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is ever setting the inactive style back to true, so once the mouse is moved the mouse cursor will never be hidden again.

})
}

return (
<div className={monitorClassNames}>
<div className={cn({...monitorClassNames})}>
<Title>Monitor</Title>
{!traysAdded && (
<SuccessMessage message='Add a CI server via the tracking page to start monitoring'/>
Expand Down
4 changes: 4 additions & 0 deletions src/client/monitor/monitor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
}

.fullscreen {
cursor: default;
}

.inactive {
cursor: none;
}