_app.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from "react";
  2. import type { AppProps } from "next/app";
  3. import { useRouter } from "next/router";
  4. import { init } from "@sentry/nextjs";
  5. import { decompress } from "compress-json";
  6. import { Toaster } from "react-hot-toast";
  7. import { GoogleAnalytics } from "src/components/GoogleAnalytics";
  8. import GlobalStyle from "src/constants/globalStyle";
  9. import { darkTheme, lightTheme } from "src/constants/theme";
  10. import useConfig from "src/hooks/store/useConfig";
  11. import useStored from "src/hooks/store/useStored";
  12. import { isValidJson } from "src/utils/isValidJson";
  13. import { ThemeProvider } from "styled-components";
  14. if (process.env.NODE_ENV !== "development") {
  15. init({
  16. dsn: "https://[email protected]/6495191",
  17. tracesSampleRate: 0.5,
  18. });
  19. }
  20. function JsonCrack({ Component, pageProps }: AppProps) {
  21. const { query } = useRouter();
  22. const lightmode = useStored(state => state.lightmode);
  23. const setJson = useConfig(state => state.setJson);
  24. const [isRendered, setRendered] = React.useState(false);
  25. React.useEffect(() => {
  26. const isJsonValid =
  27. typeof query.json === "string" && isValidJson(decodeURIComponent(query.json));
  28. if (isJsonValid) {
  29. const jsonDecoded = decompress(JSON.parse(isJsonValid));
  30. const jsonString = JSON.stringify(jsonDecoded);
  31. setJson(jsonString);
  32. }
  33. }, [query.json, setJson]);
  34. React.useEffect(() => {
  35. setRendered(true);
  36. }, []);
  37. if (!isRendered) return null;
  38. return (
  39. <>
  40. <GoogleAnalytics />
  41. <ThemeProvider theme={lightmode ? lightTheme : darkTheme}>
  42. <GlobalStyle />
  43. <Component {...pageProps} />
  44. <Toaster
  45. position="bottom-right"
  46. toastOptions={{
  47. style: {
  48. background: "#4D4D4D",
  49. color: "#B9BBBE",
  50. },
  51. }}
  52. />
  53. </ThemeProvider>
  54. </>
  55. );
  56. }
  57. export default JsonCrack;