mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-01-27 15:22:56 +08:00
fix: change format error
This commit is contained in:
parent
c3fed760cd
commit
f4ebf93233
@ -1,8 +1,8 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import Script from "next/script";
|
import Script from "next/script";
|
||||||
import * as gtag from "src/utils/gtag";
|
|
||||||
|
|
||||||
const isDevelopment = process.env.NODE_ENV === "development";
|
const isDevelopment = process.env.NODE_ENV === "development";
|
||||||
|
const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID;
|
||||||
|
|
||||||
export const GoogleAnalytics: React.FC = () => {
|
export const GoogleAnalytics: React.FC = () => {
|
||||||
if (isDevelopment) return null;
|
if (isDevelopment) return null;
|
||||||
@ -11,7 +11,7 @@ export const GoogleAnalytics: React.FC = () => {
|
|||||||
<>
|
<>
|
||||||
<Script
|
<Script
|
||||||
strategy="afterInteractive"
|
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
|
<Script
|
||||||
id="gtag-init"
|
id="gtag-init"
|
||||||
@ -21,7 +21,7 @@ export const GoogleAnalytics: React.FC = () => {
|
|||||||
window.dataLayer = window.dataLayer || [];
|
window.dataLayer = window.dataLayer || [];
|
||||||
function gtag(){dataLayer.push(arguments);}
|
function gtag(){dataLayer.push(arguments);}
|
||||||
gtag('js', new Date());
|
gtag('js', new Date());
|
||||||
gtag('config', '${gtag.GA_TRACKING_ID}', {
|
gtag('config', '${GA_TRACKING_ID}', {
|
||||||
page_path: window.location.pathname,
|
page_path: window.location.pathname,
|
||||||
});
|
});
|
||||||
`,
|
`,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import type { AppProps } from "next/app";
|
import type { AppProps } from "next/app";
|
||||||
import { useRouter } from "next/router";
|
|
||||||
import { ThemeProvider } from "styled-components";
|
import { ThemeProvider } from "styled-components";
|
||||||
import { MantineProvider } from "@mantine/core";
|
import { MantineProvider } from "@mantine/core";
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
@ -11,7 +10,6 @@ import GlobalStyle from "src/constants/globalStyle";
|
|||||||
import { lightTheme } from "src/constants/theme";
|
import { lightTheme } from "src/constants/theme";
|
||||||
import { ExternalMode } from "src/layout/DevMode";
|
import { ExternalMode } from "src/layout/DevMode";
|
||||||
import { ModalController } from "src/layout/ModalController";
|
import { ModalController } from "src/layout/ModalController";
|
||||||
import * as gtag from "src/utils/gtag";
|
|
||||||
|
|
||||||
const queryClient = new QueryClient({
|
const queryClient = new QueryClient({
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
@ -23,17 +21,9 @@ const queryClient = new QueryClient({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function JsonCrack({ Component, pageProps }: AppProps) {
|
function JsonCrack({ Component, pageProps }: AppProps) {
|
||||||
const router = useRouter();
|
|
||||||
const [isReady, setReady] = React.useState(false);
|
const [isReady, setReady] = React.useState(false);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => setReady(true), []);
|
||||||
const handleRouteChange = (url: string) => gtag.pageview(url);
|
|
||||||
router.events.on("routeChangeComplete", handleRouteChange);
|
|
||||||
setReady(true);
|
|
||||||
return () => {
|
|
||||||
router.events.off("routeChangeComplete", handleRouteChange);
|
|
||||||
};
|
|
||||||
}, [router.events]);
|
|
||||||
|
|
||||||
if (isReady)
|
if (isReady)
|
||||||
return (
|
return (
|
||||||
|
@ -98,14 +98,14 @@ const useFile = create<FileStates & JsonActions>()((set, get) => ({
|
|||||||
getHasChanges: () => get().hasChanges,
|
getHasChanges: () => get().hasChanges,
|
||||||
setFormat: async format => {
|
setFormat: async format => {
|
||||||
try {
|
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);
|
const jsonContent = await jsonToContent(JSON.stringify(contentJson, null, 2), format);
|
||||||
get().setContents({ contents: jsonContent, hasChanges: false });
|
get().setContents({ contents: jsonContent, hasChanges: false });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
get().clear();
|
get().clear();
|
||||||
console.info("The content was unable to be converted, so it was cleared instead.");
|
console.info("The content was unable to be converted, so it was cleared instead.");
|
||||||
} finally {
|
|
||||||
set({ format });
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setContents: async ({ contents, hasChanges = true, skipUpdate = false }) => {
|
setContents: async ({ contents, hasChanges = true, skipUpdate = false }) => {
|
||||||
|
2
src/typings/global.d.ts
vendored
2
src/typings/global.d.ts
vendored
@ -1,5 +1,3 @@
|
|||||||
interface Window {
|
interface Window {
|
||||||
_bsa: any;
|
_bsa: any;
|
||||||
gtag: (...args: any[]) => void;
|
|
||||||
dataLayer: Record<string, any>;
|
|
||||||
}
|
}
|
||||||
|
@ -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,
|
|
||||||
});
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user