summaryrefslogtreecommitdiffstats
path: root/src/components/Content
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <tom@vanderlee.io>2022-01-19 21:27:21 +0100
committerGravatar Tom van der Lee <tom@vanderlee.io>2022-01-25 22:06:58 +0100
commit51a2ac628822e96459b3d570eada953ac8927d43 (patch)
tree7bb3766580f0fe88d5ff5786e1ad5a640704cc8d /src/components/Content
parent1af1996d38ceaf2b96dcd5b1a6ee0a9c158022f8 (diff)
downloadclient-51a2ac628822e96459b3d570eada953ac8927d43.tar.gz
client-51a2ac628822e96459b3d570eada953ac8927d43.tar.bz2
client-51a2ac628822e96459b3d570eada953ac8927d43.zip
Added boostrap
Diffstat (limited to 'src/components/Content')
-rw-r--r--src/components/Content/Content.tsx74
1 files changed, 58 insertions, 16 deletions
diff --git a/src/components/Content/Content.tsx b/src/components/Content/Content.tsx
index a7b5949..cb5e6bc 100644
--- a/src/components/Content/Content.tsx
+++ b/src/components/Content/Content.tsx
@@ -13,6 +13,21 @@ import {
13} from "react"; 13} from "react";
14import ReactJson from 'react-json-view'; 14import ReactJson from 'react-json-view';
15import styles from './Content.module.scss'; 15import styles from './Content.module.scss';
16import {Col, Container, Row} from "react-bootstrap";
17
18function getHeader(headers: { [key: string]: string }, key: string, unit?: string): string | null {
19 console.log(headers, key)
20 try {
21 const [_, value] = Object
22 .entries(headers)
23 .find(([headerKey]) => headerKey.toLowerCase() === key.toLowerCase())
24 return unit !== undefined
25 ? `${value}${unit}`
26 : value
27 } catch {
28 return null;
29 }
30}
16 31
17interface ContentProps { 32interface ContentProps {
18 data: RequestPayload | ResponsePayload 33 data: RequestPayload | ResponsePayload
@@ -20,17 +35,29 @@ interface ContentProps {
20 raw?: boolean 35 raw?: boolean
21} 36}
22 37
23export default function Content({ raw, setRaw, ...props }: ContentProps): JSX.Element { 38export default function Content({ raw, setRaw, data }: ContentProps): JSX.Element {
24 return ( 39 return (
25 <div className={styles.content}> 40 <>
26 <div className={styles.header}> 41 <Container fluid className="border-bottom">
27 <input id='raw' type='checkbox' checked={raw} onChange={() => setRaw(!raw)}/> 42 <Row className="py-3">
28 <label htmlFor='raw'>Raw</label> 43 <Col>
29 </div> 44 <input id='raw' type='checkbox' checked={raw} onChange={() => setRaw(!raw)}/>
30 <div className={styles.body}> 45 <label htmlFor='raw' className="ps-1">Raw</label>
46 </Col>
47 <Col xs="auto">
48 {
49 [
50 getHeader(data.headers, 'content-length', 'bytes'),
51 getHeader(data.headers, 'content-type'),
52 ].filter(x => x !== null).join('; ')
53 }
54 </Col>
55 </Row>
56 </Container>
57 <Row>
31 {(() => { 58 {(() => {
32 try { 59 try {
33 return ContentBody({ ...props, raw }) 60 return ContentBody({ data, raw })
34 } catch { 61 } catch {
35 return ( 62 return (
36 <div className={styles.renderError}> 63 <div className={styles.renderError}>
@@ -40,8 +67,28 @@ export default function Content({ raw, setRaw, ...props }: ContentProps): JSX.El
40 ) 67 )
41 } 68 }
42 })()} 69 })()}
43 </div> 70 </Row>
44 </div> 71 </>
72 // <div className={styles.content}>
73 // <div className={styles.header}>
74 // <input id='raw' type='checkbox' checked={raw} onChange={() => setRaw(!raw)}/>
75 // <label htmlFor='raw'>Raw</label>
76 // </div>
77 // <div className={styles.body}>
78 // {(() => {
79 // try {
80 // return ContentBody({ ...props, raw })
81 // } catch {
82 // return (
83 // <div className={styles.renderError}>
84 // <p>Body could not be rendered</p>
85 // <a onClick={() => setRaw(true)}>View raw</a>
86 // </div>
87 // )
88 // }
89 // })()}
90 // </div>
91 // </div>
45 ) 92 )
46}; 93};
47 94
@@ -51,12 +98,7 @@ function ContentBody({ data, raw = false }: Omit<ContentProps, 'setRaw'>) {
51 return ''; 98 return '';
52 } 99 }
53 100
54 const [_, type] = ( 101 const type = getHeader(data.headers, 'content-type');
55 Object
56 .entries(data.headers)
57 .find(([key]) => key.toLowerCase() === 'content-type')
58 );
59
60 return type.toLowerCase().split(';')[0]; 102 return type.toLowerCase().split(';')[0];
61 }, [data, raw]); 103 }, [data, raw]);
62 104