Bug fix: Word Companion Create Scene buttons are still disabled after Phase 10J.

This commit is contained in:
Nick Beckley 2026-06-14 09:37:48 +01:00
parent f01232de49
commit 867d536f82

View File

@ -1520,23 +1520,24 @@
} }
if (detectedChapterAnchorId) { if (detectedChapterAnchorId) {
const anchoredChapterScene = await findSceneInBookStructure( const chapters = await getBookStructureChapters(book.bookId);
book.bookId, const anchoredChapter = chapters.find((chapter) => chapter.chapterId === detectedChapterAnchorId);
(chapter, scene) => chapter.chapterId === detectedChapterAnchorId const anchoredChapterScene = anchoredChapter
&& normalizeTitleForResolve(scene.title, "scene").toLocaleLowerCase() === requestSceneTitle.toLocaleLowerCase() ? (Array.isArray(anchoredChapter.scenes) ? anchoredChapter.scenes : [])
); .find((scene) => normalizeTitleForResolve(scene.title, "scene").toLocaleLowerCase() === requestSceneTitle.toLocaleLowerCase())
: null;
if (anchoredChapterScene) { if (anchoredChapterScene) {
setResolveDiagnostics({ setResolveDiagnostics({
result: "Matched", result: "Matched",
chapterId: anchoredChapterScene.chapter.chapterId, chapterId: anchoredChapter.chapterId,
sceneId: anchoredChapterScene.scene.sceneId sceneId: anchoredChapterScene.sceneId
}); });
await loadResolvedCompanionData(book.bookId, anchoredChapterScene.scene.sceneId, anchoredChapterScene.chapter.chapterId, "Anchor", "ChapterID Anchor"); await loadResolvedCompanionData(book.bookId, anchoredChapterScene.sceneId, anchoredChapter.chapterId, "Anchor", "ChapterID Anchor");
return true; return true;
} }
if (!detectedSceneAnchorId) { if (anchoredChapter && !detectedSceneAnchorId) {
currentResolutionAnchorType = "ChapterID Anchor"; currentResolutionAnchorType = "ChapterID Anchor";
setResolvedScene(null, detectedChapterAnchorId, "Chapter anchor"); setResolvedScene(null, detectedChapterAnchorId, "Chapter anchor");
setResolveDiagnostics({ setResolveDiagnostics({
@ -1544,6 +1545,16 @@
chapterId: detectedChapterAnchorId, chapterId: detectedChapterAnchorId,
sceneId: null sceneId: null
}); });
} else if (!detectedSceneAnchorId) {
storedAnchorInvalid = true;
currentResolutionAnchorType = "ChapterID Anchor";
setPlotDirectorSceneStatus("Not found in PlotDirector");
setDocumentMessage("Stored PlotDirector ID is invalid.");
setResolveDiagnostics({
result: "Error",
chapterId: detectedChapterAnchorId,
sceneId: null
});
} }
} }
@ -1555,11 +1566,13 @@
if (!resolveResponse?.matched || !resolveResponse.sceneId) { if (!resolveResponse?.matched || !resolveResponse.sceneId) {
const hadInvalidAnchor = storedAnchorInvalid; const hadInvalidAnchor = storedAnchorInvalid;
const matchedChapterId = Number.parseInt(resolveResponse?.chapterId || "", 10); const matchedChapterId = Number.parseInt(resolveResponse?.chapterId || "", 10);
const chapterMatched = !!resolveResponse?.chapterMatched || (Number.isInteger(matchedChapterId) && matchedChapterId > 0); const anchorChapterId = Number.isInteger(resolvedChapterId) && resolvedChapterId > 0 ? resolvedChapterId : null;
const unmatchedChapterId = Number.isInteger(matchedChapterId) && matchedChapterId > 0 ? matchedChapterId : anchorChapterId;
const chapterMatched = !!resolveResponse?.chapterMatched || !!unmatchedChapterId;
resetPlotDirectorScene("Not found in PlotDirector"); resetPlotDirectorScene("Not found in PlotDirector");
storedAnchorInvalid = hadInvalidAnchor; storedAnchorInvalid = hadInvalidAnchor;
if (chapterMatched) { if (chapterMatched) {
setResolvedScene(null, matchedChapterId, "Chapter title"); setResolvedScene(null, unmatchedChapterId, unmatchedChapterId === anchorChapterId ? "Chapter anchor" : "Chapter title");
setPlotDirectorSceneStatus("Scene not found in PlotDirector."); setPlotDirectorSceneStatus("Scene not found in PlotDirector.");
} }
setDocumentMessage(hadInvalidAnchor setDocumentMessage(hadInvalidAnchor
@ -1569,7 +1582,7 @@
: "This chapter does not exist in PlotDirector. Create or link the chapter first."); : "This chapter does not exist in PlotDirector. Create or link the chapter first.");
setResolveDiagnostics({ setResolveDiagnostics({
result: "Not matched", result: "Not matched",
chapterId: chapterMatched ? matchedChapterId : resolveResponse?.chapterId, chapterId: chapterMatched ? unmatchedChapterId : resolveResponse?.chapterId,
sceneId: resolveResponse?.sceneId sceneId: resolveResponse?.sceneId
}); });
if (!hadInvalidAnchor) { if (!hadInvalidAnchor) {