Skip to content

Commit 5884dec

Browse files
lolimmlostclaude
andcommitted
fix: Move queueRow() to dashboard script block so HTMX swaps work
The inline <script> in the queue_table partial wasn't executing after HTMX swaps, so Alpine couldn't find protect()/unprotect(). Moving the function to the persistent dashboard script block fixes this. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 35f3093 commit 5884dec

2 files changed

Lines changed: 22 additions & 24 deletions

File tree

src/web/templates/dashboard.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ <h3>Recent Activity</h3>
5656

5757
{% block scripts %}
5858
<script>
59+
function queueRow(item) {
60+
return {
61+
protecting: false,
62+
protect() {
63+
this.protecting = true;
64+
fetch('/api/protected/' + encodeURIComponent(item.download_id), {
65+
method: 'POST',
66+
headers: {'Content-Type': 'application/json'},
67+
body: JSON.stringify({title: item.title, arr_name: item.arr_name})
68+
}).then(() => {
69+
htmx.trigger('#queue-container', 'refresh');
70+
this.protecting = false;
71+
});
72+
},
73+
unprotect() {
74+
fetch('/api/protected/' + encodeURIComponent(item.download_id), {
75+
method: 'DELETE'
76+
}).then(() => htmx.trigger('#queue-container', 'refresh'));
77+
}
78+
}
79+
}
80+
5981
function dashboard() {
6082
return {
6183
triggering: false,

src/web/templates/partials/queue_table.html

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,6 @@
7272
</table>
7373
</figure>
7474
<p><small>{{ total }} items in queue</small></p>
75-
76-
<script>
77-
function queueRow(item) {
78-
return {
79-
protecting: false,
80-
protect() {
81-
this.protecting = true;
82-
fetch('/api/protected/' + encodeURIComponent(item.download_id), {
83-
method: 'POST',
84-
headers: {'Content-Type': 'application/json'},
85-
body: JSON.stringify({title: item.title, arr_name: item.arr_name})
86-
}).then(() => {
87-
htmx.trigger('#queue-container', 'refresh');
88-
this.protecting = false;
89-
});
90-
},
91-
unprotect() {
92-
fetch('/api/protected/' + encodeURIComponent(item.download_id), {
93-
method: 'DELETE'
94-
}).then(() => htmx.trigger('#queue-container', 'refresh'));
95-
}
96-
}
97-
}
98-
</script>
9975
{% else %}
10076
<p>Queue is empty</p>
10177
{% endif %}

0 commit comments

Comments
 (0)