feat: add demo mode
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { DSP, DSPTypes, AppPage } from '../types/types';
|
||||
import { SetDsps, NotifyFn } from './dspShared';
|
||||
import { forDSP408, create as createDSP408 } from './dsp408';
|
||||
import { DSP408Api } from './dsp408';
|
||||
// import { forDSP204 } from './dsp204';
|
||||
|
||||
export type DSPInstance = { dsp: Extract<DSP, { type: 'DSP408' }>; api: DSP408Api };
|
||||
// | { dsp: Extract<DSP, { type: 'DSP204' }>; api: DSP408Api };
|
||||
|
||||
export function createDSPInstance(dsp: DSP, setDsps: SetDsps, notify: NotifyFn): DSPInstance {
|
||||
switch (dsp.type) {
|
||||
case 'DSP408':
|
||||
return { dsp, api: forDSP408(dsp, setDsps, notify) };
|
||||
case 'DSP204':
|
||||
throw new Error('DSP204 not yet implemented');
|
||||
}
|
||||
}
|
||||
|
||||
export async function addDSP(
|
||||
setDsps: SetDsps,
|
||||
setSelected: React.Dispatch<React.SetStateAction<number | null>>,
|
||||
setPage: React.Dispatch<React.SetStateAction<AppPage>>,
|
||||
notify: NotifyFn,
|
||||
params: {
|
||||
name: string;
|
||||
type: DSPTypes;
|
||||
ip: string;
|
||||
port: number;
|
||||
deviceId: number;
|
||||
demo: boolean;
|
||||
}
|
||||
) {
|
||||
try {
|
||||
const newDsp: DSP =
|
||||
params.type === 'DSP408'
|
||||
? await createDSP408(params)
|
||||
: await Promise.reject('DSP204 not implemented');
|
||||
|
||||
setDsps((prev) => [...prev, newDsp]);
|
||||
setSelected(newDsp.id);
|
||||
setPage('view-dsp');
|
||||
} catch (err) {
|
||||
notify(`Failed to add DSP: ${String(err)}`, 'error', params.name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user