mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-03-28 17:43:05 +01:00
Fix bug with statistics display on mobile
This commit is contained in:
@@ -102,6 +102,7 @@ export function SettingsModal(props: SettingsModalProps) {
|
||||
};
|
||||
|
||||
const [isMobileLayout, setIsMobileLayout] = useState(getIsMobileLayout);
|
||||
const externalDesktopSidebarMode = externalSidebarNav && !isMobileLayout;
|
||||
const [expandedSections, setExpandedSections] = useState<Record<SettingsSection, boolean>>(() => {
|
||||
const isMobile = getIsMobileLayout();
|
||||
return {
|
||||
@@ -245,8 +246,16 @@ export function SettingsModal(props: SettingsModalProps) {
|
||||
setSectionError(null);
|
||||
}, [externalSidebarNav, desktopSection]);
|
||||
|
||||
// On mobile with external sidebar nav, auto-expand the selected section
|
||||
useEffect(() => {
|
||||
if (!externalSidebarNav || !isMobileLayout || !desktopSection) return;
|
||||
setExpandedSections((prev) =>
|
||||
prev[desktopSection] ? prev : { ...prev, [desktopSection]: true }
|
||||
);
|
||||
}, [externalSidebarNav, isMobileLayout, desktopSection]);
|
||||
|
||||
// Fetch statistics when the section becomes visible
|
||||
const statisticsVisible = externalSidebarNav
|
||||
const statisticsVisible = externalDesktopSidebarMode
|
||||
? desktopSection === 'statistics'
|
||||
: expandedSections.statistics;
|
||||
|
||||
@@ -596,8 +605,6 @@ export function SettingsModal(props: SettingsModalProps) {
|
||||
setSectionError(null);
|
||||
};
|
||||
|
||||
const externalDesktopSidebarMode = externalSidebarNav && !isMobileLayout;
|
||||
|
||||
const isSectionVisible = (section: SettingsSection) =>
|
||||
externalDesktopSidebarMode ? desktopSection === section : expandedSections[section];
|
||||
|
||||
|
||||
@@ -341,4 +341,45 @@ describe('SettingsModal', () => {
|
||||
expect(screen.getByText('general')).toBeInTheDocument();
|
||||
expect(screen.getByText('42 msgs')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('fetches statistics when expanded in mobile external-nav mode', async () => {
|
||||
const mockStats: StatisticsResponse = {
|
||||
busiest_channels_24h: [],
|
||||
contact_count: 10,
|
||||
repeater_count: 3,
|
||||
channel_count: 5,
|
||||
total_packets: 200,
|
||||
decrypted_packets: 150,
|
||||
undecrypted_packets: 50,
|
||||
total_dms: 25,
|
||||
total_channel_messages: 80,
|
||||
total_outgoing: 30,
|
||||
contacts_heard: { last_hour: 2, last_24_hours: 7, last_week: 10 },
|
||||
repeaters_heard: { last_hour: 1, last_24_hours: 3, last_week: 3 },
|
||||
};
|
||||
|
||||
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
|
||||
new Response(JSON.stringify(mockStats), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
);
|
||||
|
||||
renderModal({
|
||||
mobile: true,
|
||||
externalSidebarNav: true,
|
||||
desktopSection: 'radio',
|
||||
});
|
||||
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole('button', { name: /Statistics/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetchSpy).toHaveBeenCalledWith('/api/statistics', expect.any(Object));
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Network')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user