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:
csawatzky 2025-04-28 10:47:59 -06:00
parent b404c45a4f
commit 59f7f7f4e1
25 changed files with 673 additions and 535 deletions

View file

@ -5,6 +5,7 @@ import { pond } from "protobuf-ts/pond";
import { createContext, PropsWithChildren, useContext } from "react";
import { or } from "utils/types";
import { pondURL } from "./pond";
import { useGlobalState } from "providers";
export interface ITeamAPIContext {
addTeam: (team: pond.TeamSettings) => Promise<AxiosResponse<pond.AddTeamResponse>>;
@ -27,11 +28,11 @@ export interface ITeamAPIContext {
orderBy?: string,
search?: string,
asRoot?: boolean,
as?: string,
otherTeam?: string,
prefixSearch?: string,
) => Promise<AxiosResponse<pond.ListTeamsResponse>>;
listAllTeams: () => Promise<AxiosResponse<pond.ListTeamsResponse>>;
listObjectTeams: (scope: Scope, as?: string) => Promise<any>;
listObjectTeams: (scope: Scope, otherTeam?: string) => Promise<any>;
removeTeam: (key: string) => Promise<AxiosResponse<pond.RemoveTeamResponse>>;
}
@ -42,7 +43,7 @@ interface Props {}
export default function TeamProvider(props: PropsWithChildren<Props>) {
const { children } = props;
const { get, del, post, put } = useHTTP();
//const [{ team }] = useGlobalState();
const [{ as }] = useGlobalState();
const addTeam = (team: pond.TeamSettings) => {
return new Promise<AxiosResponse<pond.AddTeamResponse>>((resolve, reject) => {
@ -114,10 +115,11 @@ export default function TeamProvider(props: PropsWithChildren<Props>) {
orderBy?: string,
search?: string,
asRoot?: boolean,
as?: string,
otherTeam?: string,
prefixSearch?: string,
) => {
//let asText = team ? "&as=" + team.key() : "";
const view = otherTeam ? otherTeam : as
let url = pondURL(
"/teams" +
"?limit=" +
@ -129,7 +131,7 @@ export default function TeamProvider(props: PropsWithChildren<Props>) {
(search ? "&search=" + search : "") +
(prefixSearch ? "&prefixSearch=" + prefixSearch : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
(as ? "&as=" + as : "")
(view ? "&as=" + view : "")
)
return new Promise<AxiosResponse<pond.ListTeamsResponse>>((resolve, reject)=>{
get<pond.ListTeamsResponse>(url).then(resp => {
@ -152,9 +154,10 @@ export default function TeamProvider(props: PropsWithChildren<Props>) {
})
};
const listObjectTeams = (scope: Scope, as?: string) => {
const listObjectTeams = (scope: Scope, otherTeam?: string) => {
let url = "/" + scope.kind + "s/" + scope.key + "/teams"
if (as) url = `/${scope.kind}s/${scope.key}/teams?as=${as}`
const view = otherTeam ? otherTeam : as
if (view) url = `/${scope.kind}s/${scope.key}/teams?as=${view}`
return new Promise<AxiosResponse>((resolve, reject) => {
get(pondURL(url)).then(resp => {
return resolve(resp)