Skip to content

Commit

Permalink
download JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
joonarafael committed Mar 31, 2024
1 parent 4eb0178 commit eef2736
Show file tree
Hide file tree
Showing 4 changed files with 6,118 additions and 8,688 deletions.
29 changes: 25 additions & 4 deletions app/calc/calculator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { useEffect, useState } from "react";
import PageError from "@/app/components/pageerror";

import generateAdjacencyList from "../algos/adjacency";
import dijkstra from "../algos/dijkstra";
import Container from "../components/container";
import LatencyChange from "./latencychange";
import Matrix from "./matrix";
import Menu from "./menu";
import ReplacingTool from "./replacingtool";
import eraseAdjacentConnections from "./supports/connections/eraseadjacentconnections";
import getColIndex from "./supports/getcolindex";
import getRowIndex from "./supports/getrowindex";
import twoDimIndexOf from "./supports/indexof";
import initConnection from "./supports/initconnection";
import replaceOldEntry from "./supports/replaceoldentry";
import ToolBar from "./toolbar";
import twoDimIndexOf from "./supports/indexof";
import dijkstra from "../algos/dijkstra";
import getColIndex from "./supports/getcolindex";
import getRowIndex from "./supports/getrowindex";

interface CalculatorProps {
width: number;
Expand Down Expand Up @@ -77,6 +77,26 @@ const Calculator: React.FC<CalculatorProps> = ({ width, height }) => {
console.log(fieldDelays);
};

const savePlan = () => {
const data = {
width: width,
height: height,
fieldStatus: fieldStatus,
fieldValues: fieldValues,
fieldDelays: fieldDelays,
};

const jsonString = `data:text/json;charset=utf-8,${encodeURIComponent(
JSON.stringify(data)
)}`;

const link = document.createElement("a");
link.href = jsonString;
link.download = "plan.json";

link.click();
};

const resetField = () => {
setSelectedBoreHole(null);
setTool("cursor");
Expand Down Expand Up @@ -272,6 +292,7 @@ const Calculator: React.FC<CalculatorProps> = ({ width, height }) => {
setIsLinking={setIsLinking}
replacingToolView={replacingToolView}
setReplacingToolView={setReplacingToolView}
savePlan={savePlan}
/>
<div className="flex flex-row gap-4">
<div className="border rounded-lg w-5/6 h-[80svh] overflow-scroll">
Expand Down
12 changes: 10 additions & 2 deletions app/calc/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface MenuProps {
setIsLinking: (value: boolean) => void;
replacingToolView: boolean;
setReplacingToolView: (value: boolean) => void;
savePlan: () => void;
}

const Menu: React.FC<MenuProps> = ({
Expand All @@ -43,6 +44,7 @@ const Menu: React.FC<MenuProps> = ({
latencySelection,
setReplacingToolView,
replacingToolView,
savePlan,
}) => {
const zoomIn = () => {
if (zoom < 6) {
Expand Down Expand Up @@ -89,7 +91,7 @@ const Menu: React.FC<MenuProps> = ({
<MenubarItem onClick={() => window.open("/calc/new", "_blank")}>
New Plan
</MenubarItem>
<MenubarItem disabled>Load Plan From Save Code</MenubarItem>
<MenubarItem disabled>Load Plan From File</MenubarItem>
<MenubarSeparator />
<MenubarItem
onClick={() => {
Expand All @@ -101,7 +103,13 @@ const Menu: React.FC<MenuProps> = ({
<MenubarSeparator />
<MenubarItem disabled>Analyze</MenubarItem>
<MenubarSeparator />
<MenubarItem disabled>Get Save Code</MenubarItem>
<MenubarItem
onClick={() => {
savePlan();
}}
>
Save Plan
</MenubarItem>
<MenubarItem disabled>Print</MenubarItem>
<MenubarSeparator />
<MenubarSub>
Expand Down
2 changes: 1 addition & 1 deletion app/homeclient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const HomeClient = () => {
NEW PLAN
</Button>
<Button variant={"outline"} disabled>
LOAD PLAN FROM SAVE CODE
LOAD PLAN FROM FILE
</Button>
</div>
</div>
Expand Down
Loading

0 comments on commit eef2736

Please sign in to comment.