From 76744c1b6f6a6a70924adba3ba4f2aa230b72f3a Mon Sep 17 00:00:00 2001 From: csawatzky Date: Thu, 17 Apr 2025 14:35:24 -0600 Subject: [PATCH] updated the bin yard api with as fix --- src/bin/BinSettings.tsx | 2 +- src/bin/BinYards.tsx | 8 +++--- src/maps/mapDrawers/BinYardDrawer.tsx | 7 +++--- .../mapObjectControllers/AgMapController.tsx | 6 ++--- src/providers/pond/binYardAPI.tsx | 25 +++++++++++-------- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/bin/BinSettings.tsx b/src/bin/BinSettings.tsx index 46d3b59..3a9f15d 100644 --- a/src/bin/BinSettings.tsx +++ b/src/bin/BinSettings.tsx @@ -344,7 +344,7 @@ export default function BinSettings(props: Props) { setBinYardOptions(y); } else { binYardAPI - .listBinYards(350, 0, "desc", as ? as : userID) + .listBinYards(350, 0, "desc", as ? as : userID, undefined, undefined, undefined, as) .then(resp => { let data = resp.data.yard ? resp.data.yard : []; let yards: Option[] = data.map((yard: pond.BinYard) => { diff --git a/src/bin/BinYards.tsx b/src/bin/BinYards.tsx index 0d371f0..b1031be 100644 --- a/src/bin/BinYards.tsx +++ b/src/bin/BinYards.tsx @@ -210,7 +210,7 @@ export default function BinYard(props: Props) { const [leaving, setLeaving] = useState(false); const [yardPermissions, setYardPermissions] = useState>({}); const [searchSelected, setSearchSelected] = useState(false); - const [{ user }] = useGlobalState(); + const [{ user, as }] = useGlobalState(); const [addingYard, setAddingYard] = useState(false) useEffect(() => { @@ -240,7 +240,7 @@ export default function BinYard(props: Props) { newBinYard.description = addYardDescription; newBinYard.owner = user.id(); binYardAPI - .addBinYard(newBinYard) + .addBinYard(newBinYard, as) .then(resp => { // loadYards(); let newYards = [...binYards] @@ -271,7 +271,7 @@ export default function BinYard(props: Props) { newBinYard.name = addYardName; newBinYard.description = addYardDescription; binYardAPI - .updateBinYard(newBinYard.key, newBinYard) + .updateBinYard(newBinYard.key, newBinYard, undefined, as) .then(_resp => { loadYards(); openSnackbar("success", "Bin Yard updated"); @@ -355,7 +355,7 @@ export default function BinYard(props: Props) { const deleteYard = (index: number) => { let newBinYards = binYards; binYardAPI - .removeBinYard(binYards[index].key) + .removeBinYard(binYards[index].key, as) .then(_resp => { newBinYards.splice(index, 1); if (index + 1 === tab) { diff --git a/src/maps/mapDrawers/BinYardDrawer.tsx b/src/maps/mapDrawers/BinYardDrawer.tsx index 242c756..3153901 100644 --- a/src/maps/mapDrawers/BinYardDrawer.tsx +++ b/src/maps/mapDrawers/BinYardDrawer.tsx @@ -3,7 +3,7 @@ import DisplayDrawer from "common/DisplayDrawer"; import MapMarkerSettings from "maps/MapMarkerSettings"; //import Bins from "pages/Bins"; import { pond } from "protobuf-ts/pond"; -import { useBinYardAPI, useSnackbar } from "providers"; +import { useBinYardAPI, useGlobalState, useSnackbar } from "providers"; import React, { useEffect, useState } from "react"; interface Props { @@ -18,6 +18,7 @@ interface Props { export default function BinYardDrawer(props: Props) { const { open, onClose, selectedYard, yards, removeMarker, updateMarker, moveMap } = props; + const [{as}] = useGlobalState(); const [yard, setYard] = useState(pond.BinYardSettings.create()); const [openMarkerSettings, setOpenMarkerSettings] = useState(false); const { openSnack } = useSnackbar(); @@ -96,7 +97,7 @@ export default function BinYardDrawer(props: Props) { settings.longitude = 0; settings.latitude = 0; binyardAPI - .updateBinYard(yard.key, settings) + .updateBinYard(yard.key, settings, undefined, as) .then(resp => { openSnack("Marker Removed"); //then use the removeMarker prop function to update the markers in the parent map @@ -138,7 +139,7 @@ export default function BinYardDrawer(props: Props) { let settings = yard; settings.theme = newTheme; binyardAPI - .updateBinYard(yard.key, settings) + .updateBinYard(yard.key, settings, undefined, as) .then(resp => { openSnack("marker settings updated"); updateMarker(yard.key, settings); diff --git a/src/maps/mapObjectControllers/AgMapController.tsx b/src/maps/mapObjectControllers/AgMapController.tsx index 068b1b6..57fea0a 100644 --- a/src/maps/mapObjectControllers/AgMapController.tsx +++ b/src/maps/mapObjectControllers/AgMapController.tsx @@ -376,7 +376,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder"; let yardEntries: Result[] = []; binYardAPI - .listBinYards(400, 0, "asc") + .listBinYards(400, 0, "asc", undefined, undefined, undefined, undefined, as) .then(resp => { resp.data.yard.forEach(yard => { if (yard.settings) { @@ -433,7 +433,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder"; .catch(() => { openSnack("Failed to load yard data"); }); - }, [binYardAPI, openSnack]); // eslint-disable-line react-hooks/exhaustive-deps + }, [binYardAPI, openSnack, as]); // eslint-disable-line react-hooks/exhaustive-deps const loadBins = useCallback(() => { binAPI @@ -931,7 +931,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder"; yard.longitude = long; yard.latitude = lat; binYardAPI - .updateBinYard(yard.key, yard) + .updateBinYard(yard.key, yard, undefined, as) .then(resp => { openSnack("BinYard Location Updated"); if (yardOptions.includes(yard)) { diff --git a/src/providers/pond/binYardAPI.tsx b/src/providers/pond/binYardAPI.tsx index f07a591..263f88c 100644 --- a/src/providers/pond/binYardAPI.tsx +++ b/src/providers/pond/binYardAPI.tsx @@ -7,14 +7,15 @@ import { AxiosResponse } from "axios"; import { useGlobalState } from "providers"; export interface IBinYardAPIContext { - addBinYard: (bin: pond.BinYardSettings) => Promise>; + addBinYard: (bin: pond.BinYardSettings, as?: string) => Promise>; updateBinYard: ( key: string, binYard: pond.BinYardSettings, - asRoot?: true + asRoot?: true, + as?: string ) => Promise>; - removeBinYard: (key: string) => Promise>; - getBinYard: (key: string) => Promise>; + removeBinYard: (key: string, as?: string) => Promise>; + getBinYard: (key: string, as?: string) => Promise>; listBinYards: ( limit: number, offset: number, @@ -22,7 +23,8 @@ export interface IBinYardAPIContext { orderBy?: string, search?: string, asRoot?: boolean, - specificUser?: string + specificUser?: string, + as?: string ) => Promise>; } @@ -33,14 +35,14 @@ interface Props {} export default function BinYardProvider(props: PropsWithChildren) { const { children } = props; const { get, post, put, del } = useHTTP(); - const [{ as }] = useGlobalState(); + //const [{ as }] = useGlobalState(); - const addBinYard = (binYard: pond.BinYardSettings) => { + const addBinYard = (binYard: pond.BinYardSettings, as?: string) => { if (as) return post(pondURL(`/binyard?as=${as}`), binYard); return post(pondURL("/binyard"), binYard); }; - const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean) => { + const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean, as?: string) => { if (as) { if (asRoot) { return put( @@ -58,12 +60,12 @@ export default function BinYardProvider(props: PropsWithChildren) { ); }; - const removeBinYard = (key: string) => { + const removeBinYard = (key: string, as?: string) => { if (as) return del(pondURL("/binyard/" + key + "?as=" + as)); return del(pondURL("/binyard/" + key)); }; - const getBinYard = (key: string) => { + const getBinYard = (key: string, as?: string) => { if (as) return get(pondURL("/binYard/" + key + "?as=" + as)); return get(pondURL("/binYard/" + key)); }; @@ -75,7 +77,8 @@ export default function BinYardProvider(props: PropsWithChildren) { orderBy?: string, search?: string, asRoot?: boolean, - specificUser?: string + specificUser?: string, + as?: string ) => { let asText = ""; if (as) asText = "&as=" + as;