Files
Aislo/M02_MasterTemplete/M02_MasterTemplete_Library_SameAsk.ts
T
eomsangdonandClaude Opus 5.5 2f3cc52118 refactor(861-2): 영어 글 걷기 ⓓ — M02 글 표 짝 → 한국어 글 하나
- M02 글 표 13 개(호표 · 노무 · 서고 · 단가산출 좌측 · 주 단추) 짝 327 개 → 문자열 하나 · 표 타입 → `string`
- 읽는 곳 `TEXT[k][currentLanguageIndex] ?? TEXT[k][0]` → `TEXT[k]` · 안 쓰게 된 import · 「[한국어, 영어]」 머리 주석 걷음
- 시험: 글 소스를 짝 꼴로 뽑거나 대조하던 4 개(test_860_3 · 721 · 804_7 · m02_labor_promote_flag)를 새 꼴로
- 표 값 대조 327 같음 · typecheck 0 · 관련 시험 132 통과

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 08:57:04 +09:00

65 lines
2.7 KiB
TypeScript

/* =============================================================================
* M02_MasterTemplete_Library_SameAsk.ts
* 서고 같은 내용 물음(733-3 · 서버 꼴 = 733-2) — 사람 길(단가산출로 저장 · 공유 승인 · B09 내 자료집 …)이
* 같은 층 같은 내용이면 서버 409 `detail = {같은것: [{키, 이름, 층, 주인}], 까닭}` →
* 물음 「같은 것 있음 — 그것을 씀 / 그래도 새로」 → 같은 부름을 몸 덧칸 `{씀: 키}` · `{새로: true}` 로 다시 ·
* 취소 = null. 물음 꼴 = 부품 `askChoice`.
* ========================================================================== */
import { askChoice } from "@ui/ui_template_modal";
import { StaleError } from "./M02_MasterTemplete_Api_Fetch";
const TEXT = {
Title: "같은 내용 있음",
Message: "이 층에 내용이 같은 문서가 이미 있음 — {list}",
More: " 외 {n}",
Use: "그것을 씀",
New: "그래도 새로",
} as const;
const tx = (key: keyof typeof TEXT): string => TEXT[key];
export interface SameHit {
키: string;
이름: string;
층: string;
주인: string | null;
}
/** 다시 보낼 몸 덧칸 — 그것을 씀 = 그 키 · 그래도 새로 = 새 문서 */
export interface SameExtra {
씀?: string;
새로?: boolean;
}
/** 서버 409 몸에서 같은 내용 문서 목록 — 없으면 null(다른 409 = 판 · 같은 이름 …) */
export const sameHits = (detail: unknown): SameHit[] | null => {
const list = (detail as { 같은것?: unknown } | null)?.같은것;
return Array.isArray(list) && list.length ? (list as SameHit[]) : null;
};
/** 물음 — 그것을 씀(첫 문서 = 먼저 만든 것) · 그래도 새로 · 취소 = null */
export async function askSame(hits: SameHit[]): Promise<SameExtra | null> {
const shown = hits.slice(0, 3).map((h) => `「${h.키} ${h.이름}」`);
const more = hits.length > 3 ? tx("More").replace("{n}", String(hits.length - 3)) : "";
const got = await askChoice({
title: tx("Title"),
message: tx("Message").replace("{list}", shown.join(" · ") + more),
choices: [
{ label: tx("New"), value: "new" },
{ label: tx("Use"), value: "use" },
],
});
return got === "use" ? { 씀: hits[0].키 } : got === "new" ? { 새로: true } : null;
}
/** `job(덧칸)` — 409 같은것이면 물은 뒤 덧칸을 넣어 한 번 더 · 취소 = null · 그 밖 실패 = 그대로 던짐 */
export async function withSameAsk<T>(job: (extra: SameExtra) => Promise<T>): Promise<T | null> {
try {
return await job({});
} catch (error) {
const hits = error instanceof StaleError ? sameHits(error.detail) : null;
if (!hits) throw error;
const extra = await askSame(hits);
return extra ? job(extra) : null;
}
}