11// @flow
22
3- import type { FlamechartData , ReactProfilerDataV2 } from './types' ;
3+ import type {
4+ FlamechartData ,
5+ ReactProfilerData ,
6+ ReactProfilerDataV2 ,
7+ } from './types' ;
48
59import React , { useState , useCallback } from 'react' ;
610import { unstable_batchedUpdates } from 'react-dom' ;
@@ -11,15 +15,19 @@ import ImportPage from './ImportPage';
1115import CanvasPage from './CanvasPage' ;
1216
1317export default function App ( ) {
14- const [ profilerData , setProfilerData ] = useState < ReactProfilerDataV2 | null > (
18+ const [ profilerData , setProfilerData ] = useState < ReactProfilerData | null > (
1519 null ,
1620 ) ;
21+ const [
22+ profilerDataV2 ,
23+ setProfilerDataV2 ,
24+ ] = useState < ReactProfilerDataV2 | null > ( null ) ;
1725 const [ flamechart , setFlamechart ] = useState < FlamechartData | null > ( null ) ;
1826 const [ schedulerCanvasHeight , setSchedulerCanvasHeight ] = useState < number > ( 0 ) ;
1927
2028 const handleDataImported = useCallback (
2129 (
22- importedProfilerData : ReactProfilerDataV2 ,
30+ importedProfilerData : ReactProfilerData ,
2331 importedFlamechart : FlamechartData ,
2432 ) => {
2533 unstable_batchedUpdates ( ( ) => {
@@ -34,15 +42,39 @@ export default function App() {
3442 } ,
3543 ) ;
3644
37- if ( profilerData && flamechart ) {
45+ // TODO: Migrate and completely remove V2 stuff
46+ const handleDataImportedV2 = useCallback (
47+ (
48+ importedProfilerData : ReactProfilerDataV2 ,
49+ importedFlamechart : FlamechartData ,
50+ ) => {
51+ unstable_batchedUpdates ( ( ) => {
52+ setSchedulerCanvasHeight (
53+ REACT_PRIORITIES . reduce ( ( height , priority ) => {
54+ return height + getPriorityHeight ( importedProfilerData , priority ) ;
55+ } , 0 ) ,
56+ ) ;
57+ setProfilerDataV2 ( importedProfilerData ) ;
58+ setFlamechart ( importedFlamechart ) ;
59+ } ) ;
60+ } ,
61+ ) ;
62+
63+ if ( profilerData && profilerDataV2 && flamechart ) {
3864 return (
3965 < CanvasPage
4066 profilerData = { profilerData }
67+ profilerDataV2 = { profilerDataV2 }
4168 flamechart = { flamechart }
4269 schedulerCanvasHeight = { schedulerCanvasHeight }
4370 />
4471 ) ;
4572 } else {
46- return < ImportPage onDataImported = { handleDataImported } /> ;
73+ return (
74+ < ImportPage
75+ onDataImported = { handleDataImported }
76+ onDataImportedV2 = { handleDataImportedV2 }
77+ />
78+ ) ;
4779 }
4880}
0 commit comments