diff --git a/.env.development b/.env.development index 535988b..24f543b 100644 --- a/.env.development +++ b/.env.development @@ -1,3 +1,3 @@ NEXT_PUBLIC_BASE_URL=http://localhost:3000 -NEXT_ALTOGIC_ENV_URL=https://815e-4e5a.c5-na.altogic.com/ -NEXT_ALTOGIC_CLIENT_KEY=f1e92022789f4ccf91273a345ab2bdf8 \ No newline at end of file +NEXT_PUBLIC_ALTOGIC_ENV_URL=https://815e-4e5a.c5-na.altogic.com/ +NEXT_PUBLIC_ALTOGIC_CLIENT_KEY=f1e92022789f4ccf91273a345ab2bdf8 \ No newline at end of file diff --git a/.env.production b/.env.production index f2efe2b..640b665 100644 --- a/.env.production +++ b/.env.production @@ -1 +1,3 @@ -NEXT_PUBLIC_BASE_URL=https://jsoncrack.com \ No newline at end of file +NEXT_PUBLIC_BASE_URL=https://jsoncrack.com +NEXT_PUBLIC_ALTOGIC_ENV_URL=https://815e-4e5a.c5-na.altogic.com/ +NEXT_PUBLIC_ALTOGIC_CLIENT_KEY=f1e92022789f4ccf91273a345ab2bdf8 \ No newline at end of file diff --git a/package.json b/package.json index 957f0c7..e483db8 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "allotment": "^1.17.0", "altogic": "^2.3.8", "axios": "^1.1.3", - "compress-json": "^2.1.2", "dayjs": "^1.11.6", "html-to-image": "^1.10.8", "jsonc-parser": "^3.2.0", diff --git a/src/api/altogic.ts b/src/api/altogic.ts new file mode 100644 index 0000000..b4d0d45 --- /dev/null +++ b/src/api/altogic.ts @@ -0,0 +1,8 @@ +import { createClient } from "altogic"; + +let envUrl = process.env.NEXT_PUBLIC_ALTOGIC_ENV_URL as string; +let clientKey = process.env.NEXT_PUBLIC_ALTOGIC_CLIENT_KEY as string; + +const altogic = createClient(envUrl, clientKey); + +export { altogic }; diff --git a/src/components/Button/index.tsx b/src/components/Button/index.tsx index 75215cf..31227f7 100644 --- a/src/components/Button/index.tsx +++ b/src/components/Button/index.tsx @@ -35,7 +35,7 @@ const StyledButton = styled.button<{ background: ${({ status, theme }) => getButtonStatus(status, theme)}; color: #ffffff; padding: 8px 16px; - min-width: 60px; + min-width: 70px; min-height: 32px; border-radius: 3px; font-size: 14px; diff --git a/src/components/MonacoEditor/index.tsx b/src/components/MonacoEditor/index.tsx index 7d1f58e..53c524f 100644 --- a/src/components/MonacoEditor/index.tsx +++ b/src/components/MonacoEditor/index.tsx @@ -54,14 +54,16 @@ export const MonacoEditor = () => { const debouncedSetJson = React.useMemo( () => debounce(value => { - if (!value) return; + if (!value || hasError) return; setJson(value); }, 1200), - [setJson] + [hasError, setJson] ); React.useEffect(() => { if (!hasError) debouncedSetJson(value); + + return () => debouncedSetJson.cancel(); }, [debouncedSetJson, hasError, value]); return ( @@ -73,8 +75,8 @@ export const MonacoEditor = () => { theme={lightmode} options={editorOptions} onChange={val => { - if (json) setConfig("hasChanges", true); setValue(val); + if (json) setConfig("hasChanges", true); }} loading={} beforeMount={handleEditorWillMount} diff --git a/src/containers/Editor/BottomBar.tsx b/src/containers/Editor/BottomBar.tsx index 25f1875..b126b56 100644 --- a/src/containers/Editor/BottomBar.tsx +++ b/src/containers/Editor/BottomBar.tsx @@ -10,7 +10,7 @@ import { AiOutlineUnlock, } from "react-icons/ai"; import { VscAccount } from "react-icons/vsc"; -import { altogic } from "src/services/altogic"; +import { altogic } from "src/api/altogic"; import { getJson, saveJson, updateJson } from "src/services/db/json"; import useConfig from "src/store/useConfig"; import useGraph from "src/store/useGraph"; @@ -125,10 +125,12 @@ export const BottomBar = () => { {isPrivate ? : } {isPrivate ? "Private" : "Public"} - setVisible("share")(true)}> - - Share - + {query.json && ( + setVisible("share")(true)}> + + Share + + )} diff --git a/src/containers/Modals/ClearModal/index.tsx b/src/containers/Modals/ClearModal/index.tsx index 34cf1da..99c7e22 100644 --- a/src/containers/Modals/ClearModal/index.tsx +++ b/src/containers/Modals/ClearModal/index.tsx @@ -1,20 +1,28 @@ import React from "react"; +import { useRouter } from "next/router"; import { Button } from "src/components/Button"; import { Modal, ModalProps } from "src/components/Modal"; +import { deleteJson } from "src/services/db/json"; import useGraph from "src/store/useGraph"; export const ClearModal: React.FC = ({ visible, setVisible }) => { const setJson = useGraph(state => state.setJson); + const { query, replace } = useRouter(); const handleClear = () => { setJson("{}"); setVisible(false); + + if (typeof query.json === "string") { + deleteJson(query.json); + replace("/editor"); + } }; return ( - Clear JSON - Are you sure you want to clear JSON? + Delete JSON + Are you sure you want to delete JSON?