Просмотр исходного кода

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 4 месяцев назад
Родитель
Сommit
2afdbc5e60

+ 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
   - Text wrap toggle: "Wrap" button in header to wrap long names instead of truncating
   - Both settings persist in localStorage
   - Both settings persist in localStorage
   - Tooltip shows full name on hover
   - 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
 ## [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 { useState, useEffect, useRef, useCallback } from 'react';
-import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
+import { useQuery, useQueries, useMutation, useQueryClient } from '@tanstack/react-query';
 import {
 import {
   Github,
   Github,
   Play,
   Play,
@@ -27,7 +27,6 @@ import type {
   ScheduleType,
   ScheduleType,
   CloudAuthStatus,
   CloudAuthStatus,
   Printer,
   Printer,
-  PrinterStatus,
 } from '../api/client';
 } from '../api/client';
 import { Card, CardContent, CardHeader } from './Card';
 import { Card, CardContent, CardHeader } from './Card';
 import { Button } from './Button';
 import { Button } from './Button';
@@ -149,11 +148,20 @@ export function GitHubBackupSettings() {
     queryFn: api.getPrinters,
     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 totalPrinters = printerStatuses.length;
   const connectedPrinters = printerStatuses.filter(p => p.connected).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 -->
     <!-- Splash screens for iOS -->
     <link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
     <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">
     <link rel="stylesheet" crossorigin href="/assets/index-nwJjDqT-.css">
   </head>
   </head>
   <body>
   <body>

Некоторые файлы не были показаны из-за большого количества измененных файлов