Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions web_ui/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2290,6 +2290,8 @@ function AudionutsUAGUI() {
const descriptionVersionRef = useRef(
screenshotMode?.description.version || 0,
);
// Media id of the item the description draft state belongs to; a queue moves on without a new session.
const descriptionMediaRef = useRef(null);
const descriptionEditorRef = useRef(null);
const [descriptionAction, setDescriptionAction] = useState("");
const [canAddExecutionScreenshot, setCanAddExecutionScreenshot] = useState(
Expand Down Expand Up @@ -3651,6 +3653,7 @@ function AudionutsUAGUI() {
setDescriptionDraft("");
setDescriptionView("edit");
descriptionVersionRef.current = 0;
descriptionMediaRef.current = null;
setDescriptionVersion(0);
setDescriptionDirty(false);
setCanAddExecutionScreenshot(false);
Expand Down Expand Up @@ -3701,6 +3704,18 @@ function AudionutsUAGUI() {
const data = await response.json();
if (!cancelled && data && data.success && data.media) {
setExecutionPreview(data.media);
if (data.media.media_id !== descriptionMediaRef.current) {
// A new queue item: forget the previous item's draft and version,
// otherwise its higher version would reject this item's draft and
// the Description panel would keep showing the old text.
descriptionMediaRef.current = data.media.media_id;
descriptionVersionRef.current = 0;
descriptionDirtyRef.current = false;
setDescriptionVersion(0);
setDescriptionDraft("");
setDescriptionDirty(false);
setExecutionDescription(null);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
if (Array.isArray(data.media.progress)) {
setProgressItems((prev) =>
mergeProgressItemsById(prev, data.media.progress),
Expand Down Expand Up @@ -7530,6 +7545,8 @@ function AudionutsUAGUI() {

const saveExecutionDescription = async (content = descriptionDraft) => {
if (!sessionId || descriptionAction) return;
// A response that arrives after the queue moved on belongs to the previous item.
const mediaId = descriptionMediaRef.current;
setDescriptionAction("save");
try {
const response = await apiFetch(`${API_BASE}/execution_description`, {
Expand All @@ -7542,6 +7559,7 @@ function AudionutsUAGUI() {
}),
});
const data = await response.json().catch(() => null);
if (mediaId !== descriptionMediaRef.current) return;
if (!response.ok || !data?.success) {
if (response.status === 409 && Number.isInteger(data?.version)) {
descriptionVersionRef.current = data.version;
Expand Down Expand Up @@ -7573,6 +7591,7 @@ function AudionutsUAGUI() {

const resetExecutionDescription = async (sourceKey) => {
if (!sessionId || descriptionAction) return;
const mediaId = descriptionMediaRef.current;
setDescriptionAction(`reset:${sourceKey}`);
try {
const response = await apiFetch(
Expand All @@ -7588,6 +7607,7 @@ function AudionutsUAGUI() {
},
);
const data = await response.json().catch(() => null);
if (mediaId !== descriptionMediaRef.current) return;
if (!response.ok || !data?.success) {
if (response.status === 409 && Number.isInteger(data?.version)) {
descriptionVersionRef.current = data.version;
Expand Down