update to mine api for as to be passed in to the functions

This commit is contained in:
csawatzky 2025-04-21 13:24:26 -06:00
parent 022837de87
commit 9b9f4cdf63
9 changed files with 50 additions and 34 deletions

View file

@ -8,6 +8,7 @@ import {
import ResponsiveDialog from "common/ResponsiveDialog";
import { useMineAPI } from "hooks";
import { pond } from "protobuf-ts/pond";
import { useGlobalState } from "providers";
import { useState } from "react";
interface Props {
@ -20,11 +21,12 @@ export default function AddMine(props: Props) {
const { open, closeCallback, refreshCallback } = props;
const [name, setName] = useState("");
const mineAPI = useMineAPI();
const [{as}] = useGlobalState();
const addMine = () => {
let newMine = pond.MineSettings.create();
newMine.name = name;
mineAPI.addMine(newMine).finally(() => {
mineAPI.addMine(newMine, as).finally(() => {
closeCallback();
refreshCallback();
});

View file

@ -111,14 +111,14 @@ export default function Editor(props: Props) {
undefined | Map<string, UnitMeasurement[]>
>(undefined);
const [{ user }] = useGlobalState();
const [{ user, as }] = useGlobalState();
const save = () => {
let settings = pond.MineSettings.create();
props.devices.forEach(device => {
if (device.settings) settings.devices.push(device.settings?.deviceId);
});
mineAPI.addMine(settings).then((resp: any) => {
mineAPI.addMine(settings, as).then((resp: any) => {
console.log(resp);
});
};

View file

@ -14,7 +14,7 @@ import CursorIcon from "assets/editor/cursor.png";
import DeleteIcon from "assets/editor/delete.png";
import { ImgIcon } from "common/ImgIcon";
import { pond } from "protobuf-ts/pond";
import { useMineAPI, useSnackbar } from "providers";
import { useGlobalState, useMineAPI, useSnackbar } from "providers";
import { Save, CloudDownload } from "@mui/icons-material";
import { Placeable } from "./drawable/Placeable";
import { Component } from "models";
@ -107,6 +107,7 @@ export default function EditorHeader(props: Props) {
const snackbar = useSnackbar();
const theme = useTheme();
const [loadDialog, setLoadDialog] = useState(false);
const [{as}] = useGlobalState();
const save = () => {
let settings = pond.MineSettings.create();
@ -141,7 +142,7 @@ export default function EditorHeader(props: Props) {
});
} else {
mineAPI
.addMine(settings)
.addMine(settings, as)
.then(resp => {
if (resp.status === 200) {
snackbar.success("New mine successfully saved!");

View file

@ -13,7 +13,7 @@ import {
Typography
} from "@mui/material";
import { pond } from "protobuf-ts/pond";
import { useMineAPI, useSnackbar } from "providers";
import { useGlobalState, useMineAPI, useSnackbar } from "providers";
import React, { useEffect, useState } from "react";
import { or } from "utils";
import { loadPlaceable, Placeable } from "./drawable/Placeable";
@ -80,11 +80,12 @@ export default function LoadMine(props: Props) {
const [offset, setOffset] = useState(0);
const classes = useStyles();
const isMobile = useMobile();
const [{as}] = useGlobalState();
const load = (key: string) => {
setLoading(true);
mineAPI
.getMine(key)
.getMine(key, as)
.then(resp => {
let newBlocks: Placeable[] = [];
if (resp.data.mine?.settings?.placeables)
@ -117,13 +118,13 @@ export default function LoadMine(props: Props) {
useEffect(() => {
if (open) {
setLoading(true);
mineAPI.listMinesSimple(limit, offset).then(resp => {
mineAPI.listMinesSimple(limit, offset, undefined, undefined, undefined, false, as).then(resp => {
setMines(resp.data.mines);
setLoading(false);
setTotal(resp.data.total);
});
}
}, [mineAPI, open, limit, offset]);
}, [mineAPI, open, limit, offset, as]);
const back = () => {
if (offset - limit < 0) {

View file

@ -84,7 +84,7 @@ export default function ComponentCards(props: Props) {
const [firstLoad, setFirstLoad] = useState(true);
const themeType = useThemeType();
const classes = useStyles();
const [{ user }] = useGlobalState();
const [{ user, as }] = useGlobalState();
const theme = useTheme();
const navigate = useNavigate()
@ -96,7 +96,7 @@ export default function ComponentCards(props: Props) {
types.forEach((type, index) => {
if (type === "mine") mine = keys[index];
});
mineAPI.addComponent(mine, device, component.key(), [pond.Permission.PERMISSION_INVALID]);
mineAPI.addComponent(mine, device, component.key(), [pond.Permission.PERMISSION_INVALID], as);
};
const addComponent = (device: string, component: Component) => {
@ -110,7 +110,7 @@ export default function ComponentCards(props: Props) {
pond.Permission.PERMISSION_SHARE,
pond.Permission.PERMISSION_WRITE,
pond.Permission.PERMISSION_USERS
])
], as)
.then(() => {
let prefs = getPreferences(component);
mineComponentPreferences.set(component.key(), prefs);

View file

@ -20,6 +20,7 @@ import { useDeviceAPI, useMineAPI } from "hooks";
import LeftIcon from "@mui/icons-material/KeyboardArrowLeft";
import RightIcon from "@mui/icons-material/KeyboardArrowRight";
import { makeStyles } from "@mui/styles";
import { useGlobalState } from "providers";
const useStyles = makeStyles((theme: Theme) => {
return ({
@ -111,6 +112,7 @@ export default function DeviceDrawer(props: Props) {
const deviceAPI = useDeviceAPI();
const mineAPI = useMineAPI();
const [tab, setTab] = React.useState(0);
const [{as}] = useGlobalState();
useEffect(() => {
let ids: number[] = [];
@ -153,7 +155,7 @@ export default function DeviceDrawer(props: Props) {
const index = selectedIDs.indexOf(id);
if (index > -1) {
if (device.settings && mine.name !== "") {
mineAPI.addDevice(mine.key, device.settings.deviceId.toString(), []).then(resp => {
mineAPI.addDevice(mine.key, device.settings.deviceId.toString(), [], as).then(resp => {
selectedIDs.splice(index, 1);
let d = selectedDevices;
let deviceIndex = 0;
@ -175,7 +177,7 @@ export default function DeviceDrawer(props: Props) {
pond.Permission.PERMISSION_SHARE,
pond.Permission.PERMISSION_WRITE,
pond.Permission.PERMISSION_USERS
])
], as)
.then(resp => {
selectedIDs.push(id);
let d = selectedDevices;