Show chat uploads in gallery immediately

This commit is contained in:
pewdiepie-archdaemon
2026-06-29 01:57:35 +00:00
parent 402a2771b3
commit b419caf9f7
2 changed files with 20 additions and 4 deletions
+4
View File
@@ -183,6 +183,10 @@ export async function uploadPending() {
}
const data = await res.json();
uploaded = (data.files || []);
if (uploaded.some(x => x && x.gallery_id)) {
try { localStorage.setItem('gallery-fresh-chat-upload', String(Date.now())); } catch (_) {}
window.dispatchEvent(new CustomEvent('gallery-refresh', { detail: { source: 'chat-upload' } }));
}
pendingFiles = []; // clear only on success
// Stash the full meta (incl. width/height for images) on the module so
// callers that want it can grab it via getLastUploadedMeta(). Keep the
+16 -4
View File
@@ -14,7 +14,12 @@ let _open = false;
let _galleryResizeHandler = null;
// Auto-refresh gallery when new image is generated
window.addEventListener('gallery-refresh', () => {
window.addEventListener('gallery-refresh', (e) => {
if (e?.detail?.source === 'chat-upload' && _sort !== 'recent') {
_sort = 'recent';
const sortSel = document.getElementById('gallery-sort');
if (sortSel) sortSel.value = 'recent';
}
if (_open) _fetchLibrary(false);
});
let _items = [];
@@ -1894,6 +1899,13 @@ export function openGallery() {
if (_open) return;
_open = true;
_galleryCascaded = false; // replay the domino-in cascade on each open
let _freshChatUpload = false;
try {
const ts = Number(localStorage.getItem('gallery-fresh-chat-upload') || '0');
_freshChatUpload = ts > 0 && Date.now() - ts < 5 * 60 * 1000;
if (_freshChatUpload) localStorage.removeItem('gallery-fresh-chat-upload');
} catch (_) {}
if (_freshChatUpload) _sort = 'recent';
// State is preserved across close/reopen — filters, album, sort, items,
// albums, people — so reopening the gallery feels instant. Use the search
// input or "All" chip to clear the active filter.
@@ -1955,9 +1967,9 @@ export function openGallery() {
<option value="">All sources</option>
</select>
<select class="gallery-sort" id="gallery-sort">
<option value="shuffle">Random</option>
<option value="recent">Recent</option>
<option value="oldest">Oldest</option>
<option value="shuffle"${_sort === 'shuffle' ? ' selected' : ''}>Random</option>
<option value="recent"${_sort === 'recent' ? ' selected' : ''}>Recent</option>
<option value="oldest"${_sort === 'oldest' ? ' selected' : ''}>Oldest</option>
</select>
<button class="gallery-select-btn gallery-toolbar-action" id="gallery-select-btn" title="Select for bulk actions"><span style="position:relative;top:1px;">Select</span></button>
</div>