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

@ -7,14 +7,15 @@ import { createContext, PropsWithChildren, useContext } from "react";
import { pondURL } from "./pond";
export interface IMineAPIContext {
addMine: (mine: pond.MineSettings) => Promise<AxiosResponse<pond.AddMineResponse>>;
getMine: (key: string) => Promise<AxiosResponse<pond.GetMineResponse>>;
addDevice: (key: string, deviceID: string, permissions: pond.Permission[]) => Promise<any>;
addMine: (mine: pond.MineSettings, as?: string) => Promise<AxiosResponse<pond.AddMineResponse>>;
getMine: (key: string, as?: string) => Promise<AxiosResponse<pond.GetMineResponse>>;
addDevice: (key: string, deviceID: string, permissions: pond.Permission[], as?: string) => Promise<any>;
addComponent: (
key: string,
deviceID: string,
componentKey: string,
permissions: pond.Permission[]
permissions: pond.Permission[],
as?: string
) => Promise<any>;
listMines: (
limit: number,
@ -22,7 +23,8 @@ export interface IMineAPIContext {
order?: "asc" | "desc",
orderBy?: string,
search?: string,
asRoot?: boolean
asRoot?: boolean,
as?: string
) => Promise<AxiosResponse<pond.ListMinesResponse>>;
listMinesSimple: (
limit: number,
@ -30,9 +32,10 @@ export interface IMineAPIContext {
order?: "asc" | "desc",
orderBy?: string,
search?: string,
asRoot?: boolean
asRoot?: boolean,
as?: string
) => Promise<AxiosResponse<pond.ListMinesSimpleResponse>>;
removeMine: (key: string) => Promise<AxiosResponse<pond.RemoveMineResponse>>;
removeMine: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveMineResponse>>;
updateMine: (
mine: pond.MineSettings,
componentPreferences: Map<string, pond.MineComponentPreferences>
@ -46,13 +49,13 @@ interface Props {}
export default function MineProvider(props: PropsWithChildren<Props>) {
const { children } = props;
const { get, del, post, put } = useHTTP();
const [{ as }] = useGlobalState();
//const [{ as }] = useGlobalState();
const addMine = (mine: pond.MineSettings) => {
const addMine = (mine: pond.MineSettings, as?: string) => {
return post<pond.AddMineResponse>(pondURL("/mines" + (as ? "?as=" + as : "")), mine);
};
const getMine = (key: string) => {
const getMine = (key: string, as?: string) => {
return get<pond.GetMineResponse>(pondURL("/mines/" + key + (as ? "?as=" + as : "")));
};
@ -64,7 +67,8 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
search?: string,
asRoot?: boolean,
keys?: string,
types?: string
types?: string,
as?: string
) => {
const url = pondURL(
"/mines" +
@ -89,7 +93,8 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc",
orderBy?: string,
search?: string,
asRoot?: boolean
asRoot?: boolean,
as?: string
) => {
const url = pondURL(
"/minesSimple" +
@ -106,7 +111,7 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
return get<pond.ListMinesSimpleResponse>(url);
};
const removeMine = (key: string) => {
const removeMine = (key: string, as?: string) => {
return del<pond.RemoveMineResponse>(pondURL("/mines/" + key + (as ? "?as=" + as : "")));
};
@ -127,7 +132,7 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
return put<pond.AddMineResponse>(pondURL("/mines"), request);
};
const addDevice = (key: string, deviceID: string, permissions: pond.Permission[]) => {
const addDevice = (key: string, deviceID: string, permissions: pond.Permission[], as?: string) => {
if (as)
return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID + `?as=${as}`), {
permissions: permissions.map(permission => permissionToString(permission))
@ -141,7 +146,8 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
key: string,
deviceID: string,
componentKey: string,
permissions: pond.Permission[]
permissions: pond.Permission[],
as?: string
) => {
if (as)
return post(
@ -163,8 +169,8 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
addDevice,
addComponent,
listMines,
listMinesSimple,
removeMine,
listMinesSimple,//
removeMine,//
updateMine
}}>
{children}