@@ -10,6 +10,7 @@ import {
1010 Text ,
1111} from 'react-native' ;
1212import { LineChart , PieChart } from 'react-native-chart-kit' ;
13+ import { retrieveData } from './caching' ;
1314import susDashboardStyles from './components/styles/SustainabilityDashboard.styles' ;
1415import fullBloom from './assets/SustainablityDashboard/Rootyfullbloom.png' ;
1516import bushy from './assets/SustainablityDashboard/RootyBushy.png' ;
@@ -182,7 +183,7 @@ export default function Dashboard() {
182183 } ) ;
183184
184185 // test name
185- const senderName = 'Cormac' ;
186+ // const senderName = 'Cormac';
186187
187188 useEffect ( ( ) => {
188189 // eslint-disable-next-line no-use-before-define
@@ -241,6 +242,14 @@ export default function Dashboard() {
241242
242243 const getSustainabilityStats = async ( ) => {
243244 try {
245+ let senderName = await retrieveData ( 'username' ) ;
246+
247+ console . log ( senderName ) ;
248+
249+ if ( senderName == null ) {
250+ senderName = 'test_user' ; // Default name if not found
251+ }
252+
244253 const baseUrl =
245254 Platform . OS === 'web'
246255 ? 'http://localhost:8000'
@@ -259,15 +268,17 @@ export default function Dashboard() {
259268 } ,
260269 ) ;
261270
271+ console . log ( 'Raw response: ' , response ) ;
272+
262273 if ( response . ok ) {
263274 const serverMessage = await response . json ( ) ;
264275 console . log ( 'Response from Server: ' , serverMessage . message ) ;
265276
266277 const {
267- emissionsSavings,
268- currentYearEmissions,
269- rawDistances,
270- friendsSusScores,
278+ emissions_savings : emissionsSavings ,
279+ current_year_emissions : currentYearEmissions ,
280+ raw_distances : rawDistances ,
281+ friends_sus_scores : friendsSusScores ,
271282 } = serverMessage ;
272283
273284 console . log ( 'Emissions savings: ' , emissionsSavings ) ;
0 commit comments