Skip to content

Commit c63d143

Browse files
committed
feat: add editor top banner
1 parent ab48e45 commit c63d143

File tree

11 files changed

+91
-354
lines changed

11 files changed

+91
-354
lines changed

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
NEXT_PUBLIC_NODE_LIMIT=2000
12
NEXT_PUBLIC_DISABLE_EXTERNAL_MODE=false

src/features/Banner.tsx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React, { useEffect, useState } from "react";
2+
import { Anchor, Flex, Button } from "@mantine/core";
3+
4+
export const BANNER_HEIGHT =
5+
process.env.NEXT_PUBLIC_DISABLE_EXTERNAL_MODE === "true" ? "0px" : "40px";
6+
7+
const BANNER_LIST = [
8+
"Save and store your diagrams with ToDiagram",
9+
"Explore the ToDiagram from the creators of JSON Crack",
10+
"Generate AI diagrams with single prompt",
11+
"Try ToDiagram for free, no sign-up required",
12+
"Edit data directly inside diagrams",
13+
"Explore larger datasets (up to 50 MB) easily",
14+
];
15+
16+
export const Banner = () => {
17+
const ROTATION_INTERVAL = 6000; // ms between label changes
18+
const FADE_DURATION = 500; // ms for fade transition
19+
20+
const [index, setIndex] = useState(0);
21+
const [visible, setVisible] = useState(true);
22+
23+
useEffect(() => {
24+
let fadeTimeout: ReturnType<typeof setTimeout> | undefined;
25+
const intervalId = setInterval(() => {
26+
setVisible(false);
27+
fadeTimeout = setTimeout(() => {
28+
setIndex(i => (i + 1) % BANNER_LIST.length);
29+
setVisible(true);
30+
}, FADE_DURATION);
31+
}, ROTATION_INTERVAL);
32+
33+
return () => {
34+
clearInterval(intervalId);
35+
if (fadeTimeout) clearTimeout(fadeTimeout);
36+
};
37+
}, []);
38+
39+
return (
40+
<Anchor
41+
href="https://todiagram.com/editor?utm_source=jsoncrack&utm_medium=top_banner"
42+
target="_blank"
43+
rel="noopener"
44+
underline="never"
45+
>
46+
<Flex
47+
h={BANNER_HEIGHT}
48+
justify="center"
49+
align="center"
50+
fw="500"
51+
gap="xs"
52+
style={{
53+
background: "linear-gradient(90deg, #FF75B7 0%, #FED761 100%)",
54+
color: "black",
55+
}}
56+
>
57+
<span
58+
style={{
59+
transition: `opacity ${FADE_DURATION}ms ease`,
60+
opacity: visible ? 1 : 0,
61+
willChange: "opacity",
62+
display: "inline-block",
63+
}}
64+
>
65+
{BANNER_LIST[index]}{" "}
66+
</span>
67+
<Button size="xs" color="gray">
68+
Try now
69+
</Button>
70+
</Flex>
71+
</Anchor>
72+
);
73+
};

src/features/editor/BottomBar.tsx

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Flex, Menu, Popover, Text } from "@mantine/core";
33
import styled from "styled-components";
44
import { event as gaEvent } from "nextjs-google-analytics";
55
import { BiSolidDockLeft } from "react-icons/bi";
6-
import { FaCrown } from "react-icons/fa6";
76
import { IoMdCheckmark } from "react-icons/io";
87
import { MdArrowUpward } from "react-icons/md";
98
import { VscCheck, VscError, VscRunAll, VscSync, VscSyncIgnored } from "react-icons/vsc";
@@ -161,30 +160,6 @@ export const BottomBar = () => {
161160
{format.label}
162161
</Menu.Item>
163162
))}
164-
<Menu.Item
165-
fz={12}
166-
onClick={() =>
167-
window.open(
168-
"https://todiagram.com/editor?utm_source=jsoncrack&utm_medium=bottom-bar&utm_campaign=custom-diagram",
169-
"_blank"
170-
)
171-
}
172-
rightSection={<FaCrown color="gray" />}
173-
>
174-
Custom
175-
</Menu.Item>
176-
<Menu.Item
177-
fz={12}
178-
onClick={() =>
179-
window.open(
180-
"https://todiagram.com/editor?utm_source=jsoncrack&utm_medium=bottom-bar&utm_campaign=mermaid-diagram",
181-
"_blank"
182-
)
183-
}
184-
rightSection={<FaCrown color="gray" />}
185-
>
186-
Mermaid
187-
</Menu.Item>
188163
</Menu.Dropdown>
189164
</Menu>
190165
</StyledRight>

src/features/editor/TextEditor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled from "styled-components";
44
import Editor, { type EditorProps, loader, type OnMount, useMonaco } from "@monaco-editor/react";
55
import useConfig from "../../store/useConfig";
66
import useFile from "../../store/useFile";
7+
import { BANNER_HEIGHT } from "../Banner";
78

89
loader.config({
910
paths: {
@@ -102,7 +103,7 @@ const StyledEditorWrapper = styled.div`
102103

103104
const StyledWrapper = styled.div`
104105
display: grid;
105-
height: calc(100vh - 67px);
106+
height: ${`calc(100vh - 67px - ${BANNER_HEIGHT})`};
106107
grid-template-columns: 100%;
107108
grid-template-rows: minmax(0, 1fr);
108109
`;

src/features/editor/Toolbar/index.tsx

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import React from "react";
22
import Link from "next/link";
3-
import { Flex, Group, Button } from "@mantine/core";
3+
import { Flex, Group } from "@mantine/core";
44
import styled from "styled-components";
55
import toast from "react-hot-toast";
66
import { AiOutlineFullscreen } from "react-icons/ai";
7-
import { FaCrown, FaGithub } from "react-icons/fa6";
8-
import { LuLink } from "react-icons/lu";
7+
import { FaGithub } from "react-icons/fa6";
98
import { JSONCrackLogo } from "../../../layout/JsonCrackLogo";
10-
import { useModal } from "../../../store/useModal";
119
import { FileMenu } from "./FileMenu";
1210
import { ToolsMenu } from "./ToolsMenu";
1311
import { ViewMenu } from "./ViewMenu";
@@ -43,8 +41,6 @@ function fullscreenBrowser() {
4341
}
4442

4543
export const Toolbar = () => {
46-
const setVisible = useModal(state => state.setVisible);
47-
4844
return (
4945
<StyledTools>
5046
<Group gap="xs" justify="left" w="100%" style={{ flexWrap: "nowrap" }}>
@@ -56,33 +52,8 @@ export const Toolbar = () => {
5652
<FileMenu />
5753
<ViewMenu />
5854
<ToolsMenu />
59-
<Button
60-
component={Link}
61-
href="https://todiagram.com/editor?utm_source=jsoncrack&utm_medium=toolbar"
62-
target="_blank"
63-
rel="noopener"
64-
autoContrast
65-
color="yellow"
66-
variant="light"
67-
size="compact-xs"
68-
fz="12"
69-
fw="600"
70-
leftSection={<FaCrown />}
71-
>
72-
Try Pro for Free | No Sign-up
73-
</Button>
7455
</Group>
7556
<Group gap="xs" justify="right" w="100%" style={{ flexWrap: "nowrap" }}>
76-
<Button
77-
color="gray"
78-
fz="12"
79-
leftSection={<LuLink />}
80-
size="compact-sm"
81-
variant="default"
82-
onClick={() => setVisible("UpgradeModal", true)}
83-
>
84-
Share
85-
</Button>
8657
<Link href="https://github.com/AykutSarac/jsoncrack.com" rel="noopener" target="_blank">
8758
<StyledToolElement title="GitHub">
8859
<FaGithub size="18" />

src/features/editor/views/GraphView/NotSupported.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from "react";
22
import { Anchor, Button, Image, Overlay, Stack, Text } from "@mantine/core";
33
import styled, { keyframes } from "styled-components";
44
import useConfig from "../../../../store/useConfig";
5-
import { useModal } from "../../../../store/useModal";
65

76
const shineEffect = keyframes`
87
0% {
@@ -59,7 +58,6 @@ const ShiningButton = styled.div`
5958

6059
export const NotSupported = () => {
6160
const darkmodeEnabled = useConfig(state => state.darkmodeEnabled);
62-
const setVisible = useModal(state => state.setVisible);
6361

6462
return (
6563
<Overlay
@@ -77,7 +75,14 @@ export const NotSupported = () => {
7775
This diagram is too large and not supported at JSON Crack.
7876
<br />
7977
Try{" "}
80-
<Anchor inherit c="teal" fw="500" onClick={() => setVisible("UpgradeModal", true)}>
78+
<Anchor
79+
inherit
80+
c="teal"
81+
fw="500"
82+
href="https://todiagram.com/editor?utm_source=jsoncrack&utm_medium=data_limit"
83+
target="_blank"
84+
rel="noopener"
85+
>
8186
ToDiagram
8287
</Anchor>{" "}
8388
for larger diagrams and more features.

src/features/editor/views/GraphView/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Canvas } from "reaflow";
88
import type { ElkRoot } from "reaflow/dist/layout/useLayout";
99
import { useLongPress } from "use-long-press";
1010
import useConfig from "../../../../store/useConfig";
11+
import { BANNER_HEIGHT } from "../../../Banner";
1112
import { CustomEdge } from "./CustomEdge";
1213
import { CustomNode } from "./CustomNode";
1314
import { NotSupported } from "./NotSupported";
@@ -19,7 +20,7 @@ import useGraph from "./stores/useGraph";
1920
const StyledEditorWrapper = styled.div<{ $widget: boolean; $showRulers: boolean }>`
2021
position: absolute;
2122
width: 100%;
22-
height: ${({ $widget }) => ($widget ? "100vh" : "calc(100vh - 40px)")};
23+
height: ${({ $widget }) => ($widget ? "100vh" : `calc(100vh - 40px - ${BANNER_HEIGHT})`)};
2324
2425
--bg-color: ${({ theme }) => theme.GRID_BG_COLOR};
2526
--line-color-1: ${({ theme }) => theme.GRID_COLOR_PRIMARY};

src/features/modals/SchemaModal/index.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@ import Editor from "@monaco-editor/react";
55
import { event as gaEvent } from "nextjs-google-analytics";
66
import { toast } from "react-hot-toast";
77
import { FaChevronDown } from "react-icons/fa";
8-
import { FaCrown } from "react-icons/fa6";
98
import { VscLinkExternal } from "react-icons/vsc";
109
import { FileFormat } from "../../../enums/file.enum";
1110
import useConfig from "../../../store/useConfig";
1211
import useFile from "../../../store/useFile";
13-
import { useModal } from "../../../store/useModal";
1412

1513
export const SchemaModal = ({ opened, onClose }: ModalProps) => {
1614
const setContents = useFile(state => state.setContents);
1715
const setJsonSchema = useFile(state => state.setJsonSchema);
18-
const setVisible = useModal(state => state.setVisible);
1916
const darkmodeEnabled = useConfig(state => (state.darkmodeEnabled ? "vs-dark" : "light"));
2017
const [schema, setSchema] = React.useState(
2118
JSON.stringify(
@@ -116,12 +113,6 @@ export const SchemaModal = ({ opened, onClose }: ModalProps) => {
116113
</Menu.Target>
117114
<Menu.Dropdown>
118115
<Menu.Item onClick={generateMockData}>Generate Mock Data</Menu.Item>
119-
<Menu.Item
120-
onClick={() => setVisible("UpgradeModal", true)}
121-
rightSection={<FaCrown />}
122-
>
123-
Validate on Diagrams
124-
</Menu.Item>
125116
</Menu.Dropdown>
126117
</Menu>
127118
</Button.Group>

0 commit comments

Comments
 (0)