فهرست منبع

Fix K-profiles backup status showing incorrect printer connection count

The GitHub backup settings page was showing "1/2 connected" even when
both printers were connected. This happened because the code read
printer status from the React Query cache, which is only populated by
WebSocket messages received on other pages.

Changed to use useQueries to fetch printer status directly from the API
(/api/v1/printers/{id}/status) instead of relying on cached WebSocket
data. Results are cached for 10s and refreshed every 30s.
maziggy 7 ماه پیش
والد
کامیت
2afdbc5e60
5فایلهای تغییر یافته به همراه17 افزوده شده و 8 حذف شده
  1. 1 0
      CHANGELOG.md
  2. 15 7
      frontend/src/components/GitHubBackupSettings.tsx
  3. 0 0
      static/assets/index-BkOQ27rS.js
  4. 0 0
      static/assets/index-DuO_7tQ3.js
  5. 1 1
      static/index.html

+ 1 - 0
CHANGELOG.md

@@ -114,6 +114,7 @@ All notable changes to Bambuddy will be documented in this file.
   - Text wrap toggle: "Wrap" button in header to wrap long names instead of truncating
   - Both settings persist in localStorage
   - Tooltip shows full name on hover
+- **K-Profiles Backup Status** - Fixed GitHub backup settings showing incorrect printer connection count (e.g., "1/2 connected" when both printers are connected); now fetches status from API instead of relying on WebSocket cache
 
 ## [0.1.6b11] - 2026-01-22
 

+ 15 - 7
frontend/src/components/GitHubBackupSettings.tsx

@@ -1,5 +1,5 @@
 import { useState, useEffect, useRef, useCallback } from 'react';
-import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
+import { useQuery, useQueries, useMutation, useQueryClient } from '@tanstack/react-query';
 import {
   Github,
   Play,
@@ -27,7 +27,6 @@ import type {
   ScheduleType,
   CloudAuthStatus,
   Printer,
-  PrinterStatus,
 } from '../api/client';
 import { Card, CardContent, CardHeader } from './Card';
 import { Button } from './Button';
@@ -149,11 +148,20 @@ export function GitHubBackupSettings() {
     queryFn: api.getPrinters,
   });
 
-  // Get printer statuses from cache (populated by WebSocket on other pages)
-  const printerStatuses = printers?.map(p => {
-    const status = queryClient.getQueryData<PrinterStatus>(['printerStatus', p.id]);
-    return { printer: p, connected: status?.connected ?? false };
-  }) ?? [];
+  // Fetch printer statuses from API (not just cache) to get accurate connection status
+  const printerStatusQueries = useQueries({
+    queries: (printers ?? []).map(printer => ({
+      queryKey: ['printerStatus', printer.id],
+      queryFn: () => api.getPrinterStatus(printer.id),
+      staleTime: 10000, // Consider stale after 10s
+      refetchInterval: 30000, // Refresh every 30s
+    })),
+  });
+
+  const printerStatuses = (printers ?? []).map((printer, index) => ({
+    printer,
+    connected: printerStatusQueries[index]?.data?.connected ?? false,
+  }));
 
   const totalPrinters = printerStatuses.length;
   const connectedPrinters = printerStatuses.filter(p => p.connected).length;

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
static/assets/index-BkOQ27rS.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
static/assets/index-DuO_7tQ3.js


+ 1 - 1
static/index.html

@@ -23,7 +23,7 @@
 
     <!-- Splash screens for iOS -->
     <link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
-    <script type="module" crossorigin src="/assets/index-BkOQ27rS.js"></script>
+    <script type="module" crossorigin src="/assets/index-DuO_7tQ3.js"></script>
     <link rel="stylesheet" crossorigin href="/assets/index-nwJjDqT-.css">
   </head>
   <body>

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است