11import { useLocation } from "react-router"
22import { useContext , useMemo } from "react"
33
4- import { Tabs , Tab , TabTitleText } from "@patternfly/react-core"
5-
64import Code from "./view/Code"
75import Transcript from "./view/transcript/Transcript"
86import DarkModeContext from "./DarkModeContext"
@@ -14,7 +12,7 @@ import "./Viewer.css"
1412/** This is the main view component */
1513export default function Viewer ( { value } : { value : string } ) {
1614 // We will use this to find the current active tab (below)
17- let { hash : activeTab } = useLocation ( )
15+ const { hash : activeTab } = useLocation ( )
1816
1917 // DarkMode state
2018 const darkMode = useContext ( DarkModeContext )
@@ -28,45 +26,17 @@ export default function Viewer({ value }: { value: string }) {
2826 return "Invalid trace content"
2927 }
3028
31- // Note: please keep eventKey===href
32- const tabs = [
33- < Tab
34- key = "#transcript"
35- href = "#transcript"
36- eventKey = "#transcript"
37- className = "pdl-viewer-tab"
38- title = { < TabTitleText > Transcript</ TabTitleText > }
39- >
40- < Transcript data = { data } />
41- </ Tab > ,
42- < Tab
43- key = "#source"
44- href = "#source"
45- eventKey = "#source"
46- className = "pdl-viewer-tab"
47- title = { < TabTitleText > Source</ TabTitleText > }
48- >
49- < Code block = { data } darkMode = { darkMode } limitHeight = { false } />
50- </ Tab > ,
51- < Tab
52- key = "#raw"
53- href = "#raw"
54- eventKey = "#raw"
55- className = "pdl-viewer-tab"
56- title = { < TabTitleText > Raw Trace</ TabTitleText > }
57- >
58- < Code block = { data } darkMode = { darkMode } limitHeight = { false } raw />
59- </ Tab > ,
60- ]
61-
62- if ( ! tabs . find ( ( tab ) => tab . props . href === activeTab ) ) {
63- // User provided bogus hash, default to first tab
64- activeTab = tabs [ 0 ] . props . href
65- }
66-
6729 return (
68- < Tabs activeKey = { activeTab } component = "nav" >
69- { tabs }
70- </ Tabs >
30+ < >
31+ < section hidden = { activeTab !== "#source" } >
32+ < Code block = { data } darkMode = { darkMode } limitHeight = { false } />
33+ </ section >
34+ < section hidden = { activeTab !== "raw" } >
35+ < Code block = { data } darkMode = { darkMode } limitHeight = { false } raw />
36+ </ section >
37+ < section hidden = { activeTab === "#source" || activeTab === "#raw" } >
38+ < Transcript data = { data } />
39+ </ section >
40+ </ >
7141 )
7242}
0 commit comments