Skip to content

✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.

fix: change format error

AykutSaracf4ebf932332e
diff --git a/src/components/GoogleAnalytics/index.tsx b/src/components/GoogleAnalytics/index.tsx
index 81058fd8..eacca36a 100644
--- a/src/components/GoogleAnalytics/index.tsx
+++ b/src/components/GoogleAnalytics/index.tsx
@@ -1,8 +1,8 @@
import React from "react";
import Script from "next/script";
-import * as gtag from "src/utils/gtag";
const isDevelopment = process.env.NODE_ENV === "development";
+const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID;
export const GoogleAnalytics: React.FC = () => {
if (isDevelopment) return null;
@@ -11,7 +11,7 @@ export const GoogleAnalytics: React.FC = () => {
<>
<Script
strategy="afterInteractive"
- src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
+ src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
/>
<Script
id="gtag-init"
@@ -21,7 +21,7 @@ export const GoogleAnalytics: React.FC = () => {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
- gtag('config', '${gtag.GA_TRACKING_ID}', {
+ gtag('config', '${GA_TRACKING_ID}', {
page_path: window.location.pathname,
});
`,
diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx
index 7e0fa952..8f4a5500 100644
--- a/src/pages/_app.tsx
+++ b/src/pages/_app.tsx
@@ -1,6 +1,5 @@
import React from "react";
import type { AppProps } from "next/app";
-import { useRouter } from "next/router";
import { ThemeProvider } from "styled-components";
import { MantineProvider } from "@mantine/core";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
@@ -11,7 +10,6 @@ import GlobalStyle from "src/constants/globalStyle";
import { lightTheme } from "src/constants/theme";
import { ExternalMode } from "src/layout/DevMode";
import { ModalController } from "src/layout/ModalController";
-import * as gtag from "src/utils/gtag";
const queryClient = new QueryClient({
defaultOptions: {
@@ -23,17 +21,9 @@ const queryClient = new QueryClient({
});
function JsonCrack({ Component, pageProps }: AppProps) {
- const router = useRouter();
const [isReady, setReady] = React.useState(false);
- React.useEffect(() => {
- const handleRouteChange = (url: string) => gtag.pageview(url);
- router.events.on("routeChangeComplete", handleRouteChange);
- setReady(true);
- return () => {
- router.events.off("routeChangeComplete", handleRouteChange);
- };
- }, [router.events]);
+ React.useEffect(() => setReady(true), []);
if (isReady)
return (
diff --git a/src/store/useFile.ts b/src/store/useFile.ts
index 682c552c..648a5df8 100644
--- a/src/store/useFile.ts
+++ b/src/store/useFile.ts
@@ -98,14 +98,14 @@ const useFile = create<FileStates & JsonActions>()((set, get) => ({
getHasChanges: () => get().hasChanges,
setFormat: async format => {
try {
- const contentJson = await contentToJson(get().contents, get().format);
+ const prevFormat = get().format;
+ set({ format });
+ const contentJson = await contentToJson(get().contents, prevFormat);
const jsonContent = await jsonToContent(JSON.stringify(contentJson, null, 2), format);
get().setContents({ contents: jsonContent, hasChanges: false });
} catch (error) {
get().clear();
console.info("The content was unable to be converted, so it was cleared instead.");
- } finally {
- set({ format });
}
},
setContents: async ({ contents, hasChanges = true, skipUpdate = false }) => {
diff --git a/src/typings/global.d.ts b/src/typings/global.d.ts
index 9d720c77..78834c98 100644
--- a/src/typings/global.d.ts
+++ b/src/typings/global.d.ts
@@ -1,5 +1,3 @@
interface Window {
_bsa: any;
- gtag: (...args: any[]) => void;
- dataLayer: Record<string, any>;
}
diff --git a/src/utils/gtag.ts b/src/utils/gtag.ts
deleted file mode 100644
index 42dd54a8..00000000
--- a/src/utils/gtag.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-export const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID;
-
-// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
-export const pageview = (url: string) => {
- window.gtag("config", GA_TRACKING_ID, {
- page_path: url,
- });
-};
-
-// https://developers.google.com/analytics/devguides/collection/gtagjs/events
-export const event = ({ action, category, label, value }) => {
- window.gtag("event", action, {
- event_category: category,
- event_label: label,
- value: value,
- });
-};