Files
kandev/apps/web/hooks/domains/session/use-session-launch.ts
T
João Salavisa 5257dfbaab fix(web): close the i18n coverage gaps in the non-JSX scanner and locale catalogs (#2727)
Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 23:03:29 +00:00

42 lines
1.3 KiB
TypeScript

import { useCallback, useState } from "react";
import {
launchSession,
type LaunchSessionRequest,
type LaunchSessionResponse,
} from "@/lib/services/session-launch-service";
import { t } from "@/lib/i18n";
export function useSessionLaunch(options?: {
onSuccess?: (resp: LaunchSessionResponse) => void;
onError?: (err: Error) => void;
}): {
launch: (request: LaunchSessionRequest) => Promise<LaunchSessionResponse | null>;
isLoading: boolean;
error: string | null;
} {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const launch = useCallback(
async (request: LaunchSessionRequest): Promise<LaunchSessionResponse | null> => {
setIsLoading(true);
setError(null);
try {
const resp = await launchSession(request);
options?.onSuccess?.(resp);
return resp;
} catch (err) {
const message = err instanceof Error ? err.message : t("common:unknownError");
setError(message);
options?.onError?.(err instanceof Error ? err : new Error(message));
return null;
} finally {
setIsLoading(false);
}
},
[options?.onSuccess, options?.onError], // eslint-disable-line react-hooks/exhaustive-deps
);
return { launch, isLoading, error };
}