Skip to content

Commit d32724b

Browse files
committed
refactor(ad): revert in-article ad settings UI changes
- Revert SwitchListTile back to CheckboxListTile for in-article ad slot types - Remove premiuim user role special handling - Simplify role slot toggle logic
1 parent 7413d25 commit d32724b

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

lib/app_configuration/widgets/article_ad_settings_form.dart

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -198,41 +198,37 @@ class _ArticleAdSettingsFormState extends State<ArticleAdSettingsForm>
198198
ArticleAdConfiguration config,
199199
) {
200200
final roleSlots = config.visibleTo[role];
201-
final isEnabled = role != AppUserRole.premiumUser;
202201

203202
return Column(
204203
children: [
205204
SwitchListTile(
206-
// Changed from CheckboxListTile to SwitchListTile for consistency
207205
title: Text(l10n.enableInArticleAdsForRoleLabel(role.l10n(context))),
208-
value: roleSlots != null && isEnabled,
209-
onChanged: isEnabled
210-
? (value) {
211-
final newVisibleTo =
212-
Map<AppUserRole, Map<InArticleAdSlotType, bool>>.from(
213-
config.visibleTo,
214-
);
215-
if (value) {
216-
// Default values when enabling for a role
217-
newVisibleTo[role] = {
218-
InArticleAdSlotType.aboveArticleContinueReadingButton: true,
219-
InArticleAdSlotType.belowArticleContinueReadingButton: true,
220-
};
221-
} else {
222-
newVisibleTo.remove(role);
223-
}
206+
value: roleSlots != null, // Value is true if roleSlots exists
207+
onChanged: (value) {
208+
final newVisibleTo =
209+
Map<AppUserRole, Map<InArticleAdSlotType, bool>>.from(
210+
config.visibleTo,
211+
);
212+
if (value) {
213+
// Default values when enabling for a role
214+
newVisibleTo[role] = {
215+
InArticleAdSlotType.aboveArticleContinueReadingButton: true,
216+
InArticleAdSlotType.belowArticleContinueReadingButton: true,
217+
};
218+
} else {
219+
newVisibleTo.remove(role);
220+
}
224221

225-
widget.onConfigChanged(
226-
widget.remoteConfig.copyWith(
227-
adConfig: widget.remoteConfig.adConfig.copyWith(
228-
articleAdConfiguration: config.copyWith(
229-
visibleTo: newVisibleTo,
230-
),
231-
),
232-
),
233-
);
234-
}
235-
: null,
222+
widget.onConfigChanged(
223+
widget.remoteConfig.copyWith(
224+
adConfig: widget.remoteConfig.adConfig.copyWith(
225+
articleAdConfiguration: config.copyWith(
226+
visibleTo: newVisibleTo,
227+
),
228+
),
229+
),
230+
);
231+
},
236232
),
237233
if (roleSlots != null)
238234
Padding(
@@ -244,22 +240,23 @@ class _ArticleAdSettingsFormState extends State<ArticleAdSettingsForm>
244240
children: [
245241
// SwitchListTile for each InArticleAdSlotType
246242
for (final slotType in InArticleAdSlotType.values)
247-
SwitchListTile(
243+
CheckboxListTile(
248244
title: Text(slotType.l10n(context)),
249-
value: roleSlots[slotType] == true,
245+
value: roleSlots[slotType] ?? false,
250246
onChanged: (value) {
251-
final newRoleSlots =
252-
Map<InArticleAdSlotType, bool>.from(roleSlots);
253-
if (value) {
247+
final newRoleSlots = Map<InArticleAdSlotType, bool>.from(
248+
roleSlots,
249+
);
250+
if (value ?? false) {
254251
newRoleSlots[slotType] = true;
255252
} else {
256253
newRoleSlots.remove(slotType);
257254
}
258255

259256
final newVisibleTo =
260257
Map<AppUserRole, Map<InArticleAdSlotType, bool>>.from(
261-
config.visibleTo,
262-
)..[role] = newRoleSlots;
258+
config.visibleTo,
259+
)..[role] = newRoleSlots;
263260

264261
widget.onConfigChanged(
265262
widget.remoteConfig.copyWith(

0 commit comments

Comments
 (0)