refactor: useControl.start принимает объект параметров вместо 14 позиционных
This commit is contained in:
parent
f6d0653e68
commit
3dc116534d
6 changed files with 118 additions and 33 deletions
36
frontend/src/features/instructor/start.d.mts
Normal file
36
frontend/src/features/instructor/start.d.mts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import type { LessonCriteria, SessionMode } from "@/shared/types/generated";
|
||||
|
||||
export interface ScenarioStartOptions {
|
||||
scenarioId: string;
|
||||
mode: SessionMode;
|
||||
trainee: string;
|
||||
exercise?: "dds" | "call" | "card";
|
||||
groupId?: string;
|
||||
traineeId?: string;
|
||||
ddsService?: string;
|
||||
scenarioIds?: string[];
|
||||
randomScenarioIds?: string[];
|
||||
ddsArrivalIntervalSeconds?: number;
|
||||
ddsMaxWaiting?: number;
|
||||
handoffToDds?: boolean;
|
||||
criteria?: LessonCriteria;
|
||||
}
|
||||
|
||||
export interface ScenarioStartMessage {
|
||||
type: "scenario.start";
|
||||
scenario_id: string;
|
||||
mode: SessionMode;
|
||||
trainee: string;
|
||||
group_id: string | null;
|
||||
trainee_id: string | null;
|
||||
dds_service: string | null;
|
||||
exercise: "dds" | "call" | "card";
|
||||
handoff_to_dds: boolean;
|
||||
scenario_ids: string[] | undefined;
|
||||
random_scenario_ids: string[] | undefined;
|
||||
dds_arrival_interval_seconds: number;
|
||||
dds_max_waiting: number;
|
||||
criteria: LessonCriteria | undefined;
|
||||
}
|
||||
|
||||
export function scenarioStartMessage(options: ScenarioStartOptions): ScenarioStartMessage;
|
||||
26
frontend/src/features/instructor/start.mjs
Normal file
26
frontend/src/features/instructor/start.mjs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Сборка `scenario.start` из именованных параметров консоли преподавателя.
|
||||
// Отдельный .mjs, чтобы состав сообщения проверялся node-скриптом без сборки.
|
||||
|
||||
/** @param {import("./start.d.mts").ScenarioStartOptions} options */
|
||||
export function scenarioStartMessage({
|
||||
scenarioId, mode, trainee, exercise = "dds", groupId, traineeId, ddsService,
|
||||
scenarioIds, randomScenarioIds, ddsArrivalIntervalSeconds = 60, ddsMaxWaiting = 3,
|
||||
handoffToDds = false, criteria,
|
||||
}) {
|
||||
return {
|
||||
type: "scenario.start",
|
||||
scenario_id: scenarioId,
|
||||
mode,
|
||||
trainee,
|
||||
group_id: groupId || null,
|
||||
trainee_id: traineeId || null,
|
||||
dds_service: ddsService || null,
|
||||
exercise,
|
||||
handoff_to_dds: handoffToDds,
|
||||
scenario_ids: scenarioIds?.length ? scenarioIds : undefined,
|
||||
random_scenario_ids: randomScenarioIds?.length ? randomScenarioIds : undefined,
|
||||
dds_arrival_interval_seconds: ddsArrivalIntervalSeconds,
|
||||
dds_max_waiting: ddsMaxWaiting,
|
||||
criteria,
|
||||
};
|
||||
}
|
||||
|
|
@ -8,7 +8,8 @@
|
|||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
import { controlChannel, type ChannelStatus } from "@/shared/api/ws";
|
||||
import type { LessonCriteria, SessionMode } from "@/shared/types/generated";
|
||||
|
||||
import { scenarioStartMessage, type ScenarioStartOptions } from "./start.mjs";
|
||||
|
||||
export function useControl(sessionId: string | null) {
|
||||
const [status, setStatus] = useState<ChannelStatus>("closed");
|
||||
|
|
@ -37,30 +38,11 @@ export function useControl(sessionId: string | null) {
|
|||
};
|
||||
}, [sessionId]);
|
||||
|
||||
const start = useCallback(
|
||||
(targetSessionId: string, scenarioId: string, mode: SessionMode, trainee: string, exercise: "dds" | "call" | "card" = "dds", group?: string, traineeId?: string, ddsService?: string, scenarioIds?: string[], ddsArrivalIntervalSeconds = 60, ddsMaxWaiting = 3, handoffToDds = false, criteria?: LessonCriteria, randomScenarioIds?: string[]) => {
|
||||
const message = {
|
||||
type: "scenario.start",
|
||||
scenario_id: scenarioId,
|
||||
mode,
|
||||
trainee,
|
||||
group_id: group || null,
|
||||
trainee_id: traineeId || null,
|
||||
dds_service: ddsService || null,
|
||||
exercise,
|
||||
handoff_to_dds: handoffToDds,
|
||||
scenario_ids: scenarioIds?.length ? scenarioIds : undefined,
|
||||
random_scenario_ids: randomScenarioIds?.length ? randomScenarioIds : undefined,
|
||||
dds_arrival_interval_seconds: ddsArrivalIntervalSeconds,
|
||||
dds_max_waiting: ddsMaxWaiting,
|
||||
criteria,
|
||||
} as const;
|
||||
const current = channel.current;
|
||||
if (!current || current.sessionId !== targetSessionId) return false;
|
||||
return current.socket.send(message);
|
||||
},
|
||||
[],
|
||||
);
|
||||
const start = useCallback((targetSessionId: string, options: ScenarioStartOptions) => {
|
||||
const current = channel.current;
|
||||
if (!current || current.sessionId !== targetSessionId) return false;
|
||||
return current.socket.send(scenarioStartMessage(options));
|
||||
}, []);
|
||||
|
||||
const note = useCallback(
|
||||
(transcriptRef: string, text: string) =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue