@@ -123,76 +123,83 @@ fun HomePage(navigationController: NavController) {
123123 }
124124 }
125125
126- if (ffViewModel.isFeatureEnabled(FeatureFlippingEnum .QVST )) {
127- // When we have loaded the qvst campaigns
128- when (campaignActiveViewModel.state) {
129-
130- // If we successfully loaded the campaigns
131- is QvstActiveUiState .SUCCESS -> {
132- item {
133- Title (label = " À ne pas manquer !" )
134- val campaigns: List <QvstCampaignEntity > =
135- (campaignActiveViewModel.state as QvstActiveUiState .SUCCESS ).qvst
136- QvstCardList (
137- navigationController = navigationController,
138- campaigns = campaigns,
139- collapsable = false
140- )
141- }
142- }
126+ if (ffViewModel.isFeatureEnabled(FeatureFlippingEnum .QVST ) ||
127+ ffViewModel.isFeatureEnabled(FeatureFlippingEnum .AGENDA )) {
128+ fun hasContent (): Boolean {
129+ val campaigns = (campaignActiveViewModel.state as ?
130+ QvstActiveUiState .SUCCESS )?.qvst ? : emptyList()
131+ val agendaState = agendaViewModel.state as ? AgendaUiState .SUCCESS
132+ val events = agendaState?.agendaEvent ? : emptyList()
133+ val birthdays = agendaState?.agendaBirthday ? : emptyList()
134+
135+ return campaigns.isNotEmpty() || events.isNotEmpty()
136+ || birthdays.isNotEmpty()
137+ }
143138
144- // If there was an error loading the campaigns
145- is QvstActiveUiState .ERROR -> {
146- item {
147- CustomDialog (
148- title = stringResource(id = R .string.login_page_error_title),
149- message = (campaignActiveViewModel.state as QvstActiveUiState .ERROR ).error,
150- ) {
151- campaignActiveViewModel.resetState()
152- }
153- }
154- }
139+ item {
140+ Title (label = " À ne pas manquer !" )
155141 }
156- }
157142
158- if (ffViewModel.isFeatureEnabled(FeatureFlippingEnum .AGENDA )) {
159- // When we have loaded the agenda events
160- when (agendaViewModel.state) {
161-
162- // If we successfully loaded the events
163- is AgendaUiState .SUCCESS -> {
164- item {
165- val state = agendaViewModel.state as AgendaUiState .SUCCESS
166- val events = state.agendaEvent.map { AgendaEventItem (it) }
167- val birthdays = state.agendaBirthday.map { AgendaBirthdayItem (it) }
168- val items = (events + birthdays).sortedBy { it.date }
169- val eventsTypes = state.agendaEventType
170- AgendaCardList (
171- items = items,
172- eventsTypes = eventsTypes,
173- collapsable = false
174- )
143+ if (hasContent()) {
144+ if (ffViewModel.isFeatureEnabled(FeatureFlippingEnum .QVST )) {
145+ when (campaignActiveViewModel.state) {
146+ is QvstActiveUiState .SUCCESS -> {
147+ item {
148+ val campaigns = (campaignActiveViewModel.state
149+ as QvstActiveUiState .SUCCESS ).qvst
150+ QvstCardList (
151+ navigationController = navigationController,
152+ campaigns = campaigns,
153+ collapsable = false
154+ )
155+ }
156+ }
157+ is QvstActiveUiState .ERROR -> {
158+ item {
159+ CustomDialog (
160+ title = stringResource(id = R .string.login_page_error_title),
161+ message = (campaignActiveViewModel.state as
162+ QvstActiveUiState .ERROR ).error,
163+ ) {
164+ campaignActiveViewModel.resetState()
165+ }
166+ }
167+ }
168+ else -> {}
175169 }
176170 }
177171
178- // If there was an error loading the events
179- is AgendaUiState .ERROR -> {
180- item {
181- LaunchedEffect (Unit ) {
182- agendaViewModel.updateState()
172+ if (ffViewModel.isFeatureEnabled(FeatureFlippingEnum .AGENDA )) {
173+ when (agendaViewModel.state) {
174+ is AgendaUiState .SUCCESS -> {
175+ item {
176+ val state = agendaViewModel.state as AgendaUiState .SUCCESS
177+ val events = state.agendaEvent.map { AgendaEventItem (it) }
178+ val birthdays = state.agendaBirthday.map { AgendaBirthdayItem (it) }
179+ val items = (events + birthdays).sortedBy { it.date }
180+ AgendaCardList (
181+ items = items,
182+ eventsTypes = state.agendaEventType,
183+ collapsable = false
184+ )
185+ }
183186 }
187+ is AgendaUiState .ERROR -> {
188+ item {
189+ LaunchedEffect (Unit ) {
190+ agendaViewModel.updateState()
191+ }
192+ }
193+ }
194+ else -> {}
184195 }
185196 }
197+ } else {
198+ item {
199+ NoContentPlaceHolder ()
200+ }
186201 }
187202 }
188-
189- if (! ffViewModel.isFeatureEnabled(FeatureFlippingEnum .NEWSLETTERS )
190- && ! ffViewModel.isFeatureEnabled(FeatureFlippingEnum .QVST ) && ! ffViewModel.isFeatureEnabled(
191- FeatureFlippingEnum .AGENDA
192- )
193- ) {
194- item { NoContentPlaceHolder () }
195- }
196203 }
197204 }
198205 }
0 commit comments