all the latest socket work

This commit is contained in:
ari committed 2022-06-01 21:17:16 -04:00
1 parent a530e5e6e0
commit bc773154c6
18 files changed
+117 -61

No files matched your search

+6 -3
View File
@@ -10,13 +10,16 @@ export const makeRemoteAPI = (baseURL: string): API => ({
data = {}
}) {
try {
const reply = await fetch(baseURL + path, {
const payload: RequestInit = {
method,
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data),
});
};
if (method !== 'GET') {
payload["body"] = JSON.stringify(data);
}
const reply = await fetch(baseURL + path, payload);
let response: APIResponse<any>;
if (reply.status === 200) {
response = {
+10 -5
View File
@@ -5,13 +5,18 @@ import { useAPIService } from './core';
import { useMockAPI } from "./mock";
const locationPrefixWeb = window.location.pathname.match(/(.+)\/web/i);
const baseURL = process.env.NODE_ENV === 'development' ?
"http://localhost:8000" :
(!locationPrefixWeb ? '' : locationPrefixWeb[1]);
export const remoteDetailsAPI = makeRemoteAPI(
baseURL + "/details"
);
export const remoteAutoAPI = makeRemoteAPI(
baseURL + "/automations"
);
export const useConnectedApiService = () => useAPIService(
makeAutomationAPI(makeRemoteAPI(
process.env.NODE_ENV === 'development' ?
"http://localhost:8000/automations" :
(!locationPrefixWeb ? '' : locationPrefixWeb[1]) + "/automations"
))
makeAutomationAPI(remoteAutoAPI)
);
export const useMockApiService = (initialAutos: AutomationData[]) => useAPIService(
makeAutomationAPI(useMockAPI(initialAutos))
+1 -1
View File
@@ -7,7 +7,7 @@ export interface ListParams {
}
export type APIRequest<D> = {
path: string;
method?: "POST" | "DELETE",
method?: "POST" | "DELETE" | "GET",
data?: D;
};