Start cleaning up the mess of useServer; make startup page update in real time
This commit is contained in:
parent
179885b546
commit
c4418640eb
16 changed files with 175 additions and 61 deletions
18
resources/scripts/api/swr/getServerStartup.ts
Normal file
18
resources/scripts/api/swr/getServerStartup.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import useSWR from 'swr';
|
||||
import http, { FractalResponseList } from '@/api/http';
|
||||
import { rawDataToServerEggVariable } from '@/api/transformers';
|
||||
import { ServerEggVariable } from '@/api/server/types';
|
||||
|
||||
interface Response {
|
||||
invocation: string;
|
||||
variables: ServerEggVariable[];
|
||||
}
|
||||
|
||||
export default (uuid: string, initialData?: Response) => useSWR([ uuid, '/startup' ], async (): Promise<Response> => {
|
||||
console.log('firing getServerStartup');
|
||||
const { data } = await http.get(`/api/client/servers/${uuid}/startup`);
|
||||
|
||||
const variables = ((data as FractalResponseList).data || []).map(rawDataToServerEggVariable);
|
||||
|
||||
return { invocation: data.meta.startup_command, variables };
|
||||
}, { initialData, errorRetryCount: 3 });
|
Reference in a new issue