Skip to content

Commit 04bf32e

Browse files
committed
feat: add dismissible banner and update layout adjustments
1 parent f2ec701 commit 04bf32e

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

src/features/Banner.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, { useEffect, useState } from "react";
2-
import { Anchor, Flex, Button } from "@mantine/core";
2+
import { Anchor, Flex, Button, ActionIcon } from "@mantine/core";
3+
import { useSessionStorage } from "@mantine/hooks";
4+
import { MdClose } from "react-icons/md";
35

46
export const BANNER_HEIGHT =
57
process.env.NEXT_PUBLIC_DISABLE_EXTERNAL_MODE === "true" ? "0px" : "40px";
@@ -19,8 +21,14 @@ export const Banner = () => {
1921

2022
const [index, setIndex] = useState(0);
2123
const [visible, setVisible] = useState(true);
24+
const [dismissed, setDismissed] = useSessionStorage({
25+
key: "jsoncrack_banner_dismissed",
26+
defaultValue: false,
27+
});
2228

2329
useEffect(() => {
30+
if (dismissed) return;
31+
2432
let fadeTimeout: ReturnType<typeof setTimeout> | undefined;
2533
const intervalId = setInterval(() => {
2634
setVisible(false);
@@ -34,14 +42,23 @@ export const Banner = () => {
3442
clearInterval(intervalId);
3543
if (fadeTimeout) clearTimeout(fadeTimeout);
3644
};
37-
}, []);
45+
}, [dismissed]);
46+
47+
const handleDismiss = (e: React.MouseEvent) => {
48+
e.preventDefault();
49+
e.stopPropagation();
50+
setDismissed(true);
51+
};
52+
53+
if (dismissed) return null;
3854

3955
return (
4056
<Anchor
4157
href="https://todiagram.com/editor?utm_source=jsoncrack&utm_medium=top_banner"
4258
target="_blank"
4359
rel="noopener"
4460
underline="never"
61+
style={{ position: "relative" }}
4562
>
4663
<Flex
4764
h={BANNER_HEIGHT}
@@ -67,6 +84,19 @@ export const Banner = () => {
6784
<Button size="xs" color="gray">
6885
Try now
6986
</Button>
87+
<ActionIcon
88+
onClick={handleDismiss}
89+
size="sm"
90+
variant="transparent"
91+
style={{
92+
position: "absolute",
93+
right: "8px",
94+
color: "black",
95+
}}
96+
aria-label="Close banner"
97+
>
98+
<MdClose size={18} />
99+
</ActionIcon>
70100
</Flex>
71101
</Anchor>
72102
);

src/features/editor/TextEditor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ 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";
87

98
loader.config({
109
paths: {
@@ -105,7 +104,7 @@ const StyledEditorWrapper = styled.div`
105104

106105
const StyledWrapper = styled.div`
107106
display: grid;
108-
height: ${`calc(100vh - 67px - ${BANNER_HEIGHT})`};
107+
height: 100%;
109108
grid-template-columns: 100%;
110109
grid-template-rows: minmax(0, 1fr);
111110
`;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ 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";
1211
import { CustomEdge } from "./CustomEdge";
1312
import { CustomNode } from "./CustomNode";
1413
import { NotSupported } from "./NotSupported";
@@ -18,9 +17,8 @@ import { ZoomControl } from "./ZoomControl";
1817
import useGraph from "./stores/useGraph";
1918

2019
const StyledEditorWrapper = styled.div<{ $widget: boolean; $showRulers: boolean }>`
21-
position: absolute;
2220
width: 100%;
23-
height: ${({ $widget }) => ($widget ? "100vh" : `calc(100vh - 40px - ${BANNER_HEIGHT})`)};
21+
height: 100vh;
2422
2523
--bg-color: ${({ theme }) => theme.GRID_BG_COLOR};
2624
--line-color-1: ${({ theme }) => theme.GRID_COLOR_PRIMARY};

src/pages/editor.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import "allotment/dist/style.css";
1111
import { NextSeo } from "next-seo";
1212
import { SEO } from "../constants/seo";
1313
import { darkTheme, lightTheme } from "../constants/theme";
14-
import { Banner, BANNER_HEIGHT } from "../features/Banner";
14+
import { Banner } from "../features/Banner";
1515
import { BottomBar } from "../features/editor/BottomBar";
1616
import { FullscreenDropzone } from "../features/editor/FullscreenDropzone";
1717
import { Toolbar } from "../features/editor/Toolbar";
@@ -32,6 +32,8 @@ const queryClient = new QueryClient({
3232
});
3333

3434
export const StyledPageWrapper = styled.div`
35+
display: flex;
36+
flex-direction: column;
3537
height: 100vh;
3638
width: 100%;
3739
@@ -50,7 +52,6 @@ export const StyledEditor = styled(Allotment)`
5052
position: relative !important;
5153
display: flex;
5254
background: ${({ theme }) => theme.BACKGROUND_SECONDARY};
53-
height: ${`calc(100vh - 40px - ${BANNER_HEIGHT})`};
5455
5556
@media only screen and (max-width: 320px) {
5657
height: 100vh;

0 commit comments

Comments
 (0)