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?
diff --git a/src/pages/editor.tsx b/src/pages/editor.tsx
index 594a4d5..f82eb37 100644
--- a/src/pages/editor.tsx
+++ b/src/pages/editor.tsx
@@ -34,7 +34,7 @@ export const StyledEditorWrapper = styled.div`
const EditorPage: React.FC = () => {
const { query, isReady } = useRouter();
const checkSession = useUser(state => state.checkSession);
- const { data, isLoading } = useQuery(
+ const { data, isLoading, status } = useQuery(
["dbJson", query.json],
() => getJson(query.json as string),
{
@@ -52,12 +52,15 @@ const EditorPage: React.FC = () => {
React.useEffect(() => {
if (isReady) {
if (query.json) {
+
if (isLoading) return setLoading(true);
+ if (status || !data) setJson(defaultJson);
+
if (data?.data) setJson(decompressFromBase64(data.data.json) as string);
setLoading(false);
} else setJson(defaultJson);
}
- }, [data, isLoading, isReady, query.json, setJson, setLoading]);
+ }, [data, status, isLoading, isReady, query.json, setJson, setLoading]);
return (
diff --git a/src/services/altogic.ts b/src/services/altogic.ts
deleted file mode 100644
index ab082c0..0000000
--- a/src/services/altogic.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { createClient } from "altogic";
-
-let envUrl = process.env.NEXT_ALTOGIC_ENV_URL as string;
-let clientKey = process.env.NEXT_ALTOGIC_CLIENT_KEY as string;
-
-const altogic = createClient(
- "https://815e-4e5a.c5-na.altogic.com/",
- "f1e92022789f4ccf91273a345ab2bdf8",
- {
- signInRedirect: "/signin",
- }
-);
-
-export { altogic };
diff --git a/src/services/db/json.tsx b/src/services/db/json.tsx
index 04292e2..c8decc7 100644
--- a/src/services/db/json.tsx
+++ b/src/services/db/json.tsx
@@ -1,5 +1,5 @@
import { compressToBase64 } from "lz-string";
-import { altogic } from "../altogic";
+import { altogic } from "src/api/altogic";
type JSON = {
_id: string;
@@ -35,4 +35,6 @@ const updateJson = async (id: string, data: object) =>
...data,
});
-export { saveJson, getJson, getAllJson, updateJson };
+const deleteJson = async (id: string) => await altogic.endpoint.delete(`json/${id}`);
+
+export { saveJson, getJson, getAllJson, updateJson, deleteJson };
diff --git a/src/services/google.ts b/src/services/google.ts
deleted file mode 100644
index d784b6d..0000000
--- a/src/services/google.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import axios from "axios";
-
-const validateToken = async (token: string) => {
- return await axios.get(
- `https://oauth2.googleapis.com/tokeninfo?id_token=${token}`
- );
-};
-
-export { validateToken };
diff --git a/src/store/useUser.tsx b/src/store/useUser.tsx
index 40b38af..110742d 100644
--- a/src/store/useUser.tsx
+++ b/src/store/useUser.tsx
@@ -1,5 +1,5 @@
import toast from "react-hot-toast";
-import { altogic } from "src/services/altogic";
+import { altogic } from "src/api/altogic";
import { AltogicAuth } from "src/typings/altogic";
import create from "zustand";
@@ -31,12 +31,12 @@ const useUser = create()(set => ({
...initialStates,
setUser: (key, value) => set({ [key]: value }),
logout: () => {
- localStorage.removeItem("auth_token");
+ altogic.auth.signOut();
+
toast.success("Logged out.");
set(initialStates);
},
login: response => {
- // localStorage.setItem("auth_token", response.session.token);
set({ user: response.user, isAuthenticated: true });
},
checkSession: () => {
@@ -44,6 +44,8 @@ const useUser = create()(set => ({
const currentUser = altogic.auth.getUser();
if (currentSession) {
+ alert("has");
+
altogic.auth.setSession(currentSession);
set({ user: currentUser as any, isAuthenticated: true });
}
diff --git a/yarn.lock b/yarn.lock
index 909e1ec..605a6f9 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2194,11 +2194,6 @@ commondir@^1.0.1:
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
integrity sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==
-compress-json@^2.1.2:
- version "2.1.2"
- resolved "https://registry.yarnpkg.com/compress-json/-/compress-json-2.1.2.tgz#37e0e7c7480c572fad9ad387fca5a2f36fee6f83"
- integrity sha512-91247RD8bKQXzRmXUS4zGT250mhw86+J9X8w2L2SGtRE7g0CvzjOETFaFmsDdaXPWv8T7L9iiM7kdcnnH3BH7w==
-
concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"