@@ -6,25 +6,21 @@ import { BackendMeta, Content, ContentMeta, Insight } from "../models/models";
6
6
import containerStyles from "../styles/components/container.module.scss" ;
7
7
import contentStyles from "../styles/components/content.module.scss" ;
8
8
import { mergeBackendMeta } from "../utils/insight" ;
9
- import { Accordion } from "./accordion" ;
9
+ import { ActionButton } from "./actionbutton" ;
10
+ import { PreContent } from "./precontent" ;
10
11
11
12
export const ContentComponent : React . FunctionComponent < {
12
13
content : Content ;
13
14
insight : Insight | null ;
14
15
} > = ( { content, insight } ) => {
15
- const [ isOpen , setIsOpen ] = useState ( false ) ;
16
- const [ isFetchedBackendMeta , setIsFetchedBackendMeta ] = useState ( false ) ;
17
- const [ metaAndInsight , setData ] = useState ( null ) ;
16
+ const [ isAttributesOpen , setIsAttributesOpen ] = useState ( false ) ;
17
+ const [ attributes , setAttributes ] = useState ( null ) ;
18
18
19
- const fetchBackendMetaData = async ( ) => {
20
- const response : Response = await fetchSystemMetadata ( ) ;
21
- let ins = insight ;
22
- if ( response . status === 200 ) {
23
- const bm = ( await response . json ( ) ) as BackendMeta ;
24
- ins = mergeBackendMeta ( insight , bm ) ;
25
- setIsFetchedBackendMeta ( true ) ;
26
- }
19
+ const [ isMetadataOpen , setIsMetadataOpen ] = useState ( false ) ;
20
+ const [ isFetchedBackendMeta , setIsFetchedBackendMeta ] = useState ( false ) ;
21
+ const [ metadata , setMetaData ] = useState ( null ) ;
27
22
23
+ const formatAttributes = ( ) => {
28
24
let actualRobotsMeta = "" ;
29
25
let maybeRobotsMeta = document . querySelector ( 'meta[name="robots"]' ) ;
30
26
if ( maybeRobotsMeta ) {
@@ -57,37 +53,45 @@ export const ContentComponent: React.FunctionComponent<{
57
53
updatedAt : content . updatedAt
58
54
} ;
59
55
60
- setData (
61
- JSON . stringify (
62
- {
63
- attributes : meta ,
64
- insight : ins
65
- } ,
66
- null ,
67
- 2
68
- )
69
- ) ;
56
+ setAttributes ( JSON . stringify ( { attributes : meta } , null , 2 ) ) ;
57
+ } ;
58
+
59
+ const fetchBackendMetaData = async ( ) => {
60
+ const response : Response = await fetchSystemMetadata ( ) ;
61
+ let ins = insight ;
62
+ if ( response . status === 200 ) {
63
+ const bm = ( await response . json ( ) ) as BackendMeta ;
64
+ ins = mergeBackendMeta ( insight , bm ) ;
65
+ setIsFetchedBackendMeta ( true ) ;
66
+ }
67
+
68
+ setMetaData ( JSON . stringify ( { insight : ins } , null , 2 ) ) ;
69
+ } ;
70
+
71
+ const toggleAttributes = ( ) => {
72
+ formatAttributes ( ) ;
73
+ setIsMetadataOpen ( false ) ;
74
+ setIsAttributesOpen ( ! isAttributesOpen ) ;
70
75
} ;
71
76
72
- const toggle = ( ) => {
77
+ const toggleMetadata = ( ) => {
73
78
if ( ! isFetchedBackendMeta ) {
74
79
fetchBackendMetaData ( ) ;
75
80
setIsFetchedBackendMeta ( true ) ;
76
81
}
77
- setIsOpen ( ! isOpen ) ;
82
+ setIsAttributesOpen ( false ) ;
83
+ setIsMetadataOpen ( ! isMetadataOpen ) ;
78
84
} ;
79
85
80
86
return (
81
87
< article className = { contentStyles . content } >
82
88
< div className = { containerStyles . container } >
83
- < div className = { `${ contentStyles [ "accordion-wrap" ] } ` } >
84
- < Accordion
85
- open = { isOpen }
86
- onclick = { toggle }
87
- title = "Attributes / Insight ▼"
88
- content = { metaAndInsight }
89
- />
89
+ < div className = { `${ contentStyles [ "actionbutton-wrap" ] } ` } >
90
+ < ActionButton onclick = { toggleAttributes } title = "Attributes ▼" />
91
+ < ActionButton onclick = { toggleMetadata } title = "Insight ▼" />
90
92
</ div >
93
+ { isAttributesOpen && < PreContent content = { attributes } /> }
94
+ { isMetadataOpen && < PreContent content = { metadata } /> }
91
95
< div className = { `${ contentStyles [ "words" ] } ` } >
92
96
{ content . length . toLocaleString ( ) } words
93
97
</ div >
0 commit comments