forked from jsnbuchanan/crowd-funder-for-time-pwa
feat: add auto-refresh with countdown to MembersList
- Auto-refresh members list every 10 seconds - Display countdown timer in refresh buttons - Manual refresh resets countdown to 10 seconds
This commit is contained in:
@@ -59,11 +59,12 @@
|
|||||||
-->
|
-->
|
||||||
<button
|
<button
|
||||||
class="text-sm bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
class="text-sm bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
||||||
title="Refresh members list"
|
title="Refresh members list now"
|
||||||
@click="fetchMembers"
|
@click="manualRefresh"
|
||||||
>
|
>
|
||||||
<font-awesome icon="rotate" :class="{ 'fa-spin': isLoading }" />
|
<font-awesome icon="rotate" :class="{ 'fa-spin': isLoading }" />
|
||||||
Refresh <span class="text-xs">(10s)</span>
|
Refresh
|
||||||
|
<span class="text-xs">({{ countdownTimer }}s)</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@@ -155,11 +156,12 @@
|
|||||||
-->
|
-->
|
||||||
<button
|
<button
|
||||||
class="text-sm bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
class="text-sm bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
||||||
title="Refresh members list"
|
title="Refresh members list now"
|
||||||
@click="fetchMembers"
|
@click="manualRefresh"
|
||||||
>
|
>
|
||||||
<font-awesome icon="rotate" :class="{ 'fa-spin': isLoading }" />
|
<font-awesome icon="rotate" :class="{ 'fa-spin': isLoading }" />
|
||||||
Refresh <span class="text-xs">(10s)</span>
|
Refresh
|
||||||
|
<span class="text-xs">({{ countdownTimer }}s)</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@@ -243,6 +245,11 @@ export default class MembersList extends Vue {
|
|||||||
apiServer = "";
|
apiServer = "";
|
||||||
contacts: Array<Contact> = [];
|
contacts: Array<Contact> = [];
|
||||||
|
|
||||||
|
// Auto-refresh functionality
|
||||||
|
countdownTimer = 10;
|
||||||
|
autoRefreshInterval: NodeJS.Timeout | null = null;
|
||||||
|
lastRefreshTime = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the unnamed member constant
|
* Get the unnamed member constant
|
||||||
*/
|
*/
|
||||||
@@ -264,6 +271,9 @@ export default class MembersList extends Vue {
|
|||||||
this.firstName = settings.firstName || "";
|
this.firstName = settings.firstName || "";
|
||||||
await this.fetchMembers();
|
await this.fetchMembers();
|
||||||
await this.loadContacts();
|
await this.loadContacts();
|
||||||
|
|
||||||
|
// Start auto-refresh
|
||||||
|
this.startAutoRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshData() {
|
async refreshData() {
|
||||||
@@ -576,6 +586,52 @@ export default class MembersList extends Vue {
|
|||||||
-1,
|
-1,
|
||||||
); // -1 means no auto-dismiss, stays open until user acts
|
); // -1 means no auto-dismiss, stays open until user acts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startAutoRefresh() {
|
||||||
|
this.lastRefreshTime = Date.now();
|
||||||
|
this.countdownTimer = 10;
|
||||||
|
|
||||||
|
this.autoRefreshInterval = setInterval(() => {
|
||||||
|
const now = Date.now();
|
||||||
|
const timeSinceLastRefresh = (now - this.lastRefreshTime) / 1000;
|
||||||
|
|
||||||
|
if (timeSinceLastRefresh >= 10) {
|
||||||
|
// Time to refresh
|
||||||
|
this.fetchMembers();
|
||||||
|
this.lastRefreshTime = now;
|
||||||
|
this.countdownTimer = 10;
|
||||||
|
} else {
|
||||||
|
// Update countdown
|
||||||
|
this.countdownTimer = Math.max(
|
||||||
|
0,
|
||||||
|
Math.round(10 - timeSinceLastRefresh),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, 1000); // Update every second
|
||||||
|
}
|
||||||
|
|
||||||
|
stopAutoRefresh() {
|
||||||
|
if (this.autoRefreshInterval) {
|
||||||
|
clearInterval(this.autoRefreshInterval);
|
||||||
|
this.autoRefreshInterval = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
manualRefresh() {
|
||||||
|
// Clear existing auto-refresh interval
|
||||||
|
if (this.autoRefreshInterval) {
|
||||||
|
clearInterval(this.autoRefreshInterval);
|
||||||
|
this.autoRefreshInterval = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger immediate refresh and restart timer
|
||||||
|
this.fetchMembers();
|
||||||
|
this.startAutoRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeDestroy() {
|
||||||
|
this.stopAutoRefresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user