Skip to content

Commit

Permalink
fix: error & premium views
Browse files Browse the repository at this point in the history
  • Loading branch information
AykutSarac committed Aug 14, 2023
1 parent 3e8b268 commit 2b8ed62
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/components/Graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ const GraphCanvas = ({ isWidget }: { isWidget: boolean }) => {
const centerView = useGraph(state => state.centerView);
const setSelectedNode = useGraph(state => state.setSelectedNode);
const setVisible = useModal(state => state.setVisible);
const isPremium = useUser(state => state.premium);
const direction = useGraph(state => state.direction);
const nodes = useGraph(state => state.nodes);
const edges = useGraph(state => state.edges);
Expand Down Expand Up @@ -142,12 +141,6 @@ const GraphCanvas = ({ isWidget }: { isWidget: boolean }) => {
[]
);

if (nodes.length > 6_000) return <ErrorView />;

if (nodes.length > 250 && !isWidget) {
if (!isPremium) return <PremiumView />;
}

return (
<Canvas
className="jsoncrack-canvas"
Expand Down Expand Up @@ -177,6 +170,10 @@ const GraphCanvas = ({ isWidget }: { isWidget: boolean }) => {

export const Graph = ({ isWidget = false }: GraphProps) => {
const setViewPort = useGraph(state => state.setViewPort);
const isPremium = useUser(state => state.premium);
const viewType = useGraph(state =>
state.nodes.length > 6_000 ? "error" : state.nodes.length > 250 ? "premium" : "graph"
);

const callback = React.useCallback(() => {
const canvas = document.querySelector(".jsoncrack-canvas") as HTMLDivElement | null;
Expand All @@ -195,6 +192,12 @@ export const Graph = ({ isWidget = false }: GraphProps) => {
if ("activeElement" in document) (document.activeElement as HTMLElement)?.blur();
}, []);

if (viewType === "error") return <ErrorView />;

if (viewType === "premium" && !isWidget) {
if (!isPremium) return <PremiumView />;
}

return (
<>
<Loading message="Painting graph..." />
Expand Down

1 comment on commit 2b8ed62

@vercel
Copy link

@vercel vercel bot commented on 2b8ed62 Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.