forked from testing-library/testing-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
85 lines (73 loc) · 2.09 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React, { useState, useEffect } from 'react';
import debounce from 'lodash/debounce';
import Editor from './Editor';
import ElementInfo from './ElementInfo';
import Header from './Header';
import Footer from './Footer';
import parser from '../parser';
import { initialValues } from '../constants';
import { useAppContext } from './Context';
import HtmlPreview from './HtmlPreview';
import state from '../lib/state';
import ErrorBox from './ErrorBox';
const savedState = state.load();
function App() {
const [html, setHtml] = useState(savedState.html || initialValues.html);
const [js, setJs] = useState(savedState.js || initialValues.js);
const {
htmlEditorRef,
htmlPreviewRef,
jsEditorRef,
parsed,
setParsed,
} = useAppContext();
useEffect(() => {
const parsed = parser.parse(htmlPreviewRef.current, js);
setParsed(parsed);
state.save({ html, js });
state.updateTitle(parsed.expression?.expression);
}, [html, js, htmlPreviewRef.current]);
return (
<div>
<div className="mb-8">
<Header />
</div>
<div className="space-y-8 px-8 pb-8">
<div className="editor">
<Editor
mode="html"
initialValue={html}
onChange={setHtml}
ref={htmlEditorRef}
/>
<HtmlPreview html={html} ref={htmlPreviewRef} />
</div>
<div className="editor">
<div>
<Editor
mode="javascript"
initialValue={js}
onChange={setJs}
ref={jsEditorRef}
/>
<div className="output">
<span className="text-blue-600">> </span>
{parsed.error
? `Error: ${parsed.error}`
: parsed.text || 'undefined'}
</div>
</div>
{parsed.error ? (
<ErrorBox caption={parsed.error} body={parsed.errorBody} />
) : (
<ElementInfo />
)}
</div>
</div>
<div className="mx-8 pb-8">
<Footer />
</div>
</div>
);
}
export default App;