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: styling & auth

AykutSarace443f8e98f3d
diff --git a/src/containers/Editor/BottomBar.tsx b/src/containers/Editor/BottomBar.tsx
index 38aa5b86..db695c57 100644
--- a/src/containers/Editor/BottomBar.tsx
+++ b/src/containers/Editor/BottomBar.tsx
@@ -28,10 +28,6 @@ const StyledBottomBar = styled.div`
max-height: 27px;
height: 27px;
padding: 0 6px;
-
- @media only screen and (max-width: 768px) {
- display: none;
- }
`;
const StyledLeft = styled.div`
@@ -39,6 +35,10 @@ const StyledLeft = styled.div`
align-items: center;
justify-content: left;
gap: 4px;
+
+ @media screen and (max-width: 480px) {
+ display: none;
+ }
`;
const StyledRight = styled.div`
@@ -198,6 +198,7 @@ export const BottomBar = () => {
</>
)}
</StyledLeft>
+
<StyledRight>
<a
href="https://www.altogic.com/?utm_source=jsoncrack&utm_medium=referral&utm_campaign=sponsorship"
diff --git a/src/containers/Editor/LiveEditor/Tools.tsx b/src/containers/Editor/LiveEditor/Tools.tsx
index 0ca81d32..bedf22ef 100644
--- a/src/containers/Editor/LiveEditor/Tools.tsx
+++ b/src/containers/Editor/LiveEditor/Tools.tsx
@@ -1,6 +1,6 @@
import React from "react";
import styled from "styled-components";
-import { Flex, Group, Menu, Text } from "@mantine/core";
+import { Flex, Group, MediaQuery, Menu, Text } from "@mantine/core";
import { useHotkeys } from "@mantine/hooks";
import toast from "react-hot-toast";
import { AiOutlineFullscreen, AiOutlineMinus, AiOutlinePlus } from "react-icons/ai";
@@ -180,104 +180,110 @@ export const Tools: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) =>
</StyledToolElement>
)}
{!isWidget && (
- <Group spacing="xs" position="left" w="100%" noWrap>
- <StyledToolElement as="a" title="JSON Crack" href="https://jsoncrack.com">
- <Flex gap="xs" align="center" justify="center">
- <StyledLogo
- src="/assets/icon.png"
- width="auto"
- height="16"
- alt="logo"
- invert={lightmode}
- />
- </Flex>
- </StyledToolElement>
- <StyledToolElement title="Import File" onClick={() => setVisible("import")(true)}>
- Import
- </StyledToolElement>
- <Menu shadow="md" closeOnItemClick={false}>
- <Menu.Target>
- <StyledToolElement>
- <Flex align="center" gap={3}>
- View <CgChevronDown />
- </Flex>
- </StyledToolElement>
- </Menu.Target>
- <Menu.Dropdown>
- <Menu.Item
- fz={12}
- onClick={toggleEditor}
- icon={fullscreen ? <VscLayoutSidebarLeft /> : <VscLayoutSidebarLeftOff />}
- rightSection={
- <Text ml="md" fz={10} color="dimmed">
- {CoreKey} Shift E
- </Text>
- }
- >
- {fullscreen ? "Show" : "Hide"} Editor
- </Menu.Item>
- <Menu.Item
- fz={12}
- onClick={toggleDirection}
- icon={<StyledFlowIcon rotate={rotateLayout(direction)} />}
- rightSection={
- <Text ml="md" fz={10} color="dimmed">
- {CoreKey} Shift D
- </Text>
- }
- >
- Rotate Layout
- </Menu.Item>
- <Menu.Item
- fz={12}
- onClick={toggleFoldNodes}
- icon={foldNodes ? <CgArrowsShrinkH /> : <CgArrowsMergeAltH />}
- rightSection={
- <Text ml="md" fz={10} color="dimmed">
- {CoreKey} Shift F
- </Text>
- }
- >
- {foldNodes ? "Unfold" : "Fold"} Nodes
- </Menu.Item>
- <Menu.Item
- fz={12}
- onClick={toggleExpandCollapseGraph}
- icon={graphCollapsed ? <VscExpandAll /> : <VscCollapseAll />}
- rightSection={
- <Text ml="md" fz={10} color="dimmed">
- {CoreKey} Shift C
- </Text>
- }
- >
- {graphCollapsed ? "Expand" : "Collapse"} Nodes
- </Menu.Item>
- </Menu.Dropdown>
- </Menu>
- <Menu shadow="md">
- <Menu.Target>
- <StyledToolElement>
- <Flex align="center" gap={3}>
- Tools <CgChevronDown />
- </Flex>
- </StyledToolElement>
- </Menu.Target>
- <Menu.Dropdown>
- <Menu.Item fz={12} icon={<VscJson />} onClick={() => setVisible("schema")(true)}>
- JSON Schema
- </Menu.Item>
- <Menu.Item fz={12} icon={<SiJsonwebtokens />} onClick={() => setVisible("jwt")(true)}>
- Decode JWT
- </Menu.Item>
- </Menu.Dropdown>
- </Menu>
- <StyledToolElement title="Cloud" onClick={() => setVisible("cloud")(true)}>
- Cloud
- </StyledToolElement>
- <StyledToolElement title="Download as File" onClick={handleSave}>
- Download
- </StyledToolElement>
- </Group>
+ <MediaQuery smallerThan="xs" styles={{ display: "none" }}>
+ <Group spacing="xs" position="left" w="100%" noWrap>
+ <StyledToolElement as="a" title="JSON Crack" href="https://jsoncrack.com">
+ <Flex gap="xs" align="center" justify="center">
+ <StyledLogo
+ src="/assets/icon.png"
+ width="auto"
+ height="16"
+ alt="logo"
+ invert={lightmode}
+ />
+ </Flex>
+ </StyledToolElement>
+ <StyledToolElement title="Import File" onClick={() => setVisible("import")(true)}>
+ Import
+ </StyledToolElement>
+ <Menu shadow="md" closeOnItemClick={false}>
+ <Menu.Target>
+ <StyledToolElement>
+ <Flex align="center" gap={3}>
+ View <CgChevronDown />
+ </Flex>
+ </StyledToolElement>
+ </Menu.Target>
+ <Menu.Dropdown>
+ <Menu.Item
+ fz={12}
+ onClick={toggleEditor}
+ icon={fullscreen ? <VscLayoutSidebarLeft /> : <VscLayoutSidebarLeftOff />}
+ rightSection={
+ <Text ml="md" fz={10} color="dimmed">
+ {CoreKey} Shift E
+ </Text>
+ }
+ >
+ {fullscreen ? "Show" : "Hide"} Editor
+ </Menu.Item>
+ <Menu.Item
+ fz={12}
+ onClick={toggleDirection}
+ icon={<StyledFlowIcon rotate={rotateLayout(direction)} />}
+ rightSection={
+ <Text ml="md" fz={10} color="dimmed">
+ {CoreKey} Shift D
+ </Text>
+ }
+ >
+ Rotate Layout
+ </Menu.Item>
+ <Menu.Item
+ fz={12}
+ onClick={toggleFoldNodes}
+ icon={foldNodes ? <CgArrowsShrinkH /> : <CgArrowsMergeAltH />}
+ rightSection={
+ <Text ml="md" fz={10} color="dimmed">
+ {CoreKey} Shift F
+ </Text>
+ }
+ >
+ {foldNodes ? "Unfold" : "Fold"} Nodes
+ </Menu.Item>
+ <Menu.Item
+ fz={12}
+ onClick={toggleExpandCollapseGraph}
+ icon={graphCollapsed ? <VscExpandAll /> : <VscCollapseAll />}
+ rightSection={
+ <Text ml="md" fz={10} color="dimmed">
+ {CoreKey} Shift C
+ </Text>
+ }
+ >
+ {graphCollapsed ? "Expand" : "Collapse"} Nodes
+ </Menu.Item>
+ </Menu.Dropdown>
+ </Menu>
+ <Menu shadow="md">
+ <Menu.Target>
+ <StyledToolElement>
+ <Flex align="center" gap={3}>
+ Tools <CgChevronDown />
+ </Flex>
+ </StyledToolElement>
+ </Menu.Target>
+ <Menu.Dropdown>
+ <Menu.Item fz={12} icon={<VscJson />} onClick={() => setVisible("schema")(true)}>
+ JSON Schema
+ </Menu.Item>
+ <Menu.Item
+ fz={12}
+ icon={<SiJsonwebtokens />}
+ onClick={() => setVisible("jwt")(true)}
+ >
+ Decode JWT
+ </Menu.Item>
+ </Menu.Dropdown>
+ </Menu>
+ <StyledToolElement title="Cloud" onClick={() => setVisible("cloud")(true)}>
+ Cloud
+ </StyledToolElement>
+ <StyledToolElement title="Download as File" onClick={handleSave}>
+ Download
+ </StyledToolElement>
+ </Group>
+ </MediaQuery>
)}
<Group spacing="xs" position="right" w="100%" noWrap>
<StyledToolElement title="Zoom Out" onClick={zoomOut}>
diff --git a/src/pages/editor.tsx b/src/pages/editor.tsx
index 048d648d..9ecdd2e2 100644
--- a/src/pages/editor.tsx
+++ b/src/pages/editor.tsx
@@ -16,12 +16,6 @@ import useUser from "src/store/useUser";
export const StyledPageWrapper = styled.div`
height: calc(100vh - 27px);
width: 100%;
-
- @media only screen and (max-width: 768px) {
- position: fixed;
- height: -webkit-fill-available;
- flex-direction: column;
- }
`;
export const StyledEditorWrapper = styled.div`
diff --git a/src/store/useUser.ts b/src/store/useUser.ts
index 702c7e62..616e06bf 100644
--- a/src/store/useUser.ts
+++ b/src/store/useUser.ts
@@ -6,6 +6,14 @@ import useModal from "./useModal";
const isDevelopment = process.env.NODE_ENV === "development";
+interface CustomUser extends User {
+ premium: {
+ status: boolean;
+ end_date: string;
+ };
+ type: 0 | 1;
+}
+
interface UserActions {
login: (response: AltogicAuth) => void;
logout: () => void;
@@ -27,17 +35,21 @@ const initialUser = () => {
lastLoginAt: "2023-05-13T09:56:02.915Z",
updatedAt: "2023-05-06T16:19:47.486Z",
type: 1,
- } as User;
- } else null;
+ } as CustomUser;
+ }
+ return null;
};
-const initialStates = {
+interface UserStates {
+ user: CustomUser | null;
+ isAuthenticated: boolean;
+}
+
+const initialStates: UserStates = {
isAuthenticated: isDevelopment,
- user: initialUser() as User | null,
+ user: initialUser(),
};
-export type UserStates = typeof initialStates;
-
const useUser = create<UserStates & UserActions>()((set, get) => ({
...initialStates,
setUser: (key, value) => set({ [key]: value }),
@@ -48,30 +60,41 @@ const useUser = create<UserStates & UserActions>()((set, get) => ({
if (user) return user.type > 0;
return false;
},
- logout: () => {
- altogic.auth.signOut();
+ logout: async () => {
+ const session = altogic.auth.getSession();
+ if (!session) return;
+
+ const { errors } = await altogic.auth.signOut(session.token);
+ if (errors?.items) return console.error(errors);
+
+ set(initialStates);
+ altogic.auth.clearLocalData();
toast.success("Logged out.");
useModal.setState({ account: false });
- set(initialStates);
- },
- login: response => {
- set({ user: response.user as any, isAuthenticated: true });
},
+ login: user => set({ user: user as unknown as CustomUser, isAuthenticated: true }),
checkSession: async () => {
const currentSession = altogic.auth.getSession();
if (currentSession) {
- const dbUser = await altogic.auth.getUserFromDB();
+ const { user, errors } = await altogic.auth.getUserFromDB();
+ if (errors?.items || !user) {
+ altogic.auth.clearLocalData();
+ return;
+ }
+ altogic.auth.setUser(user);
altogic.auth.setSession(currentSession);
- set({ user: dbUser.user as any, isAuthenticated: true });
- } else {
- if (!new URLSearchParams(window.location.search).get("access_token")) return;
- const data = await altogic.auth.getAuthGrant();
- if (!data.errors?.items.length) {
- set({ user: data.user as any, isAuthenticated: true });
+ set({ user: user as CustomUser, isAuthenticated: true });
+ } else if (new URLSearchParams(window.location.search).get("access_token")) {
+ const { errors, user } = await altogic.auth.getAuthGrant();
+ if (errors?.items) {
+ toast.error(errors.items[0].message);
+ return;
}
+
+ set({ user: user as CustomUser, isAuthenticated: true });
}
},
}));