@@ -5,6 +5,7 @@ import android.util.Log
55import androidx.compose.foundation.layout.Arrangement
66import androidx.compose.foundation.layout.PaddingValues
77import androidx.compose.foundation.layout.fillMaxSize
8+ import androidx.compose.foundation.layout.fillMaxWidth
89import androidx.compose.foundation.layout.padding
910import androidx.compose.foundation.lazy.LazyColumn
1011import androidx.compose.foundation.lazy.items
@@ -19,6 +20,8 @@ import androidx.compose.ui.Modifier
1920import androidx.compose.ui.unit.dp
2021import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
2122import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
23+ import com.pennapps.labs.pennmobile.compose.presentation.components.error.ErrorCard
24+ import com.pennapps.labs.pennmobile.compose.presentation.components.error.UserDisplayErrors
2225import com.pennapps.labs.pennmobile.dining.composables.components.DiningBalancesCard
2326import com.pennapps.labs.pennmobile.dining.composables.components.DiningPredictionCard
2427import com.pennapps.labs.pennmobile.dining.viewmodels.DiningInsightsViewModel
@@ -54,6 +57,8 @@ fun DiningInsightsScreen(
5457 }
5558
5659 val cells by viewModel.cells.collectAsState()
60+ val pastBalances by viewModel.pastBalances.collectAsState()
61+
5762 LazyColumn (
5863 modifier =
5964 modifier
@@ -88,39 +93,64 @@ fun DiningInsightsScreen(
8893 )
8994 }
9095
91- // Header for Dining Dollars Predictions
92- item {
93- Text (
94- text = " Dining Dollars Predictions" ,
95- fontFamily = GilroyExtraBold ,
96- color = MaterialTheme .colorScheme.onBackground,
97- modifier = Modifier .padding(bottom = 4 .dp),
98- )
99- }
96+ /*
97+ * When the pastBalances list size is:
98+ * a) 0 -> The user is either a junior/senior not on a dining plan or an RA who has a plan but for RAs, we never get the plan balances at all
99+ * b) 1 -> The user is a normal student on a plan. However, Campus Express currently has an issue
100+ * c) 2 or more -> Everything is alright. Render the balances graph.
101+ */
102+ pastBalances?.diningBalancesList?.size?.let { balanceListSize ->
103+ if (balanceListSize == 0 || balanceListSize == 1 ) {
104+ item {
105+ ErrorCard (
106+ modifier =
107+ Modifier
108+ .padding(vertical = 12 .dp)
109+ .fillMaxWidth(0.95f ),
110+ errorMessage =
111+ when (balanceListSize) {
112+ 0 -> UserDisplayErrors .PAST_BALANCES_NOT_AVAILABLE
113+ 1 -> UserDisplayErrors .CAMPUS_EXPRESS_DOWN
114+ else -> " Error occurred"
115+ },
116+ )
117+ }
118+ } else {
119+ // Header for Dining Dollars Predictions
120+ item {
121+ Text (
122+ text = " Dining Dollars Predictions" ,
123+ fontFamily = GilroyExtraBold ,
124+ color = MaterialTheme .colorScheme.onBackground,
125+ modifier = Modifier .padding(bottom = 4 .dp),
126+ )
127+ }
100128
101- // Dining Dollars Prediction cards
102- items(cells.filter { it.type == " dining_dollars_predictions" }) { cell ->
103- DiningPredictionCard (
104- cell = cell,
105- modifier = Modifier .padding(bottom = 12 .dp),
106- )
107- }
129+ // Dining Dollars Prediction cards
130+ items(cells.filter { it.type == " dining_dollars_predictions" }) { cell ->
131+ DiningPredictionCard (
132+ cell = cell,
133+ modifier = Modifier .padding(bottom = 12 .dp),
134+ )
135+ }
108136
109- // Header for Swipes Predictions
110- item {
111- Text (
112- text = " Swipes Predictions" ,
113- fontFamily = GilroyExtraBold ,
114- color = MaterialTheme .colorScheme.onBackground,
115- modifier = Modifier .padding(bottom = 4 .dp),
116- )
117- }
137+ // Header for Swipes Predictions
138+ item {
139+ Text (
140+ text = " Swipes Predictions" ,
141+ fontFamily = GilroyExtraBold ,
142+ color = MaterialTheme .colorScheme.onBackground,
143+ modifier = Modifier .padding(bottom = 4 .dp),
144+ )
145+ }
118146
119- // Swipes Prediction cards
120- items(cells.filter { it.type == " dining_swipes_predictions" }) { cell ->
121- DiningPredictionCard (
122- cell = cell,
123- )
147+ // Swipes Prediction cards
148+ items(cells.filter { it.type == " dining_swipes_predictions" }) { cell ->
149+ DiningPredictionCard (
150+ cell = cell,
151+ )
152+ }
153+ }
124154 }
125155 }
126156 }
0 commit comments