Skip to content

Commit 4d53bdf

Browse files
committed
fix: improve GIF removal logic
1 parent 637e678 commit 4d53bdf

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

js/app/component/gif.js

+26-7
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ export const gif = (() => {
136136
<div onclick="undangan.comment.gif.click('${ctx.uuid}', '${id}', '${util.base64Encode(url)}')" class="gif-checklist position-absolute justify-content-center align-items-center top-0 end-0 bg-overlay-auto p-1 m-1 rounded-circle border shadow-sm z-1">
137137
<i class="fa-solid fa-circle-check"></i>
138138
</div>
139-
<img src="${uri}" class="img-fluid" alt="${description}" style="width: 100%;">
139+
<img src="${uri}" class="img-fluid" alt="${util.escapeHtml(description)}" style="width: 100%;">
140140
</figure>
141-
`);
141+
`);
142142
});
143143
}
144144
k++;
@@ -181,9 +181,10 @@ export const gif = (() => {
181181
* @returns {Promise<void>}
182182
*/
183183
const render = async (ctx, reqCancel, response) => {
184+
let run = true;
185+
184186
ctx.last = new Promise((res) => {
185187
const load = loading(ctx);
186-
let run = true;
187188

188189
(async () => {
189190
await reqCancel;
@@ -207,10 +208,10 @@ export const gif = (() => {
207208
} else {
208209
alert(err);
209210
}
211+
} finally {
212+
load.release();
213+
res();
210214
}
211-
212-
load.release();
213-
res();
214215
})();
215216
});
216217
};
@@ -258,6 +259,11 @@ export const gif = (() => {
258259
* @returns {Promise<void>}
259260
*/
260261
const infinite = async (ctx) => {
262+
// Don't try to load more if there's no next page token
263+
if (!ctx.next || ctx.next.length === 0) {
264+
return;
265+
}
266+
261267
const isQuery = ctx.query && ctx.query.trim().length;
262268
const params = { pos: ctx.next, limit: ctx.limit };
263269

@@ -498,7 +504,20 @@ export const gif = (() => {
498504
* @param {string|null} uuid
499505
* @returns {void}
500506
*/
501-
const remove = (uuid = null) => uuid ? objectPool.delete(uuid) : objectPool.clear();
507+
const remove = (uuid = null) => {
508+
if (uuid) {
509+
if (objectPool.has(uuid)) {
510+
objectPool.get(uuid).reqs.forEach(f => f());
511+
512+
objectPool.delete(uuid);
513+
queue.delete(uuid);
514+
}
515+
} else {
516+
objectPool.forEach((ses) => ses.reqs.forEach(f => f()));
517+
objectPool.clear();
518+
queue.clear();
519+
}
520+
};
502521

503522
/**
504523
* @param {string} uuid

0 commit comments

Comments
 (0)