@@ -12,6 +12,7 @@ import 'package:flutter_news_app_web_dashboard_full_source_code/local_ads_manage
1212 RestoreLocalAdRequested,
1313 UndoDeleteLocalAdRequested;
1414import 'package:flutter_news_app_web_dashboard_full_source_code/shared/extensions/extensions.dart' ;
15+ import 'package:flutter_news_app_web_dashboard_full_source_code/shared/services/pending_deletions_service.dart' ;
1516import 'package:intl/intl.dart' ;
1617import 'package:ui_kit/ui_kit.dart' ;
1718
@@ -28,6 +29,7 @@ class ArchivedLocalAdsPage extends StatelessWidget {
2829 create: (context) =>
2930 ArchiveLocalAdsBloc (
3031 localAdsRepository: context.read <DataRepository <LocalAd >>(),
32+ pendingDeletionsService: context.read <PendingDeletionsService >(),
3133 )
3234 ..add (const LoadArchivedLocalAdsRequested (adType: AdType .native ))
3335 ..add (const LoadArchivedLocalAdsRequested (adType: AdType .banner))
@@ -77,6 +79,7 @@ class _ArchivedLocalAdsViewState extends State<_ArchivedLocalAdsView>
7779 @override
7880 Widget build (BuildContext context) {
7981 final l10n = AppLocalizationsX (context).l10n;
82+ final pendingDeletionsService = context.read <PendingDeletionsService >();
8083 return Scaffold (
8184 appBar: AppBar (
8285 title: Text (l10n.archivedLocalAdsTitle),
@@ -89,42 +92,14 @@ class _ArchivedLocalAdsViewState extends State<_ArchivedLocalAdsView>
8992 ),
9093 body: BlocListener <ArchiveLocalAdsBloc , ArchiveLocalAdsState >(
9194 listenWhen: (previous, current) =>
92- previous.lastDeletedLocalAd != current.lastDeletedLocalAd ||
93- (previous.nativeAds.length != current.nativeAds.length &&
94- current.lastDeletedLocalAd == null ) ||
95- (previous.bannerAds.length != current.bannerAds.length &&
96- current.lastDeletedLocalAd == null ) ||
97- (previous.interstitialAds.length !=
98- current.interstitialAds.length &&
99- current.lastDeletedLocalAd == null ) ||
100- (previous.videoAds.length != current.videoAds.length &&
101- current.lastDeletedLocalAd == null ) ||
95+ previous.lastPendingDeletionId != current.lastPendingDeletionId ||
96+ previous.snackbarLocalAdTitle != current.snackbarLocalAdTitle ||
10297 (previous.restoredLocalAd == null &&
10398 current.restoredLocalAd != null ),
10499 listener: (context, state) {
105- if (state.lastDeletedLocalAd != null ) {
106- String truncatedTitle;
107- switch (state.lastDeletedLocalAd! .adType) {
108- case 'native' :
109- truncatedTitle = (state.lastDeletedLocalAd! as LocalNativeAd )
110- .title
111- .truncate (30 );
112- case 'banner' :
113- truncatedTitle = (state.lastDeletedLocalAd! as LocalBannerAd )
114- .imageUrl
115- .truncate (30 );
116- case 'interstitial' :
117- truncatedTitle =
118- (state.lastDeletedLocalAd! as LocalInterstitialAd ).imageUrl
119- .truncate (30 );
120- case 'video' :
121- truncatedTitle = (state.lastDeletedLocalAd! as LocalVideoAd )
122- .videoUrl
123- .truncate (30 );
124- default :
125- truncatedTitle = state.lastDeletedLocalAd! .id.truncate (30 );
126- }
127-
100+ if (state.snackbarLocalAdTitle != null ) {
101+ final adId = state.lastPendingDeletionId! ;
102+ final truncatedTitle = state.snackbarLocalAdTitle! .truncate (30 );
128103 ScaffoldMessenger .of (context)
129104 ..hideCurrentSnackBar ()
130105 ..showSnackBar (
@@ -135,9 +110,7 @@ class _ArchivedLocalAdsViewState extends State<_ArchivedLocalAdsView>
135110 action: SnackBarAction (
136111 label: l10n.undo,
137112 onPressed: () {
138- context.read <ArchiveLocalAdsBloc >().add (
139- const UndoDeleteLocalAdRequested (),
140- );
113+ pendingDeletionsService.undoDeletion (adId);
141114 },
142115 ),
143116 ),
0 commit comments