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

fix: when loading a dashboard set the loaded flag after the fetch so state doesn't toggle back and forth #1975

Merged
merged 2 commits into from
Sep 14, 2021
Merged
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
13 changes: 5 additions & 8 deletions src/pages/view/ViewDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ViewDashboard = props => {
const [loaded, setLoaded] = useState(false)
const [loadFailed, setLoadFailed] = useState(false)
const { online } = useOnlineStatus()
const { isCached, recordingState } = useCacheableSection(props.requestedId)
const { isCached } = useCacheableSection(props.requestedId)

useEffect(() => {
setHeaderbarVisible(true)
Expand Down Expand Up @@ -76,9 +76,8 @@ const ViewDashboard = props => {
}, 500)

try {
setLoaded(true)
await props.fetchDashboard(props.requestedId, props.username)

setLoaded(true)
setLoadFailed(false)
setLoadingMessage(null)
clearTimeout(alertTimeout)
Expand All @@ -93,16 +92,14 @@ const ViewDashboard = props => {

const requestedIsAvailable = online || isCached
const switchingDashboard = props.requestedId !== props.currentId
if (
requestedIsAvailable &&
(recordingState === 'recording' || !loaded)
) {

if (requestedIsAvailable && !loaded) {
loadDashboard()
} else if (!requestedIsAvailable && switchingDashboard) {
setLoaded(false)
props.setSelectedAsOffline(props.requestedId, props.username)
}
}, [props.requestedId, props.currentId, loaded, recordingState, online])
}, [props.requestedId, props.currentId, loaded, online])

const onExpandedChanged = expanded => setControlbarExpanded(expanded)

Expand Down