updated all uses of as in the api files to use the global state as well as a passed in value, will give priority to the passed in value and fall back to the state if it is undefined.
This commit is contained in:
parent
b404c45a4f
commit
59f7f7f4e1
25 changed files with 673 additions and 535 deletions
|
|
@ -7,15 +7,15 @@ import { createContext, PropsWithChildren, useContext } from "react";
|
|||
import { pondURL } from "./pond";
|
||||
|
||||
export interface IMineAPIContext {
|
||||
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>;
|
||||
addMine: (mine: pond.MineSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddMineResponse>>;
|
||||
getMine: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetMineResponse>>;
|
||||
addDevice: (key: string, deviceID: string, permissions: pond.Permission[], otherTeam?: string) => Promise<any>;
|
||||
addComponent: (
|
||||
key: string,
|
||||
deviceID: string,
|
||||
componentKey: string,
|
||||
permissions: pond.Permission[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<any>;
|
||||
listMines: (
|
||||
limit: number,
|
||||
|
|
@ -24,7 +24,7 @@ export interface IMineAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListMinesResponse>>;
|
||||
listMinesSimple: (
|
||||
limit: number,
|
||||
|
|
@ -33,9 +33,9 @@ export interface IMineAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListMinesSimpleResponse>>;
|
||||
removeMine: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveMineResponse>>;
|
||||
removeMine: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveMineResponse>>;
|
||||
updateMine: (
|
||||
mine: pond.MineSettings,
|
||||
componentPreferences: Map<string, pond.MineComponentPreferences>
|
||||
|
|
@ -49,14 +49,16 @@ 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, as?: string) => {
|
||||
return post<pond.AddMineResponse>(pondURL("/mines" + (as ? "?as=" + as : "")), mine);
|
||||
const addMine = (mine: pond.MineSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return post<pond.AddMineResponse>(pondURL("/mines" + (view ? "?as=" + view : "")), mine);
|
||||
};
|
||||
|
||||
const getMine = (key: string, as?: string) => {
|
||||
return get<pond.GetMineResponse>(pondURL("/mines/" + key + (as ? "?as=" + as : "")));
|
||||
const getMine = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.GetMineResponse>(pondURL("/mines/" + key + (view ? "?as=" + view : "")));
|
||||
};
|
||||
|
||||
const listMines = (
|
||||
|
|
@ -68,8 +70,9 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
asRoot?: boolean,
|
||||
keys?: string,
|
||||
types?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL(
|
||||
"/mines" +
|
||||
"?limit=" +
|
||||
|
|
@ -80,7 +83,7 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
("&by=" + (orderBy ? orderBy : "deviceId")) +
|
||||
(search ? "&search=" + search : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(keys ? "&keys=" + keys : "") +
|
||||
(types ? "&types=" + types : "")
|
||||
);
|
||||
|
|
@ -94,8 +97,9 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL(
|
||||
"/minesSimple" +
|
||||
"?limit=" +
|
||||
|
|
@ -106,13 +110,14 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
("&by=" + (orderBy ? orderBy : "deviceId")) +
|
||||
(search ? "&search=" + search : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
);
|
||||
return get<pond.ListMinesSimpleResponse>(url);
|
||||
};
|
||||
|
||||
const removeMine = (key: string, as?: string) => {
|
||||
return del<pond.RemoveMineResponse>(pondURL("/mines/" + key + (as ? "?as=" + as : "")));
|
||||
const removeMine = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return del<pond.RemoveMineResponse>(pondURL("/mines/" + key + (view ? "?as=" + view : "")));
|
||||
};
|
||||
|
||||
const updateMine = (
|
||||
|
|
@ -132,9 +137,10 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
return put<pond.AddMineResponse>(pondURL("/mines"), request);
|
||||
};
|
||||
|
||||
const addDevice = (key: string, deviceID: string, permissions: pond.Permission[], as?: string) => {
|
||||
if (as)
|
||||
return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID + `?as=${as}`), {
|
||||
const addDevice = (key: string, deviceID: string, permissions: pond.Permission[], otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID + `?as=${view}`), {
|
||||
permissions: permissions.map(permission => permissionToString(permission))
|
||||
});
|
||||
return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID), {
|
||||
|
|
@ -147,11 +153,12 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
deviceID: string,
|
||||
componentKey: string,
|
||||
permissions: pond.Permission[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
if (as)
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return post(
|
||||
pondURL(`/mines/` + key + `/addComponent/` + deviceID + "/" + componentKey + `?as=${as}`),
|
||||
pondURL(`/mines/` + key + `/addComponent/` + deviceID + "/" + componentKey + `?as=${view}`),
|
||||
{
|
||||
permissions: permissions.map(permission => permissionToString(permission))
|
||||
}
|
||||
|
|
@ -169,8 +176,8 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
addDevice,
|
||||
addComponent,
|
||||
listMines,
|
||||
listMinesSimple,//
|
||||
removeMine,//
|
||||
listMinesSimple,
|
||||
removeMine,
|
||||
updateMine
|
||||
}}>
|
||||
{children}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue