@@ -9,18 +9,12 @@ import {
99 useTheme ,
1010} from "@mui/material"
1111import Grid from "@mui/material/Grid"
12- import { useAtomValue } from "jotai"
13- import React , { FC , useEffect , useMemo } from "react"
12+ import React , { FC , useMemo } from "react"
1413import { Link , useParams } from "react-router-dom"
1514
16- import { actionCreator } from "../action"
1715import { useConstants } from "../constantsProvider"
18- import {
19- reloadIntervalState ,
20- useStudyDetailValue ,
21- useStudyIsPreferential ,
22- useStudyName ,
23- } from "../state"
16+ import { useLatestStudyDetail } from "../hooks/useLatestStudyDetail"
17+ import { useStudyIsPreferential , useStudyName } from "../state"
2418import { AppDrawer , PageId } from "./AppDrawer"
2519import { Contour } from "./GraphContour"
2620import { GraphEdf } from "./GraphEdf"
@@ -54,45 +48,21 @@ export const StudyDetail: FC<{
5448 const { url_prefix } = useConstants ( )
5549
5650 const theme = useTheme ( )
57- const action = actionCreator ( )
5851 const studyId = useURLVars ( )
59- const studyDetail = useStudyDetailValue ( studyId )
60- const reloadInterval = useAtomValue ( reloadIntervalState )
6152 const studyName = useStudyName ( studyId )
6253 const isPreferential = useStudyIsPreferential ( studyId )
6354
64- const title =
65- studyName !== null ? `${ studyName } (id=${ studyId } )` : `Study #${ studyId } `
66-
67- useEffect ( ( ) => {
68- action . updateStudyDetail ( studyId )
69- } , [ ] )
70-
71- useEffect ( ( ) => {
72- if ( reloadInterval < 0 ) {
73- return
74- }
75- const nTrials = studyDetail ? studyDetail . trials . length : 0
76- let interval = reloadInterval * 1000
77-
55+ const studyDetail = useLatestStudyDetail ( {
56+ studyId : studyId ,
7857 // For Human-in-the-loop Optimization, the interval is set to 2 seconds
7958 // when the number of trials is small, and the page is "trialList" or top page of preferential.
80- if (
59+ shortInterval :
8160 ( ! isPreferential && page === "trialList" ) ||
82- ( isPreferential && page === "top" )
83- ) {
84- if ( nTrials < 100 ) {
85- interval = 2000
86- } else if ( nTrials < 500 ) {
87- interval = 5000
88- }
89- }
61+ ( ! ! isPreferential && page === "top" ) ,
62+ } )
9063
91- const intervalId = setInterval ( ( ) => {
92- action . updateStudyDetail ( studyId )
93- } , interval )
94- return ( ) => clearInterval ( intervalId )
95- } , [ reloadInterval , studyDetail , page ] )
64+ const title =
65+ studyName !== null ? `${ studyName } (id=${ studyId } )` : `Study #${ studyId } `
9666
9767 let content = null
9868 if ( page === "top" ) {
0 commit comments