refactor: remove files from previous demo

main
Josue 4 years ago committed by Tsu-ba-me
parent 1ed509e497
commit 17c52d562b
  1. 22
      striker-ui/lib/anvil/getAllAnvil.ts
  2. 23
      striker-ui/lib/anvil/getOneAnvil.ts
  3. 22
      striker-ui/lib/anvil/handleAPIFakeGetAllAnvil.ts
  4. 23
      striker-ui/lib/anvil/handleAPIFakeGetOneAnvil.ts
  5. 23
      striker-ui/lib/anvil/handleAPIGetAllAnvil.ts
  6. 31
      striker-ui/lib/anvil/handleAPIGetOneAnvil.ts
  7. 23
      striker-ui/lib/anvil/useOneAnvil.ts

@ -1,22 +0,0 @@
import fetchJSON from '../fetchers/fetchJSON';
async function getAllAnvil(): Promise<GetAllAnvilResponse> {
const response: GetAllAnvilResponse = {
anvilList: {
anvils: [],
},
error: null,
};
try {
response.anvilList = await fetchJSON(
`${process.env.DATA_ENDPOINT_BASE_URL}/get_anvils`,
);
} catch (fetchError) {
response.error = fetchError;
}
return response;
}
export default getAllAnvil;

@ -1,23 +0,0 @@
import fetchJSON from '../fetchers/fetchJSON';
async function getOneAnvil(anvilUUID: string): Promise<GetOneAnvilResponse> {
const response: GetOneAnvilResponse = {
anvilStatus: {
nodes: [],
timestamp: 0,
},
error: null,
};
try {
response.anvilStatus = await fetchJSON(
`${process.env.DATA_ENDPOINT_BASE_URL}/get_anvil_status?anvil_uuid=${anvilUUID}`,
);
} catch (fetchError) {
response.error = fetchError;
}
return response;
}
export default getOneAnvil;

@ -1,22 +0,0 @@
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
const handleAPIFakeGetAllAnvil: NextApiHandler<AnvilList> = (
request: NextApiRequest,
response: NextApiResponse<AnvilList>,
): void => {
response.send({
anvils: [
{
uuid: '62ed925e-dddc-4541-acae-525fc99a9945',
},
{
uuid: '1040f37a-9847-4025-af2e-973b0f136979',
},
{
uuid: '52057dd0-04a6-4097-8a38-deb036116190',
},
],
});
};
export default handleAPIFakeGetAllAnvil;

@ -1,23 +0,0 @@
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
const handleAPIFakeGetOneAnvil: NextApiHandler<AnvilStatus> = (
request: NextApiRequest,
response: NextApiResponse<AnvilStatus>,
): void => {
const generateNodeState: () => 0 | 1 = (): 0 | 1 =>
Math.random() > 0.5 ? 1 : 0;
response.send({
nodes: [
{
on: generateNodeState(),
},
{
on: generateNodeState(),
},
],
timestamp: Math.round(Date.now() / 1000),
});
};
export default handleAPIFakeGetOneAnvil;

@ -1,23 +0,0 @@
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
import getAllAnvil from './getAllAnvil';
import handleAPIFakeGetAllAnvil from './handleAPIFakeGetAllAnvil';
const handleAPIGetAllAnvil: NextApiHandler<AnvilList> = async (
request: NextApiRequest,
response: NextApiResponse<AnvilList>,
): Promise<void> => {
const { anvilList, error }: GetAllAnvilResponse = await getAllAnvil();
if (error) {
response.status(503);
} else {
response.status(200);
}
response.send(anvilList);
};
export default process.env.IS_USE_FAKE_DATA
? handleAPIFakeGetAllAnvil
: handleAPIGetAllAnvil;

@ -1,31 +0,0 @@
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
import getOneAnvil from './getOneAnvil';
import handleAPIFakeGetOneAnvil from './handleAPIFakeGetOneAnvil';
const handleAPIGetOneAnvil: NextApiHandler<AnvilStatus> = async (
request: NextApiRequest,
response: NextApiResponse<AnvilStatus>,
): Promise<void> => {
const {
query: { uuid },
}: NextApiRequest = request;
const anvilUUID: string = uuid instanceof Array ? uuid[0] : uuid;
const { anvilStatus, error }: GetOneAnvilResponse = await getOneAnvil(
anvilUUID,
);
if (error) {
response.status(503);
} else {
response.status(200);
}
response.send(anvilStatus);
};
export default process.env.IS_USE_FAKE_DATA
? handleAPIFakeGetOneAnvil
: handleAPIGetOneAnvil;

@ -1,23 +0,0 @@
import useSWR from 'swr';
import fetchJSON from '../fetchers/fetchJSON';
const useOneAnvil = (
anvilUUID: string,
refreshInterval = 2000,
): GetOneAnvilResponse => {
const {
data = { nodes: [], timestamp: 0 },
error = null,
} = useSWR<AnvilStatus>(`/api/anvils/${anvilUUID}`, fetchJSON, {
refreshInterval,
});
return {
anvilStatus: data,
error,
isLoading: !error && !data,
};
};
export default useOneAnvil;
Loading…
Cancel
Save