mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-01-27 15:22:56 +08:00
feat: move news modal check to cookie
This commit is contained in:
parent
53138b50c8
commit
614c6946fb
@ -41,6 +41,7 @@
|
|||||||
"react-zoom-pan-pinch": "^3.0.2",
|
"react-zoom-pan-pinch": "^3.0.2",
|
||||||
"reaflow": "^5.1.2",
|
"reaflow": "^5.1.2",
|
||||||
"styled-components": "^5.3.8",
|
"styled-components": "^5.3.8",
|
||||||
|
"universal-cookie": "^4.0.4",
|
||||||
"zustand": "^4.3.6"
|
"zustand": "^4.3.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,51 +1,43 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Modal, Group, Button, MantineProvider, Image, Text, Paper } from "@mantine/core";
|
import {
|
||||||
import { useDebouncedState, useSessionStorage } from "@mantine/hooks";
|
Modal,
|
||||||
|
Group,
|
||||||
export const HerowandModal = () => {
|
Button,
|
||||||
const [opened, setOpened] = useDebouncedState(false, 300);
|
MantineProvider,
|
||||||
const [isNewsVisible, setNewsVisible] = useSessionStorage<boolean>({
|
Image,
|
||||||
key: "news",
|
Text,
|
||||||
defaultValue: true,
|
Paper,
|
||||||
getInitialValueInEffect: true,
|
ModalProps,
|
||||||
});
|
Anchor,
|
||||||
|
} from "@mantine/core";
|
||||||
React.useEffect(() => {
|
|
||||||
if (isNewsVisible) setOpened(true);
|
|
||||||
else setOpened(false);
|
|
||||||
}, [isNewsVisible, setOpened]);
|
|
||||||
|
|
||||||
const onClose = () => {
|
|
||||||
setNewsVisible(false);
|
|
||||||
setOpened(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
export const HerowandModal: React.FC<ModalProps> = ({ opened, onClose }) => {
|
||||||
return (
|
return (
|
||||||
<MantineProvider theme={{ colorScheme: "dark" }}>
|
<MantineProvider theme={{ colorScheme: "dark" }}>
|
||||||
<Modal title="What's New?" opened={opened} onClose={onClose} centered>
|
<Modal title="What's New?" opened={opened} onClose={onClose} centered>
|
||||||
<Group>
|
<Group>
|
||||||
<Paper withBorder>
|
<Anchor href="https://editor.herowand.com">
|
||||||
<Image
|
<Paper withBorder>
|
||||||
radius="md"
|
<Image
|
||||||
mx="auto"
|
radius="md"
|
||||||
src="assets/herowand_banner.webp"
|
mx="auto"
|
||||||
width={400}
|
src="assets/herowand_banner.webp"
|
||||||
alt="herowand"
|
width={400}
|
||||||
/>
|
alt="herowand"
|
||||||
</Paper>
|
/>
|
||||||
|
</Paper>
|
||||||
|
</Anchor>
|
||||||
</Group>
|
</Group>
|
||||||
<Text pt="lg">
|
<Text pt="lg">
|
||||||
Introducing you something new...
|
Introducing you something new...
|
||||||
<hr />
|
<hr />
|
||||||
Herowand Editor - the ultimate tool for visualizing, editing, and sharing data in graph
|
Now, you can visualize not only JSON but also other data formats. Explore Herowand Editor.
|
||||||
format. Import JSON, YAML, TOML, XML and manipulate data on the graph. Save to cloud,
|
|
||||||
share, download as image, search through graph, accessibility features. Try it now!
|
|
||||||
</Text>
|
</Text>
|
||||||
<Group pt="lg" position="right">
|
<Group pt="lg" position="right">
|
||||||
<Button color="red" onClick={onClose}>
|
<Button color="red" onClick={onClose}>
|
||||||
Dismiss
|
Dismiss
|
||||||
</Button>
|
</Button>
|
||||||
<Button component="a" href="https://editor.herowand.com/?ref=jsoncrack">
|
<Button onClick={onClose} component="a" href="https://editor.herowand.com/?ref=jsoncrack">
|
||||||
Show me!
|
Show me!
|
||||||
</Button>
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
|
@ -6,6 +6,7 @@ import { MantineProvider } from "@mantine/core";
|
|||||||
import { init } from "@sentry/nextjs";
|
import { init } from "@sentry/nextjs";
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
import { Toaster } from "react-hot-toast";
|
import { Toaster } from "react-hot-toast";
|
||||||
|
import Cookie from "universal-cookie";
|
||||||
import { GoogleAnalytics } from "src/components/GoogleAnalytics";
|
import { GoogleAnalytics } from "src/components/GoogleAnalytics";
|
||||||
import GlobalStyle from "src/constants/globalStyle";
|
import GlobalStyle from "src/constants/globalStyle";
|
||||||
import { darkTheme, lightTheme } from "src/constants/theme";
|
import { darkTheme, lightTheme } from "src/constants/theme";
|
||||||
@ -21,6 +22,9 @@ if (process.env.NODE_ENV !== "development") {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cookie = new Cookie();
|
||||||
|
const newsCookie = cookie.get("news_seen");
|
||||||
|
|
||||||
const queryClient = new QueryClient({
|
const queryClient = new QueryClient({
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
queries: {
|
queries: {
|
||||||
@ -39,10 +43,20 @@ const monaSans = localFont({
|
|||||||
|
|
||||||
function JsonCrack({ Component, pageProps }: AppProps) {
|
function JsonCrack({ Component, pageProps }: AppProps) {
|
||||||
const [isReady, setReady] = React.useState(false);
|
const [isReady, setReady] = React.useState(false);
|
||||||
|
const [showNews, setShowNews] = React.useState(false);
|
||||||
const lightmode = useStored(state => state.lightmode);
|
const lightmode = useStored(state => state.lightmode);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
setReady(true);
|
setReady(true);
|
||||||
|
|
||||||
|
if (typeof newsCookie === "undefined") {
|
||||||
|
setShowNews(true);
|
||||||
|
} else setShowNews(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const closeNews = React.useCallback(() => {
|
||||||
|
setShowNews(false);
|
||||||
|
cookie.set("news_seen", true, { path: "/", maxAge: 43200 });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (isReady)
|
if (isReady)
|
||||||
@ -51,7 +65,8 @@ function JsonCrack({ Component, pageProps }: AppProps) {
|
|||||||
<GoogleAnalytics />
|
<GoogleAnalytics />
|
||||||
<ThemeProvider theme={lightmode ? lightTheme : darkTheme}>
|
<ThemeProvider theme={lightmode ? lightTheme : darkTheme}>
|
||||||
<GlobalStyle />
|
<GlobalStyle />
|
||||||
<HerowandModal />
|
{}
|
||||||
|
<HerowandModal opened={showNews} onClose={closeNews} />
|
||||||
<MantineProvider
|
<MantineProvider
|
||||||
withGlobalStyles
|
withGlobalStyles
|
||||||
withNormalizeCSS
|
withNormalizeCSS
|
||||||
|
15
yarn.lock
15
yarn.lock
@ -979,6 +979,11 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@types/aria-query/-/aria-query-5.0.1.tgz#3286741fb8f1e1580ac28784add4c7a1d49bdfbc"
|
resolved "https://registry.yarnpkg.com/@types/aria-query/-/aria-query-5.0.1.tgz#3286741fb8f1e1580ac28784add4c7a1d49bdfbc"
|
||||||
integrity sha512-XTIieEY+gvJ39ChLcB4If5zHtPxt3Syj5rgZR+e1ctpmK8NjPf0zFqsz4JpLJT0xla9GFDKjy8Cpu331nrmE1Q==
|
integrity sha512-XTIieEY+gvJ39ChLcB4If5zHtPxt3Syj5rgZR+e1ctpmK8NjPf0zFqsz4JpLJT0xla9GFDKjy8Cpu331nrmE1Q==
|
||||||
|
|
||||||
|
"@types/cookie@^0.3.3":
|
||||||
|
version "0.3.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.3.3.tgz#85bc74ba782fb7aa3a514d11767832b0e3bc6803"
|
||||||
|
integrity sha512-LKVP3cgXBT9RYj+t+9FDKwS5tdI+rPBXaNSkma7hvqy35lc7mAokC2zsqWJH0LaqIt3B962nuYI77hsJoT1gow==
|
||||||
|
|
||||||
"@types/estree@*", "@types/estree@^1.0.0":
|
"@types/estree@*", "@types/estree@^1.0.0":
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.0.tgz#5fb2e536c1ae9bf35366eed879e827fa59ca41c2"
|
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.0.tgz#5fb2e536c1ae9bf35366eed879e827fa59ca41c2"
|
||||||
@ -1516,7 +1521,7 @@ convert-source-map@^1.5.0:
|
|||||||
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.9.0.tgz#7faae62353fb4213366d0ca98358d22e8368b05f"
|
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.9.0.tgz#7faae62353fb4213366d0ca98358d22e8368b05f"
|
||||||
integrity sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==
|
integrity sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==
|
||||||
|
|
||||||
cookie@^0.4.1:
|
cookie@^0.4.0, cookie@^0.4.1:
|
||||||
version "0.4.2"
|
version "0.4.2"
|
||||||
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.2.tgz#0e41f24de5ecf317947c82fc789e06a884824432"
|
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.2.tgz#0e41f24de5ecf317947c82fc789e06a884824432"
|
||||||
integrity sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==
|
integrity sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==
|
||||||
@ -4261,6 +4266,14 @@ undoo@^0.5.0:
|
|||||||
defaulty "^2.1.0"
|
defaulty "^2.1.0"
|
||||||
fast-deep-equal "^1.0.0"
|
fast-deep-equal "^1.0.0"
|
||||||
|
|
||||||
|
universal-cookie@^4.0.4:
|
||||||
|
version "4.0.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/universal-cookie/-/universal-cookie-4.0.4.tgz#06e8b3625bf9af049569ef97109b4bb226ad798d"
|
||||||
|
integrity sha512-lbRVHoOMtItjWbM7TwDLdl8wug7izB0tq3/YVKhT/ahB4VDvWMyvnADfnJI8y6fSvsjh51Ix7lTGC6Tn4rMPhw==
|
||||||
|
dependencies:
|
||||||
|
"@types/cookie" "^0.3.3"
|
||||||
|
cookie "^0.4.0"
|
||||||
|
|
||||||
uri-js@^4.2.2:
|
uri-js@^4.2.2:
|
||||||
version "4.4.1"
|
version "4.4.1"
|
||||||
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e"
|
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user