From 63b8ae500791f8e3b49fe210984827573889ecc8 Mon Sep 17 00:00:00 2001 From: Sergei Date: Sat, 24 Jan 2026 14:25:05 -0800 Subject: [PATCH] feat(sensors): Convert location code to display name in equipment list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add getLocationDisplay() helper to convert location ID (e.g., 'bedroom') to human-readable format with icon (e.g., '🛏️ Bedroom') using ROOM_LOCATIONS. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/(tabs)/beneficiaries/[id]/equipment.tsx | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/(tabs)/beneficiaries/[id]/equipment.tsx b/app/(tabs)/beneficiaries/[id]/equipment.tsx index bb790c1..7200910 100644 --- a/app/(tabs)/beneficiaries/[id]/equipment.tsx +++ b/app/(tabs)/beneficiaries/[id]/equipment.tsx @@ -17,7 +17,7 @@ import { router, useLocalSearchParams } from 'expo-router'; import * as Device from 'expo-device'; import { useBeneficiary } from '@/contexts/BeneficiaryContext'; import { useBLE } from '@/contexts/BLEContext'; -import { api } from '@/services/api'; +import { api, ROOM_LOCATIONS } from '@/services/api'; import type { WPSensor } from '@/types'; import { AppColors, @@ -54,34 +54,25 @@ export default function EquipmentScreen() { }, [id]); const loadSensors = async () => { - console.log('[Equipment] loadSensors called, beneficiaryId:', id); if (!id) { - console.log('[Equipment] No beneficiary ID, skipping load'); return; } try { setIsLoading(true); - console.log('[Equipment] Calling api.getDevicesForBeneficiary...'); // Get WP sensors from API (attached to beneficiary) const response = await api.getDevicesForBeneficiary(id); - console.log('[Equipment] API Response:', JSON.stringify(response, null, 2)); - if (!response.ok) { // If error is "Not authenticated with Legacy API" or network error, // just show empty state without Alert - console.warn('[Equipment] Could not load sensors:', response.error); setApiSensors([]); return; } - console.log('[Equipment] Sensors loaded successfully, count:', response.data?.length || 0); - console.log('[Equipment] Sensors data:', JSON.stringify(response.data, null, 2)); setApiSensors(response.data || []); } catch (error) { - console.error('[Equipment] Failed to load sensors:', error); // Show empty state instead of Alert setApiSensors([]); } finally { @@ -171,7 +162,6 @@ export default function EquipmentScreen() { Alert.alert('Success', `${sensor.name} has been detached.`); } catch (error) { - console.error('[Equipment] Failed to detach sensor:', error); Alert.alert('Error', 'Failed to detach sensor. Please try again.'); } finally { setIsDetaching(null); @@ -207,7 +197,6 @@ export default function EquipmentScreen() { setApiSensors([]); Alert.alert('Success', 'All sensors have been detached.'); } catch (error) { - console.error('[Equipment] Failed to detach all sensors:', error); Alert.alert('Error', 'Failed to detach sensors. Please try again.'); } finally { setIsLoading(false); @@ -270,6 +259,17 @@ export default function EquipmentScreen() { return 'Weak'; }; + // Convert location ID to display label with icon + const getLocationDisplay = (locationId: string | undefined): string => { + if (!locationId) return ''; + const location = ROOM_LOCATIONS.find(l => l.id === locationId); + if (location) { + return `${location.icon} ${location.label}`; + } + // Fallback for unknown location IDs + return locationId; + }; + if (isLoading) { return ( @@ -419,7 +419,7 @@ export default function EquipmentScreen() { styles.deviceLocation, !sensor.location && styles.deviceLocationPlaceholder ]}> - {sensor.location || 'No location set'} + {getLocationDisplay(sensor.location) || 'No location set'}