Skip to content

Commit 7338f95

Browse files
committed
fix(archived-sources): restore source and update state with restored source
1 parent 9e2fb92 commit 7338f95

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

lib/content_management/bloc/archived_sources/archived_sources_bloc.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ class ArchivedSourcesBloc
7474
emit(state.copyWith(sources: updatedSources));
7575

7676
try {
77-
await _sourcesRepository.update(
77+
final restoredSource = await _sourcesRepository.update(
7878
id: event.id,
7979
item: sourceToRestore.copyWith(status: ContentStatus.active),
8080
);
81+
emit(state.copyWith(restoredSource: restoredSource));
8182
} on HttpException catch (e) {
8283
emit(state.copyWith(sources: originalSources, exception: e));
8384
} catch (e) {

lib/content_management/bloc/archived_sources/archived_sources_state.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,31 @@ class ArchivedSourcesState extends Equatable {
1616
this.cursor,
1717
this.hasMore = false,
1818
this.exception,
19+
this.restoredSource,
1920
});
2021

2122
final ArchivedSourcesStatus status;
2223
final List<Source> sources;
2324
final String? cursor;
2425
final bool hasMore;
2526
final HttpException? exception;
27+
final Source? restoredSource;
2628

2729
ArchivedSourcesState copyWith({
2830
ArchivedSourcesStatus? status,
2931
List<Source>? sources,
3032
String? cursor,
3133
bool? hasMore,
3234
HttpException? exception,
35+
Source? restoredSource,
3336
}) {
3437
return ArchivedSourcesState(
3538
status: status ?? this.status,
3639
sources: sources ?? this.sources,
3740
cursor: cursor ?? this.cursor,
3841
hasMore: hasMore ?? this.hasMore,
3942
exception: exception ?? this.exception,
43+
restoredSource: restoredSource,
4044
);
4145
}
4246

@@ -47,5 +51,6 @@ class ArchivedSourcesState extends Equatable {
4751
cursor,
4852
hasMore,
4953
exception,
54+
restoredSource,
5055
];
5156
}

lib/content_management/view/archived_sources_page.dart

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'package:data_table_2/data_table_2.dart';
44
import 'package:flutter/material.dart';
55
import 'package:flutter_bloc/flutter_bloc.dart';
66
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/archived_sources/archived_sources_bloc.dart';
7+
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/content_management_bloc.dart';
8+
import 'package:flutter_news_app_web_dashboard_full_source_code/dashboard/bloc/dashboard_bloc.dart';
79
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/app_localizations.dart';
810
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
911
import 'package:intl/intl.dart';
@@ -35,10 +37,21 @@ class _ArchivedSourcesView extends StatelessWidget {
3537
),
3638
body: Padding(
3739
padding: const EdgeInsets.all(AppSpacing.lg),
38-
child: BlocBuilder<ArchivedSourcesBloc, ArchivedSourcesState>(
39-
builder: (context, state) {
40-
if (state.status == ArchivedSourcesStatus.loading &&
41-
state.sources.isEmpty) {
40+
child: BlocListener<ArchivedSourcesBloc, ArchivedSourcesState>(
41+
listenWhen: (previous, current) =>
42+
previous.restoredSource != current.restoredSource,
43+
listener: (context, state) {
44+
if (state.restoredSource != null) {
45+
context.read<ContentManagementBloc>().add(
46+
const LoadSourcesRequested(limit: kDefaultRowsPerPage),
47+
);
48+
context.read<DashboardBloc>().add(DashboardSummaryLoaded());
49+
}
50+
},
51+
child: BlocBuilder<ArchivedSourcesBloc, ArchivedSourcesState>(
52+
builder: (context, state) {
53+
if (state.status == ArchivedSourcesStatus.loading &&
54+
state.sources.isEmpty) {
4255
return LoadingStateWidget(
4356
icon: Icons.source,
4457
headline: l10n.loadingArchivedSources,
@@ -116,7 +129,8 @@ class _ArchivedSourcesView extends StatelessWidget {
116129
),
117130
],
118131
);
119-
},
132+
},
133+
),
120134
),
121135
),
122136
);

0 commit comments

Comments
 (0)