Parcourir la source

fix: cron input clears after save; Recent Schedules shows oldest first

Two SchedulesPage bugs surfaced after the cron editor shipped:

- After pressing Save the cron text input went blank. The save handler
  called loadScheduleDetails() which only refreshes this.schedules — not
  this.sites — so re-rendering pulled the stale (empty) scrape_cron value
  back into the input. Now calls loadSitesAndSchedules() so the site
  list is also refetched.

- 'Recent Schedules' was showing scheduled_jobs from a month ago because
  getScheduledJobs returns rows ordered by next_run_at ASC (oldest first),
  and the UI sliced(0, 3). For 'recent' to mean recent we now sort
  next_run_at DESC at render time, putting upcoming + last-completed runs
  on top — which matches what 'Last: 3d ago' in the header implies.
fszontagh il y a 2 mois
Parent
commit
0d1b7256a0
1 fichiers modifiés avec 8 ajouts et 4 suppressions
  1. 8 4
      web/src/components/pages/SchedulesPage.ts

+ 8 - 4
web/src/components/pages/SchedulesPage.ts

@@ -314,7 +314,10 @@ export class SchedulesPage {
           <div class="mt-4 pt-4 border-t border-gray-200 dark:border-gray-600">
             <h5 class="text-sm font-medium text-gray-900 dark:text-white mb-2">Recent Schedules:</h5>
             <div class="grid grid-cols-1 md:grid-cols-3 gap-2 text-xs">
-              ${siteSchedules.slice(0, 3).map(schedule => `
+              ${[...siteSchedules]
+                .sort((a, b) => (b.next_run_at || '').localeCompare(a.next_run_at || ''))
+                .slice(0, 3)
+                .map(schedule => `
                 <div class="flex items-center justify-between p-2 bg-gray-50 dark:bg-gray-700 rounded">
                   <span class="text-gray-700 dark:text-gray-300">
                     ${this.calculateNextScheduleTime(schedule)}
@@ -411,9 +414,10 @@ export class SchedulesPage {
                 ? `Cron set to "${cron}"${next ? ` — next run ${new Date(next).toLocaleString()}` : ''}`
                 : 'Cron cleared — using sitemap default'
             );
-            await this.loadScheduleDetails();
-            this.renderStats();
-            this.renderSchedulesList();
+            // Reload BOTH the site list (so scrape_cron in the input reflects
+            // the saved value) AND the per-site schedule rows (next_run_at).
+            // loadScheduleDetails alone leaves this.sites stale.
+            await this.loadSitesAndSchedules();
           } else {
             this.toastService.error('Update Failed', response.error || 'Failed to update cron');
           }