From a3d2a3327ae6247315b3c0428a08f8aae0661972 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Sat, 7 Feb 2026 09:42:38 +0100 Subject: [PATCH] feat: poll payment status every 15s on my-listings page for pending transactions --- js/components/pages/page-my-listings.js | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/js/components/pages/page-my-listings.js b/js/components/pages/page-my-listings.js index 11d11b3..5acca14 100644 --- a/js/components/pages/page-my-listings.js +++ b/js/components/pages/page-my-listings.js @@ -38,6 +38,50 @@ class PageMyListings extends HTMLElement { disconnectedCallback() { if (this.unsubscribe) this.unsubscribe() if (this.authUnsubscribe) this.authUnsubscribe() + this.stopPolling() + } + + startPolling() { + this.stopPolling() + const hasPending = this.listings.some(l => + l.payment_status === 'processing' || l.payment_status === 'pending' + ) + if (hasPending) { + this.pollInterval = setInterval(() => this.pollListings(), 15000) + } + } + + stopPolling() { + if (this.pollInterval) { + clearInterval(this.pollInterval) + this.pollInterval = null + } + } + + async pollListings() { + try { + const user = await auth.getUser() + if (!user) return + + const response = await directus.getListings({ + fields: [ + 'id', 'status', 'title', 'slug', 'price', 'currency', + 'condition', 'payment_status', 'date_created', 'user_created', + 'images.directus_files_id.id', + 'location.id', 'location.name' + ], + filter: { + user_created: { _eq: user.id } + }, + sort: ['-date_created'], + limit: 50 + }) + this.listings = response.items || [] + this.updateContent() + this.startPolling() + } catch (err) { + console.error('Polling failed:', err) + } } async loadMyListings() { @@ -65,6 +109,7 @@ class PageMyListings extends HTMLElement { this.listings = response.items || [] this.loading = false this.updateContent() + this.startPolling() } catch (err) { console.error('Failed to load my listings:', err) this.error = err.message