Skip to content

Commit 0e465db

Browse files
committed
feat: make sand-box read titles from global
1 parent 0f02948 commit 0e465db

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/sand-box.tsx

+22-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ const useWindowData = () => {
4545
const [leftJsonStr, setLeftJsonStr] = React.useState('{}')
4646
const [rightJsonStr, setRightJsonStr] = React.useState('{}')
4747
const [diffResult, setJYCMResult] = React.useState({});
48+
const [leftTitle, setLeftTitle] = React.useState('Left');
49+
const [rightTitle, setRightTitle] = React.useState('Right');
50+
4851

4952
const obData = React.useCallback(() => {
5053
// // @ts-ignore
@@ -53,6 +56,19 @@ const useWindowData = () => {
5356
safeJSONCallback(window.jycmLeftJsonStr, v => setLeftJsonStr(v))
5457
// @ts-ignore
5558
safeJSONCallback(window.jycmRightJsonStr, v => setRightJsonStr(v))
59+
60+
// @ts-ignore
61+
if(window.jycmLeftTitle) {
62+
// @ts-ignore
63+
setLeftTitle(window.jycmLeftTitle)
64+
}
65+
66+
// @ts-ignore
67+
if(window.jycmRightTitle) {
68+
// @ts-ignore
69+
setRightTitle(window.c)
70+
}
71+
5672
// @ts-ignore
5773
if (window.diffResult && typeof window.diffResult === 'object') {
5874
// @ts-ignore
@@ -65,7 +81,9 @@ const useWindowData = () => {
6581
return {
6682
leftJsonStr,
6783
rightJsonStr,
68-
diffResult
84+
diffResult,
85+
leftTitle,
86+
rightTitle
6987
}
7088
}
7189

@@ -74,6 +92,8 @@ function SandBox() {
7492
leftJsonStr,
7593
rightJsonStr,
7694
diffResult,
95+
leftTitle,
96+
rightTitle
7797
} = useWindowData();
7898

7999
// use this can ave your time! see provider below
@@ -96,7 +116,7 @@ function SandBox() {
96116
{/* <JYCMRender leftTitle="BenchMark" rightTitle="Actual" /> */}
97117
<div style={{ display: "flex", alignItems: "center", height: "100%" }}>
98118
<div style={{ flexGrow: 1, height: "100%" }}>
99-
<JYCMRender leftTitle='Left' rightTitle='Right' />
119+
<JYCMRender leftTitle={leftTitle} rightTitle={rightTitle} />
100120
</div>
101121
<div style={{ flexBasis: "24%", height: '100%', display: "flex", flexDirection: "column" }}>
102122
<div style={{ textAlign: 'center', fontWeight: 700 }}>Diff Detail</div>

0 commit comments

Comments
 (0)