Skip to content

Commit 4ed22dd

Browse files
committed
fix(local_ads_management): listen for restored local ad and update UI
- Add listener for `restoredLocalAd` in `_ArchivedLocalAdsViewState` - Implement `RestoreLocalAdRequested` event handling - Remove duplicate `AdType` extension
1 parent 9d6f107 commit 4ed22dd

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

lib/local_ads_management/view/archived_local_ads_page.dart

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ import 'package:data_repository/data_repository.dart';
33
import 'package:data_table_2/data_table_2.dart';
44
import 'package:flutter/material.dart';
55
import 'package:flutter_bloc/flutter_bloc.dart';
6+
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/app_localizations.dart';
67
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
78
import 'package:flutter_news_app_web_dashboard_full_source_code/local_ads_management/bloc/archive_local_ads/archive_local_ads_bloc.dart';
8-
import 'package:flutter_news_app_web_dashboard_full_source_code/local_ads_management/bloc/local_ads_management_bloc.dart';
9+
import 'package:flutter_news_app_web_dashboard_full_source_code/local_ads_management/bloc/local_ads_management_bloc.dart'
10+
hide
11+
DeleteLocalAdForeverRequested,
12+
UndoDeleteLocalAdRequested,
13+
RestoreLocalAdRequested;
914
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/extensions/content_status_l10n.dart';
1015
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/extensions/extensions.dart';
16+
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/extensions/string_truncate.dart';
1117
import 'package:intl/intl.dart';
1218
import 'package:ui_kit/ui_kit.dart';
1319

@@ -88,7 +94,9 @@ class _ArchivedLocalAdsViewState extends State<_ArchivedLocalAdsView>
8894
current.interstitialAds.length &&
8995
current.lastDeletedLocalAd == null) ||
9096
(previous.videoAds.length != current.videoAds.length &&
91-
current.lastDeletedLocalAd == null),
97+
current.lastDeletedLocalAd == null) ||
98+
(previous.restoredLocalAd == null &&
99+
current.restoredLocalAd != null),
92100
listener: (context, state) {
93101
if (state.lastDeletedLocalAd != null) {
94102
String truncatedTitle;
@@ -162,7 +170,7 @@ class _ArchivedLocalAdsDataTable extends StatelessWidget {
162170
final l10n = AppLocalizationsX(context).l10n;
163171
return BlocBuilder<ArchiveLocalAdsBloc, ArchiveLocalAdsState>(
164172
builder: (context, state) {
165-
ArchivedLocalAdsStatus status;
173+
ArchiveLocalAdsStatus status;
166174
List<LocalAd> ads;
167175
String? cursor;
168176
bool hasMore;
@@ -190,15 +198,15 @@ class _ArchivedLocalAdsDataTable extends StatelessWidget {
190198
hasMore = state.videoAdsHasMore;
191199
}
192200

193-
if (status == ArchivedLocalAdsStatus.loading && ads.isEmpty) {
201+
if (status == ArchiveLocalAdsStatus.loading && ads.isEmpty) {
194202
return LoadingStateWidget(
195203
icon: Icons.ads_click,
196204
headline: l10n.loadingArchivedLocalAds,
197205
subheadline: l10n.pleaseWait,
198206
);
199207
}
200208

201-
if (status == ArchivedLocalAdsStatus.failure) {
209+
if (status == ArchiveLocalAdsStatus.failure) {
202210
return FailureStateWidget(
203211
exception: state.exception!,
204212
onRetry: () => context.read<ArchiveLocalAdsBloc>().add(
@@ -216,7 +224,7 @@ class _ArchivedLocalAdsDataTable extends StatelessWidget {
216224

217225
return Column(
218226
children: [
219-
if (status == ArchivedLocalAdsStatus.loading && ads.isNotEmpty)
227+
if (status == ArchiveLocalAdsStatus.loading && ads.isNotEmpty)
220228
const LinearProgressIndicator(),
221229
Expanded(
222230
child: PaginatedDataTable2(
@@ -252,7 +260,7 @@ class _ArchivedLocalAdsDataTable extends StatelessWidget {
252260
final newOffset = pageIndex * kDefaultRowsPerPage;
253261
if (newOffset >= ads.length &&
254262
hasMore &&
255-
status != ArchivedLocalAdsStatus.loading) {
263+
status != ArchiveLocalAdsStatus.loading) {
256264
context.read<ArchiveLocalAdsBloc>().add(
257265
LoadArchivedLocalAdsRequested(
258266
adType: adType,
@@ -384,20 +392,3 @@ class _ArchivedLocalAdsDataSource extends DataTableSource {
384392
@override
385393
int get selectedRowCount => 0;
386394
}
387-
388-
extension on LocalAd {
389-
AdType toAdType() {
390-
switch (adType) {
391-
case 'native':
392-
return AdType.native;
393-
case 'banner':
394-
return AdType.banner;
395-
case 'interstitial':
396-
return AdType.interstitial;
397-
case 'video':
398-
return AdType.video;
399-
default:
400-
throw FormatException('Unknown AdType: $adType');
401-
}
402-
}
403-
}

0 commit comments

Comments
 (0)