diff --git a/src/gate/GateDevice.tsx b/src/gate/GateDevice.tsx index 3018a56..7ab8efc 100644 --- a/src/gate/GateDevice.tsx +++ b/src/gate/GateDevice.tsx @@ -32,6 +32,7 @@ interface Props { export default function GateDevice(props: Props) { const { gate, comprehensiveDevice, linkedCompList, drawerView } = props; + const [{as}] = useGlobalState(); const [device, setDevice] = useState(Device.create()); const [componentOptions, setComponentOptions] = useState>( new Map() @@ -159,7 +160,8 @@ export default function GateDevice(props: Props) { device.id() + ":" + componentKey, gateCompType, [gate.key], - ["gate"] + ["gate"], + as ) .then(resp => { openSnack("Component Prefence Updated"); diff --git a/src/gate/GateFlowGraph.tsx b/src/gate/GateFlowGraph.tsx index c37b106..9e05ea9 100644 --- a/src/gate/GateFlowGraph.tsx +++ b/src/gate/GateFlowGraph.tsx @@ -14,7 +14,7 @@ import SingleSetAreaChart, { SSAreaDataPoint } from "charts/SingleSetAreaChart"; import { Gate } from "models/Gate"; import moment, { Moment } from "moment"; import { pond } from "protobuf-ts/pond"; -import { useGateAPI } from "providers"; +import { useGateAPI, useGlobalState } from "providers"; import React, { useEffect, useState } from "react"; interface Props { @@ -61,6 +61,7 @@ export default function GateFlowGraph(props: Props) { newXDomain, multiGraphZoom } = props; + const [{as}] = useGlobalState(); const gateAPI = useGateAPI(); const [flowData, setFlowData] = useState([]); const [loadingChartData, setLoadingChartData] = useState(false); @@ -84,7 +85,10 @@ export default function GateFlowGraph(props: Props) { ambient, pressureComponent, start.toISOString(), - end.toISOString() + end.toISOString(), + undefined, + undefined, + as ) .then(resp => { let data: SSAreaDataPoint[] = []; @@ -135,7 +139,7 @@ export default function GateFlowGraph(props: Props) { setRecent(recent); }); } - }, [gateAPI, gate, ambient, pressureComponent, start, end, device, setPCAState]); // eslint-disable-line react-hooks/exhaustive-deps + }, [gateAPI, gate, ambient, pressureComponent, start, end, device, setPCAState, as]); // eslint-disable-line react-hooks/exhaustive-deps const loadFlowEvents = () => { if (ambient && pressureComponent) { @@ -149,7 +153,10 @@ export default function GateFlowGraph(props: Props) { start.toISOString(), end.toISOString(), idleFlow, - eventThreshold + eventThreshold, + undefined, + undefined, + as ) .then(resp => { console.log(resp); diff --git a/src/gate/GateGraphs.tsx b/src/gate/GateGraphs.tsx index 19f2fda..911d525 100644 --- a/src/gate/GateGraphs.tsx +++ b/src/gate/GateGraphs.tsx @@ -60,6 +60,7 @@ const useStyles = makeStyles((theme: Theme) => ({ export default function GateGraphs(props: Props) { const { gate, display, compMap, device, pressure, ambient, setPCAState } = props; + const [{ as }] = useGlobalState(); const [xDomain, setXDomain] = useState(["dataMin", "dataMax"]); const [zoomed, setZoomed] = useState(false); const defaultDateRange = GetDefaultDateRange(); @@ -79,7 +80,7 @@ export default function GateGraphs(props: Props) { setLoading(true); let measurementMap: Map = new Map(); gateAPI - .listGateMeasurements(gate.key, startDate.toISOString(), endDate.toISOString()) + .listGateMeasurements(gate.key, startDate.toISOString(), endDate.toISOString(), as) .then(resp => { resp.data.measurements.forEach(um => { let unitMeasurement = UnitMeasurement.any(um, user); @@ -93,7 +94,7 @@ export default function GateGraphs(props: Props) { setLoading(false); setCompMeasurements(measurementMap); }); - }, [gate, endDate, gateAPI, startDate]); // eslint-disable-line react-hooks/exhaustive-deps + }, [gate, endDate, gateAPI, startDate, as]); // eslint-disable-line react-hooks/exhaustive-deps const updateDateRange = (newStartDate: any, newEndDate: any) => { let range = GetDefaultDateRange(); diff --git a/src/gate/GateList.tsx b/src/gate/GateList.tsx index c43a837..8f0c8bc 100644 --- a/src/gate/GateList.tsx +++ b/src/gate/GateList.tsx @@ -10,7 +10,7 @@ import { makeStyles } from "@mui/styles"; import ResponsiveTable, { Column } from "common/ResponsiveTable"; import AddGateFab from "./AddGateFab"; import GateSettings from "./GateSettings"; -import { useGateAPI } from "providers"; +import { useGateAPI, useGlobalState } from "providers"; import { Settings } from "@mui/icons-material"; interface Props { @@ -38,7 +38,8 @@ const useStyles = makeStyles((theme: Theme) => ({ })); export default function GateList(props: Props) { -const {terminals, currentTerminal } = props; + const {terminals, currentTerminal } = props; + const [{as}] = useGlobalState(); // const history = useHistory(); const navigate = useNavigate(); const isMobile = useMobile(); @@ -73,11 +74,11 @@ const {terminals, currentTerminal } = props; keys = [currentTerminal] types = ["terminal"] } - gateAPI.listGates(pageSize, pageSize * tablePage, "asc", "name", search, undefined, keys, types).then(resp => { + gateAPI.listGates(pageSize, pageSize * tablePage, "asc", "name", search, undefined, keys, types, undefined, undefined, as).then(resp => { setGates(resp.data.gates.map(gate => Gate.create(gate))) setTotal(resp.data.total) }) - },[currentTerminal, search, pageSize, tablePage]) + },[currentTerminal, search, pageSize, tablePage, as]) useEffect(() => { loadGates() diff --git a/src/gate/GateSettings.tsx b/src/gate/GateSettings.tsx index a458f17..b4a1d92 100644 --- a/src/gate/GateSettings.tsx +++ b/src/gate/GateSettings.tsx @@ -19,7 +19,7 @@ import ResponsiveDialog from "common/ResponsiveDialog"; import { Terminal } from "models/Terminal"; import { Gate } from "models/Gate"; import { pond } from "protobuf-ts/pond"; -import { useTerminalAPI, useGateAPI } from "providers"; +import { useTerminalAPI, useGateAPI, useGlobalState } from "providers"; import React, { useEffect, useState } from "react"; import { useSnackbar } from "hooks"; //import { useHistory } from "react-router"; @@ -48,6 +48,7 @@ const steps = ["Gate", "Duct"]; export default function GateSettings(props: Props) { const { open, close, terminals, gate, long, lat } = props; + const [{as}] = useGlobalState(); const [gateName, setGateName] = useState(""); const [lowerFlowBound, setLowerFlowBound] = useState(0); const [upperFlowBound, setUpperFlowBound] = useState(0); @@ -83,7 +84,7 @@ export default function GateSettings(props: Props) { if (loadingTerminals) return; setLoadingTerminals(true); terminalAPI - .listTerminals(500, 0) + .listTerminals(500, 0, undefined, undefined, undefined, as) .then(resp => { setTerminalOptions(resp.data.terminals.map(a => Terminal.any(a))); }) @@ -95,7 +96,7 @@ export default function GateSettings(props: Props) { setTerminalOptions(terminals); } //eslint-disable-next-line react-hooks/exhaustive-deps - }, [terminals, terminalAPI]); + }, [terminals, terminalAPI, as]); useEffect(() => { if (gate) { @@ -146,7 +147,7 @@ export default function GateSettings(props: Props) { settings.hourlyApuCost = hourlyAPU; settings.hourlyPcaCost = hourlyPCA; gateAPI - .updateGate(gate.key, gateName, settings) + .updateGate(gate.key, gateName, settings, as) .then(resp => { openSnack("Gate update"); close(); @@ -174,7 +175,7 @@ export default function GateSettings(props: Props) { hourlyPcaCost: hourlyPCA }); gateAPI - .addGate(gateName, settings) + .addGate(gateName, settings, as) .then(resp => { openSnack("New gate added"); let newGate = Gate.create( @@ -191,7 +192,7 @@ export default function GateSettings(props: Props) { const remove = () => { if (gate) { gateAPI - .removeGate(gate.key) + .removeGate(gate.key, as) .then(resp => { openSnack("Gate Deleted"); }) diff --git a/src/maps/mapDrawers/GateDrawer.tsx b/src/maps/mapDrawers/GateDrawer.tsx index c516e8f..f9eb7ce 100644 --- a/src/maps/mapDrawers/GateDrawer.tsx +++ b/src/maps/mapDrawers/GateDrawer.tsx @@ -1,7 +1,7 @@ import DisplayDrawer from "common/DisplayDrawer"; import { Gate as IGate } from "models/Gate"; import Gate from "pages/Gate"; -import { useGateAPI, useSnackbar } from "providers"; +import { useGateAPI, useGlobalState, useSnackbar } from "providers"; import React, { useEffect, useState } from "react"; interface Props { @@ -15,6 +15,7 @@ interface Props { export default function GateDrawer(props: Props) { const { open, onClose, gates, selectedGate, moveMap, removeMarker } = props; + const [{as}] = useGlobalState(); const [gate, setGate] = useState(IGate.create()); const gateAPI = useGateAPI(); const { openSnack } = useSnackbar(); @@ -91,7 +92,7 @@ export default function GateDrawer(props: Props) { settings.longitude = 0; settings.latitude = 0; gateAPI - .updateGate(gate.key, gate.name, settings) + .updateGate(gate.key, gate.name, settings, as) .then(resp => { openSnack("Marker Removed"); //then use the removeMarker prop function to update the markers in the parent map diff --git a/src/maps/mapDrawers/TerminalDrawer.tsx b/src/maps/mapDrawers/TerminalDrawer.tsx index 4c1387d..10e3b28 100644 --- a/src/maps/mapDrawers/TerminalDrawer.tsx +++ b/src/maps/mapDrawers/TerminalDrawer.tsx @@ -1,7 +1,7 @@ import DisplayDrawer from "common/DisplayDrawer"; import { Terminal as ITerminal } from "models/Terminal"; import Terminal from "pages/Terminals"; -import { useSnackbar, useTerminalAPI } from "providers"; +import { useGlobalState, useSnackbar, useTerminalAPI } from "providers"; import React, { useState, useEffect } from "react"; interface Props { @@ -15,6 +15,7 @@ interface Props { export default function TerminalDrawer(props: Props) { const { terminals, selectedKey, open, onClose, moveMap, removeMarker } = props; + const [{as}] = useGlobalState(); const [terminal, setTerminal] = useState(ITerminal.create()); const terminalAPI = useTerminalAPI(); const { openSnack } = useSnackbar(); @@ -91,7 +92,7 @@ export default function TerminalDrawer(props: Props) { settings.longitude = 0; settings.latitude = 0; terminalAPI - .updateTerminal(terminal.key, terminal.name, settings) + .updateTerminal(terminal.key, terminal.name, settings, as) .then(resp => { openSnack("Marker Removed"); //then use the removeMarker prop function to update the markers in the parent map diff --git a/src/maps/mapObjectControllers/AviationMapController.tsx b/src/maps/mapObjectControllers/AviationMapController.tsx index 9a83fd9..0e13ed4 100644 --- a/src/maps/mapObjectControllers/AviationMapController.tsx +++ b/src/maps/mapObjectControllers/AviationMapController.tsx @@ -31,7 +31,7 @@ interface Props { } export default function AviationMapController(props: Props) { - const [{ user }] = useGlobalState(); + const [{ user, as }] = useGlobalState(); const transDuration = 3000; const [currentView, setCurrentView] = useState( props.startingView @@ -99,7 +99,7 @@ export default function AviationMapController(props: Props) { settings.longitude = longitude; settings.latitude = latitude; terminalAPI - .updateTerminal(terminal.key, terminal.name, settings) + .updateTerminal(terminal.key, terminal.name, settings, as) .then(resp => { openSnack("Terminal Location Updated"); if (newMarker) { @@ -139,7 +139,7 @@ export default function AviationMapController(props: Props) { settings.longitude = longitude; settings.latitude = latitude; gateAPI - .updateGate(gate.key, gate.name, settings) + .updateGate(gate.key, gate.name, settings, as) .then(resp => { openSnack("Gate Location Updated"); if (newMarker) { @@ -170,7 +170,7 @@ export default function AviationMapController(props: Props) { }; const loadTerminals = useCallback(() => { - terminalAPI.listTerminals(0, 0, undefined, undefined, undefined).then(resp => { + terminalAPI.listTerminals(0, 0, undefined, undefined, undefined, as).then(resp => { let terminalMap: Map = new Map(); let terminalMarkers: Map = new Map(); let terminalOps: Terminal[] = []; @@ -212,10 +212,10 @@ export default function AviationMapController(props: Props) { setTerminalSearchEntries(searchEntries); setTerminalOptions(terminalOps); }); - }, [terminalAPI]); // eslint-disable-line react-hooks/exhaustive-deps + }, [terminalAPI, as]); // eslint-disable-line react-hooks/exhaustive-deps const loadGates = useCallback(() => { - gateAPI.listGates(0, 0, undefined, undefined, undefined, true).then(resp => { + gateAPI.listGates(0, 0, undefined, undefined, undefined, true, undefined, undefined, undefined, undefined, as).then(resp => { let gates: Map = new Map(); let gateOptions: Gate[] = []; let gateMarkers: Map = new Map(); @@ -255,7 +255,7 @@ export default function AviationMapController(props: Props) { setGateMarkers(gateMarkers); setGateSearchEntries(searchEntries); }); - }, [gateAPI]); // eslint-disable-line react-hooks/exhaustive-deps + }, [gateAPI, as]); // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { loadTerminals(); diff --git a/src/pages/Gate.tsx b/src/pages/Gate.tsx index 310ae3f..e45ffae 100644 --- a/src/pages/Gate.tsx +++ b/src/pages/Gate.tsx @@ -132,7 +132,7 @@ export default function Gate(props: Props) { if (loadingGate || id === undefined || id === "") return; setLoadingGate(true); gateAPI - .getGatePageData(id) + .getGatePageData(id, as) .then(resp => { //console.log(resp.data); let p = new Map(); @@ -168,7 +168,7 @@ export default function Gate(props: Props) { setLoadingGate(false); }); //eslint-disable-next-line react-hooks/exhaustive-deps - }, [gateAPI, gateID]); + }, [gateAPI, gateID, as]); useEffect(() => { loadGate(); @@ -176,7 +176,7 @@ export default function Gate(props: Props) { const updateGateDevicePrefs = (deviceID: number, newPref: pond.GateDeviceType) => { gateAPI - .updatePrefs(gate.key, "device", deviceID.toString(), newPref, [gate.key], ["gate"]) + .updatePrefs(gate.key, "device", deviceID.toString(), newPref, [gate.key], ["gate"], as) .then(resp => { openSnack("Updated gate device type"); // have to do the clone method to force the select box to update @@ -226,7 +226,7 @@ export default function Gate(props: Props) { "write", "grant", "revoke" - ]) + ], as) .then(resp => { if (id) { devMap.set(id.toString(), device); @@ -238,7 +238,7 @@ export default function Gate(props: Props) { console.log("error linking device"); }); } else { - gateAPI.updateLink(gateID, "gate", id.toString(), "device", []).then(resp => { + gateAPI.updateLink(gateID, "gate", id.toString(), "device", [], as).then(resp => { if (id) { devMap.delete(id.toString()); if (tabVal === id) { @@ -264,14 +264,14 @@ export default function Gate(props: Props) { "write", "grant", "revoke" - ]) + ],as) .then(resp => { c.push(component); setComponents([...c]); }); } else { gateAPI - .updateLink(gateID, "gate", deviceID + ":" + component.key(), "component", []) + .updateLink(gateID, "gate", deviceID + ":" + component.key(), "component", [], as) .then(resp => { c.forEach((comp, i) => { if (component.key() === comp.key()) { diff --git a/src/pages/Terminals.tsx b/src/pages/Terminals.tsx index 5a8db59..51aa2a7 100644 --- a/src/pages/Terminals.tsx +++ b/src/pages/Terminals.tsx @@ -181,14 +181,14 @@ export default function Terminals(props: Props) { const load = useCallback(() => { if(loading) return setLoading(true) - terminalAPI.listTerminals(200, 0, "asc", "name").then(resp => { + terminalAPI.listTerminals(200, 0, "asc", "name", as).then(resp => { setTerminals(resp.data.terminals.map(a => Terminal.any(a))); }).catch(err => { console.log("There was a problem loading Terminals") }).finally(() => { setLoading(false) }) - }, [terminalAPI, openSnack]); //eslint-disable-line react-hooks/exhaustive-deps + }, [terminalAPI, openSnack, as]); //eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { load(); @@ -197,7 +197,7 @@ export default function Terminals(props: Props) { const remove = () => { if (currentTerminal) { terminalAPI - .removeTerminal(currentTerminal.key) + .removeTerminal(currentTerminal.key, as) .then(resp => { openSnack("Terminal Deleted"); let a = terminals; diff --git a/src/providers/pond/gateAPI.tsx b/src/providers/pond/gateAPI.tsx index 2c1c08f..72035e5 100644 --- a/src/providers/pond/gateAPI.tsx +++ b/src/providers/pond/gateAPI.tsx @@ -8,7 +8,8 @@ import { useGlobalState } from "providers"; export interface IGateInterface { addGate: ( name: string, - settings: pond.GateSettings + settings: pond.GateSettings, + as?: string ) => Promise>; listGates: ( limit: number, @@ -20,21 +21,24 @@ export interface IGateInterface { keys?: string[], types?: string[], numerical?: boolean, - specificUser?: string + specificUser?: string, + as?: string ) => Promise>; updateGate: ( key: string, name: string, - settings: pond.GateSettings + settings: pond.GateSettings, + as?: string ) => Promise>; - getGate: (key: string) => Promise>; - removeGate: (key: string) => Promise>; + getGate: (key: string, as?: string) => Promise>; + removeGate: (key: string, as?: string) => Promise>; updateLink: ( parentKey: string, parentType: string, objectID: string, objectType: string, - permissions: string[] + permissions: string[], + as?: string ) => Promise; updatePrefs: ( gateKey: string, @@ -42,9 +46,10 @@ export interface IGateInterface { childKey: string, gatePref: pond.GateComponentType | pond.GateDeviceType, keys?: string[], - types?: string[] + types?: string[], + as?: string ) => Promise>; - getGatePageData: (key: string) => Promise>; + getGatePageData: (key: string, as?: string) => Promise>; listGateAirflow: ( gate: string, device: number | string, @@ -53,7 +58,8 @@ export interface IGateInterface { start: string, end: string, keys?: string[], - types?: string[] + types?: string[], + as?: string ) => Promise>; listGateFlowEvents: ( gate: string, @@ -65,12 +71,14 @@ export interface IGateInterface { idleFlow: number, flowVariance: number, keys?: string[], - types?: string[] + types?: string[], + as?: string ) => Promise>; listGateMeasurements: ( key: string, start: string, - end: string + end: string, + as?: string ) => Promise>; } @@ -81,9 +89,9 @@ interface Props {} export default function GateProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - const [{ as }] = useGlobalState(); + //const [{ as }] = useGlobalState(); - const addGate = (name: string, settings: pond.GateSettings) => { + const addGate = (name: string, settings: pond.GateSettings, as?: string) => { let url = pondURL("/gates?name=" + name + (as ? "&as=" + as : "")) return new Promise>((resolve, reject) => { post(url, settings).then(resp => { @@ -105,7 +113,8 @@ export default function GateProvider(props: PropsWithChildren) { keys?: string[], types?: string[], numerical?: boolean, - specificUser?: string + specificUser?: string, + as?: string ) => { let asText = ""; if (as) asText = "&as=" + as; @@ -134,7 +143,7 @@ export default function GateProvider(props: PropsWithChildren) { }) }; - const updateGate = (key: string, name: string, settings: pond.GateSettings) => { + const updateGate = (key: string, name: string, settings: pond.GateSettings, as?: string) => { let url = pondURL("/gates/" + key + "?name=" + name + (as ? "&as=" + as : "")) return new Promise>((resolve, reject) => { put(url, settings).then(resp => { @@ -146,7 +155,7 @@ export default function GateProvider(props: PropsWithChildren) { }) }; - const removeGate = (key: string) => { + const removeGate = (key: string, as?: string) => { let url = pondURL("/gates/" + key + (as ? "?as=" + as : "")) return new Promise>((resolve, reject) => { del(url).then(resp => { @@ -158,7 +167,7 @@ export default function GateProvider(props: PropsWithChildren) { }) }; - const getGate = (key: string) => { + const getGate = (key: string, as?: string) => { let url = pondURL("/gates/" + key + (as ? "?as=" + as : "")) return new Promise>((resolve, reject) => { get(url).then(resp => { @@ -170,7 +179,7 @@ export default function GateProvider(props: PropsWithChildren) { }) }; - const getGatePageData = (key: string) => { + const getGatePageData = (key: string, as?: string) => { let url = pondURL("/gatePage/" + key + (as ? "?as=" + as : "")) return new Promise>((resolve, reject) => { get(url).then(resp => { @@ -187,7 +196,8 @@ export default function GateProvider(props: PropsWithChildren) { parentType: string, objectID: string, objectType: string, - permissions: string[] + permissions: string[], + as?: string ) => { let url = pondURL(`/gates/` + parentID + "/link" + (as ? `?as=${as}` : "")) return new Promise((resolve, reject) => { @@ -212,7 +222,8 @@ export default function GateProvider(props: PropsWithChildren) { childKey: string, gatePref: pond.GateComponentType | pond.GateDeviceType, keys?: string[], - types?: string[] + types?: string[], + as?: string ) => { let url = pondURL( `/gatePrefs/` + @@ -245,7 +256,8 @@ export default function GateProvider(props: PropsWithChildren) { start: string, end: string, keys?: string[], - types?: string[] + types?: string[], + as?: string ) => { let url = pondURL( "/gates/" + @@ -274,7 +286,7 @@ export default function GateProvider(props: PropsWithChildren) { }) }; - const listGateMeasurements = (key: string, start: string, end: string) => { + const listGateMeasurements = (key: string, start: string, end: string, as?: string) => { let url = pondURL("/gates/" + key + "/measurements?start=" + start + "&end=" + end + "&as=" + as) return new Promise>((resolve, reject) => { get(url).then(resp => { @@ -296,7 +308,8 @@ export default function GateProvider(props: PropsWithChildren) { idleFlow: number, flowVariance: number, keys?: string[], - types?: string[] + types?: string[], + as?: string ) => { return get( pondURL( diff --git a/src/providers/pond/terminalAPI.tsx b/src/providers/pond/terminalAPI.tsx index 94ef7d0..ec8d586 100644 --- a/src/providers/pond/terminalAPI.tsx +++ b/src/providers/pond/terminalAPI.tsx @@ -8,28 +8,32 @@ import { useGlobalState } from "providers"; export interface ITerminalAPIContext { addTerminal: ( name: string, - terminal: pond.TerminalSettings + terminal: pond.TerminalSettings, + as?: string ) => Promise>; listTerminals: ( limit: number, offset: number, order?: "asc" | "desc", orderBy?: string, - search?: string + search?: string, + as?: string ) => Promise>; listTerminalsAndGates: ( limit: number, offset: number, order?: "asc" | "desc", orderBy?: string, - search?: string + search?: string, + as?: string ) => Promise>; updateTerminal: ( key: string, name: string, - settings: pond.TerminalSettings + settings: pond.TerminalSettings, + as?: string ) => Promise>; - removeTerminal: (key: string) => Promise>; + removeTerminal: (key: string, as?: string) => Promise>; } export const TerminalAPIContext = createContext({} as ITerminalAPIContext); @@ -39,9 +43,9 @@ interface Props {} export default function TerminalProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - const [{ as }] = useGlobalState(); + //const [{ as }] = useGlobalState(); - const addTerminal = (name: string, terminal: pond.TerminalSettings) => { + const addTerminal = (name: string, terminal: pond.TerminalSettings, as?: string) => { if (as) return post( pondURL("/terminals?name=" + name + "&as=" + as), @@ -55,7 +59,8 @@ export default function TerminalProvider(props: PropsWithChildren) { offset: number, order?: "asc" | "desc", orderBy?: string, - search?: string + search?: string, + as?: string ) => { if (as) return get( @@ -89,7 +94,8 @@ export default function TerminalProvider(props: PropsWithChildren) { offset: number, order?: "asc" | "desc", orderBy?: string, - search?: string + search?: string, + as?: string ) => { if (as) return get( @@ -118,7 +124,7 @@ export default function TerminalProvider(props: PropsWithChildren) { ); }; - const updateTerminal = (key: string, name: string, settings: pond.TerminalSettings) => { + const updateTerminal = (key: string, name: string, settings: pond.TerminalSettings, as?: string) => { if (as) { return put( pondURL("/terminals/" + key + "?as=" + as + "&name=" + name), @@ -131,7 +137,7 @@ export default function TerminalProvider(props: PropsWithChildren) { ); }; - const removeTerminal = (key: string) => { + const removeTerminal = (key: string, as?: string) => { if (as) { return del(pondURL("/terminals/" + key + "?as=" + as)); } diff --git a/src/terminal/TerminalSettings.tsx b/src/terminal/TerminalSettings.tsx index 8cf694b..7894d5b 100644 --- a/src/terminal/TerminalSettings.tsx +++ b/src/terminal/TerminalSettings.tsx @@ -1,7 +1,7 @@ import { Button, DialogActions, DialogContent, DialogTitle, TextField } from "@mui/material"; import ResponsiveDialog from "common/ResponsiveDialog"; import { useEffect, useState } from "react"; -import { useTerminalAPI } from "providers"; +import { useGlobalState, useTerminalAPI } from "providers"; import { useSnackbar } from "hooks"; import { pond } from "protobuf-ts/pond"; import { Terminal } from "models/Terminal"; @@ -16,6 +16,7 @@ interface Props { export default function TerminalSettings(props: Props) { const { open, closeDialog, terminal, long, lat } = props; + const [{as}] = useGlobalState(); const terminalAPI = useTerminalAPI(); const [name, setName] = useState(""); const { openSnack } = useSnackbar(); @@ -35,7 +36,7 @@ export default function TerminalSettings(props: Props) { terminal.name = name; //note: changing the terminal object passed in WILL in fact change it in the parent terminalAPI - .updateTerminal(terminal.key, terminal.name, terminal.settings) + .updateTerminal(terminal.key, terminal.name, terminal.settings, as) .then(resp => { openSnack("Terminal updated"); closeDialog(); @@ -49,7 +50,7 @@ export default function TerminalSettings(props: Props) { latitude: lat }); terminalAPI - .addTerminal(name, settings) + .addTerminal(name, settings, as) .then(resp => { openSnack("New terminal added"); let newTerminal = Terminal.create(