|
17 | 17 | sel: { b0: null, b1: null, tracks: new Set(), notes: [] }, loop: false, drag: null, userScrollAt: 0, follow: true, |
18 | 18 | }; |
19 | 19 | let dlg, scroller, canvas, space, tip; |
| 20 | + const HINT = 'Saved to review.json in the song folder with the bars, tracks, notes and time you selected.'; |
20 | 21 |
|
21 | 22 | /* ---------- markup ---------- */ |
22 | 23 | function build() { |
|
57 | 58 | <h4>Comment for the agent</h4> |
58 | 59 | <textarea id="ed-text" placeholder="What should change here? (Cmd+Enter to save)"></textarea> |
59 | 60 | <div class="ed-actions"><button class="ed-btn primary" id="ed-save">Save comment</button></div> |
60 | | - <div class="ed-hint">Saved to review.json in the song folder with the bars, tracks, notes and time you selected.</div> |
| 61 | + <div class="ed-hint">${HINT}</div> |
61 | 62 | </section> |
62 | 63 | <h4 style="padding:12px 14px 0;margin:0">Comments <span class="r" id="ed-count"></span></h4> |
63 | 64 | <div class="ed-list" id="ed-list"></div> |
|
575 | 576 | const r = reference(); |
576 | 577 | const body = { op: 'add', text, ref: r.ref || 'whole song', render: state.song.reportPath ? state.files[state.song.reportPath]?.[1] : null }; |
577 | 578 | for (const k of ['bars', 'beats', 'time', 'tracks', 'notes']) if (r[k]) body[k] = r[k]; |
578 | | - const res = await fetch('api/review?song=' + encodeURIComponent(state.slug), { method: 'POST', headers: postHeaders(), body: JSON.stringify(body) }).then(r => r.json()); |
579 | | - if (res.comments) { E.comments = res.comments; $d('#ed-text').value = ''; renderComments(); badge(); dirty(); } |
| 579 | + const res = await post(body); |
| 580 | + if (res?.comments) { E.comments = res.comments; $d('#ed-text').value = ''; renderComments(); badge(); dirty(); } |
580 | 581 | } |
581 | 582 | async function op(body) { |
582 | | - const res = await fetch('api/review?song=' + encodeURIComponent(state.slug), { method: 'POST', headers: postHeaders(), body: JSON.stringify(body) }).then(r => r.json()); |
583 | | - if (res.comments) { E.comments = res.comments; renderComments(); badge(); dirty(); } |
| 583 | + const res = await post(body); |
| 584 | + if (res?.comments) { E.comments = res.comments; renderComments(); badge(); dirty(); } |
| 585 | + } |
| 586 | + // a change to review.json; a failure shows under the save button instead of vanishing (the text stays in the box) |
| 587 | + async function post(body) { |
| 588 | + const hint = $d('.ed-hint'); |
| 589 | + try { |
| 590 | + const res = await postJson('api/review?song=' + encodeURIComponent(state.slug), body); |
| 591 | + hint.textContent = HINT; hint.classList.remove('err'); |
| 592 | + return res; |
| 593 | + } catch (e) { |
| 594 | + hint.textContent = `Not saved: ${e.message}. Reload the page and save again.`; hint.classList.add('err'); |
| 595 | + return null; |
| 596 | + } |
584 | 597 | } |
585 | 598 | function renderComments() { |
586 | 599 | if (!dlg) return; |
|
0 commit comments