fix(interview): retain answer drafts during same-job refresh
This commit is contained in:
@@ -25,7 +25,7 @@ import ViewStateNotice from "./ViewStateNotice";
|
||||
// become prep items after an explicit accept action.
|
||||
// docs/architecture/overview.md.
|
||||
|
||||
function Shell({ title, subtitle, loading, error, children, onRetry, keepContentOnError = false }: {
|
||||
function Shell({ title, subtitle, loading, error, children, onRetry, keepContentOnError = false, keepContentOnLoading = false }: {
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
loading: boolean;
|
||||
@@ -33,11 +33,12 @@ function Shell({ title, subtitle, loading, error, children, onRetry, keepContent
|
||||
children: React.ReactNode;
|
||||
onRetry?: () => void | Promise<void>;
|
||||
keepContentOnError?: boolean;
|
||||
keepContentOnLoading?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<PageSection surface title={title} description={subtitle} level="h3">
|
||||
<ViewStateNotice title={title} loading={loading} error={error ? { kind: "error", message: error, retryable: Boolean(onRetry) } : null} onRetry={onRetry} compact />
|
||||
{!loading && (!error || keepContentOnError) && children}
|
||||
{(!loading || keepContentOnLoading) && (!error || keepContentOnError) && children}
|
||||
</PageSection>
|
||||
);
|
||||
}
|
||||
@@ -118,7 +119,9 @@ function InterviewPrepWorkspace({ jobId }: { jobId: number }) {
|
||||
subtitle={t("interviewPrepSubtitle")}
|
||||
loading={loading}
|
||||
error={error ? getApiErrorMessage(error.cause, t(error.fallback)) : null}
|
||||
keepContentOnError={error?.fallback === "interviewPrepAnswerSaveFailed" || error?.fallback === "interviewPrepUpdateFailed"}
|
||||
onRetry={error?.fallback === "interviewPrepLoadFailed" ? load : undefined}
|
||||
keepContentOnLoading={board !== null}
|
||||
keepContentOnError={board !== null}
|
||||
>
|
||||
<Stack spacing={2}>
|
||||
{board && !board.isInterviewStage && (
|
||||
@@ -355,11 +358,11 @@ function PrepRow({ jobId, item, busy, onChanged, onError }: {
|
||||
const content = draft ?? item.content ?? "";
|
||||
const dirty = draft !== null && draft !== (item.content ?? "");
|
||||
|
||||
const run = async (fn: () => Promise<unknown>) => {
|
||||
const run = async (fn: () => Promise<unknown>, savesAnswer = false) => {
|
||||
setSaving(true);
|
||||
try {
|
||||
await fn();
|
||||
setDraft(null);
|
||||
if (savesAnswer) setDraft(null);
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
onError({ cause: err, fallback: "interviewPrepAnswerSaveFailed" });
|
||||
@@ -404,7 +407,7 @@ function PrepRow({ jobId, item, busy, onChanged, onError }: {
|
||||
size="small"
|
||||
variant="contained"
|
||||
disabled={saving}
|
||||
onClick={() => run(() => interviewPrepApi.update(jobId, item.id, { content }))}
|
||||
onClick={() => run(() => interviewPrepApi.update(jobId, item.id, { content }), true)}
|
||||
>
|
||||
{t("interviewPrepSaveAnswer")}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user