Skip to content

Commit 81f6f9b

Browse files
authored
Merge branch 'dev' into feat(web)/improve-voting-history-accordion-or-cards
2 parents a4b723b + b2eccc6 commit 81f6f9b

File tree

10 files changed

+1100
-334
lines changed

10 files changed

+1100
-334
lines changed

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"react-toastify": "^9.1.3",
108108
"react-use": "^17.4.3",
109109
"styled-components": "^5.3.11",
110+
"vanilla-jsoneditor": "^0.21.4",
110111
"viem": "^1.21.4",
111112
"wagmi": "^1.4.13"
112113
}

web/src/components/JSONEditor.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React, { useEffect, useRef } from "react";
2+
import styled, { css } from "styled-components";
3+
import { JSONEditor as Editor, JSONEditorPropsOptional } from "vanilla-jsoneditor";
4+
import { landscapeStyle } from "styles/landscapeStyle";
5+
6+
const Container = styled.div`
7+
width: 100%;
8+
height: calc(100vh - 180px);
9+
10+
--text-color: ${({ theme }) => theme.primaryText};
11+
--jse-text-readonly: ${({ theme }) => theme.primaryText};
12+
--jse-theme-color: ${({ theme }) => theme.primaryPurple};
13+
--jse-background-color: ${({ theme }) => theme.whiteBackground};
14+
--jse-panel-background: ${({ theme }) => theme.hoveredShadow};
15+
--jse-theme-color-highlight: ${({ theme }) => theme.lightPurple};
16+
--jse-value-color-string: ${({ theme }) => theme.primaryText};
17+
--jse-value-color-number: ${({ theme }) => theme.primaryBlue};
18+
--jse-value-color-null: ${({ theme }) => theme.error};
19+
--jse-main-border: 1px solid ${({ theme }) => theme.stroke};
20+
--jse-key-color: ${({ theme }) => theme.tint};
21+
--jse-value-color: ${({ theme }) => theme.success};
22+
--jse-delimiter-color: ${({ theme }) => theme.primaryText};
23+
.cm-gutter-lint {
24+
width: 0.6em;
25+
}
26+
${landscapeStyle(
27+
() => css`
28+
width: 30vw;
29+
height: calc(100vh - 300px);
30+
`
31+
)}
32+
`;
33+
34+
const JSONEditor = (props: JSONEditorPropsOptional) => {
35+
const refContainer = useRef(null);
36+
const refEditor = useRef<Editor | null>(null);
37+
38+
useEffect(() => {
39+
refEditor.current = new Editor({
40+
target: refContainer.current,
41+
props: {
42+
...props,
43+
},
44+
});
45+
46+
return () => {
47+
if (refEditor.current) {
48+
refEditor.current.destroy();
49+
refEditor.current = null;
50+
}
51+
};
52+
}, []);
53+
54+
useEffect(() => {
55+
if (refEditor.current) {
56+
refEditor.current.updateProps(props);
57+
}
58+
}, [props]);
59+
60+
return <Container ref={refContainer}></Container>;
61+
};
62+
export default JSONEditor;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { graphql } from "src/graphql";
2+
import { useQuery } from "@tanstack/react-query";
3+
import { graphqlQueryFnHelper } from "utils/graphqlQueryFnHelper";
4+
import { isUndefined } from "utils/index";
5+
import { DisputeTemplateQuery } from "src/graphql/graphql";
6+
7+
const disputeTemplateQuery = graphql(`
8+
query DisputeTemplate($id: ID!) {
9+
disputeTemplate(id: $id) {
10+
id
11+
templateTag
12+
templateData
13+
templateDataMappings
14+
}
15+
}
16+
`);
17+
18+
export const useDisputeTemplateFromId = (templateId?: string) => {
19+
const isEnabled = !isUndefined(templateId);
20+
21+
return useQuery<DisputeTemplateQuery>({
22+
queryKey: [`disputeTemplate${templateId}`],
23+
enabled: isEnabled,
24+
staleTime: Infinity,
25+
queryFn: async () => await graphqlQueryFnHelper(disputeTemplateQuery, { id: templateId?.toString() }, true),
26+
});
27+
};

web/src/layout/Header/navbar/Explore.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const StyledLink = styled(Link)<{ isActive: boolean }>`
4949
`;
5050

5151
const HiddenLink = styled(StyledLink)<{ isActive: boolean }>`
52-
color: ${({ isActive, theme }) => (isActive ? theme.primaryText : theme.primaryPurple)};
52+
color: ${({ isActive, theme }) => (isActive ? theme.primaryText : "transparent")};
5353
`;
5454

5555
const links = [
@@ -61,7 +61,7 @@ const links = [
6161

6262
const Explore: React.FC = () => {
6363
const location = useLocation();
64-
const { toggleIsOpen } = useOpenContext();
64+
const { isOpen, toggleIsOpen } = useOpenContext();
6565

6666
return (
6767
<Container>
@@ -77,15 +77,17 @@ const Explore: React.FC = () => {
7777
</StyledLink>
7878
</LinkContainer>
7979
))}
80-
<LinkContainer>
81-
<HiddenLink
82-
to="/disputeTemplate"
83-
onClick={toggleIsOpen}
84-
isActive={location.pathname.startsWith("/disputeTemplate")}
85-
>
86-
Dev
87-
</HiddenLink>
88-
</LinkContainer>
80+
{!isOpen && (
81+
<LinkContainer>
82+
<HiddenLink
83+
to="/disputeTemplate"
84+
onClick={toggleIsOpen}
85+
isActive={location.pathname.startsWith("/disputeTemplate")}
86+
>
87+
Dev
88+
</HiddenLink>
89+
</LinkContainer>
90+
)}
8991
</Container>
9092
);
9193
};

0 commit comments

Comments
 (0)