Skip to content

Fix content management archive #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ class ArchivedHeadlinesBloc
emit(state.copyWith(headlines: updatedHeadlines));

try {
await _headlinesRepository.update(
final restoredHeadline = await _headlinesRepository.update(
id: event.id,
item: headlineToRestore.copyWith(status: ContentStatus.active),
);
emit(state.copyWith(restoredHeadline: restoredHeadline));
} on HttpException catch (e) {
emit(state.copyWith(headlines: originalHeadlines, exception: e));
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@ class ArchivedHeadlinesState extends Equatable {
this.cursor,
this.hasMore = false,
this.exception,
this.restoredHeadline,
});

final ArchivedHeadlinesStatus status;
final List<Headline> headlines;
final String? cursor;
final bool hasMore;
final HttpException? exception;
final Headline? restoredHeadline;

ArchivedHeadlinesState copyWith({
ArchivedHeadlinesStatus? status,
List<Headline>? headlines,
String? cursor,
bool? hasMore,
HttpException? exception,
Headline? restoredHeadline,
}) {
return ArchivedHeadlinesState(
status: status ?? this.status,
headlines: headlines ?? this.headlines,
cursor: cursor ?? this.cursor,
hasMore: hasMore ?? this.hasMore,
exception: exception ?? this.exception,
restoredHeadline: restoredHeadline,
);
}

Expand All @@ -47,5 +51,6 @@ class ArchivedHeadlinesState extends Equatable {
cursor,
hasMore,
exception,
restoredHeadline,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ class ArchivedSourcesBloc
emit(state.copyWith(sources: updatedSources));

try {
await _sourcesRepository.update(
final restoredSource = await _sourcesRepository.update(
id: event.id,
item: sourceToRestore.copyWith(status: ContentStatus.active),
);
emit(state.copyWith(restoredSource: restoredSource));
} on HttpException catch (e) {
emit(state.copyWith(sources: originalSources, exception: e));
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@ class ArchivedSourcesState extends Equatable {
this.cursor,
this.hasMore = false,
this.exception,
this.restoredSource,
});

final ArchivedSourcesStatus status;
final List<Source> sources;
final String? cursor;
final bool hasMore;
final HttpException? exception;
final Source? restoredSource;

ArchivedSourcesState copyWith({
ArchivedSourcesStatus? status,
List<Source>? sources,
String? cursor,
bool? hasMore,
HttpException? exception,
Source? restoredSource,
}) {
return ArchivedSourcesState(
status: status ?? this.status,
sources: sources ?? this.sources,
cursor: cursor ?? this.cursor,
hasMore: hasMore ?? this.hasMore,
exception: exception ?? this.exception,
restoredSource: restoredSource,
);
}

Expand All @@ -47,5 +51,6 @@ class ArchivedSourcesState extends Equatable {
cursor,
hasMore,
exception,
restoredSource,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ class ArchivedTopicsBloc
emit(state.copyWith(topics: updatedTopics));

try {
await _topicsRepository.update(
final restoredTopic = await _topicsRepository.update(
id: event.id,
item: topicToRestore.copyWith(status: ContentStatus.active),
);
emit(state.copyWith(restoredTopic: restoredTopic));
} on HttpException catch (e) {
emit(state.copyWith(topics: originalTopics, exception: e));
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@ class ArchivedTopicsState extends Equatable {
this.cursor,
this.hasMore = false,
this.exception,
this.restoredTopic,
});

final ArchivedTopicsStatus status;
final List<Topic> topics;
final String? cursor;
final bool hasMore;
final HttpException? exception;
final Topic? restoredTopic;

ArchivedTopicsState copyWith({
ArchivedTopicsStatus? status,
List<Topic>? topics,
String? cursor,
bool? hasMore,
HttpException? exception,
Topic? restoredTopic,
}) {
return ArchivedTopicsState(
status: status ?? this.status,
topics: topics ?? this.topics,
cursor: cursor ?? this.cursor,
hasMore: hasMore ?? this.hasMore,
exception: exception ?? this.exception,
restoredTopic: restoredTopic,
);
}

Expand All @@ -47,5 +51,6 @@ class ArchivedTopicsState extends Equatable {
cursor,
hasMore,
exception,
restoredTopic,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ class CreateHeadlineBloc
final [sourcesResponse, topicsResponse] = await Future.wait([
_sourcesRepository.readAll(
sort: [const SortOption('updatedAt', SortOrder.desc)],
filter: {'status': ContentStatus.active.name},
),
_topicsRepository.readAll(
sort: [const SortOption('updatedAt', SortOrder.desc)],
filter: {'status': ContentStatus.active.name},
),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
final responses = await Future.wait([
_countriesRepository.readAll(
sort: [const SortOption('name', SortOrder.asc)],
filter: {'status': ContentStatus.active.name},
),
_languagesRepository.readAll(
sort: [const SortOption('name', SortOrder.asc)],
filter: {'status': ContentStatus.active.name},
),
]);
final countriesPaginated = responses[0] as PaginatedResponse<Country>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ class EditHeadlineBloc extends Bloc<EditHeadlineEvent, EditHeadlineState> {
_headlinesRepository.read(id: _headlineId),
_sourcesRepository.readAll(
sort: [const SortOption('updatedAt', SortOrder.desc)],
filter: {'status': ContentStatus.active.name},
),
_topicsRepository.readAll(
sort: [const SortOption('updatedAt', SortOrder.desc)],
filter: {'status': ContentStatus.active.name},
),
]);

Expand Down
2 changes: 2 additions & 0 deletions lib/content_management/bloc/edit_source/edit_source_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
_sourcesRepository.read(id: _sourceId),
_countriesRepository.readAll(
sort: [const SortOption('name', SortOrder.asc)],
filter: {'status': ContentStatus.active.name},
),
_languagesRepository.readAll(
sort: [const SortOption('name', SortOrder.asc)],
filter: {'status': ContentStatus.active.name},
),
]);

Expand Down
34 changes: 24 additions & 10 deletions lib/content_management/view/archived_headlines_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:data_table_2/data_table_2.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/archived_headlines/archived_headlines_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/content_management_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/app_localizations.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
import 'package:intl/intl.dart';
Expand Down Expand Up @@ -35,16 +36,28 @@ class _ArchivedHeadlinesView extends StatelessWidget {
),
body: Padding(
padding: const EdgeInsets.all(AppSpacing.lg),
child: BlocBuilder<ArchivedHeadlinesBloc, ArchivedHeadlinesState>(
builder: (context, state) {
if (state.status == ArchivedHeadlinesStatus.loading &&
state.headlines.isEmpty) {
return LoadingStateWidget(
icon: Icons.newspaper,
headline: l10n.loadingArchivedHeadlines,
subheadline: l10n.pleaseWait,
);
child: BlocListener<ArchivedHeadlinesBloc, ArchivedHeadlinesState>(
listenWhen: (previous, current) =>
previous.status != current.status ||
previous.restoredHeadline != current.restoredHeadline,
listener: (context, state) {
if (state.status == ArchivedHeadlinesStatus.success &&
state.restoredHeadline != null) {
context.read<ContentManagementBloc>().add(
const LoadHeadlinesRequested(limit: kDefaultRowsPerPage),
);
}
},
child: BlocBuilder<ArchivedHeadlinesBloc, ArchivedHeadlinesState>(
builder: (context, state) {
if (state.status == ArchivedHeadlinesStatus.loading &&
state.headlines.isEmpty) {
return LoadingStateWidget(
icon: Icons.newspaper,
headline: l10n.loadingArchivedHeadlines,
subheadline: l10n.pleaseWait,
);
}

if (state.status == ArchivedHeadlinesStatus.failure) {
return FailureStateWidget(
Expand Down Expand Up @@ -120,7 +133,8 @@ class _ArchivedHeadlinesView extends StatelessWidget {
),
],
);
},
},
),
),
),
);
Expand Down
24 changes: 19 additions & 5 deletions lib/content_management/view/archived_sources_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:data_table_2/data_table_2.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/archived_sources/archived_sources_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/content_management_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/dashboard/bloc/dashboard_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/app_localizations.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
import 'package:intl/intl.dart';
Expand Down Expand Up @@ -35,10 +37,21 @@ class _ArchivedSourcesView extends StatelessWidget {
),
body: Padding(
padding: const EdgeInsets.all(AppSpacing.lg),
child: BlocBuilder<ArchivedSourcesBloc, ArchivedSourcesState>(
builder: (context, state) {
if (state.status == ArchivedSourcesStatus.loading &&
state.sources.isEmpty) {
child: BlocListener<ArchivedSourcesBloc, ArchivedSourcesState>(
listenWhen: (previous, current) =>
previous.restoredSource != current.restoredSource,
listener: (context, state) {
if (state.restoredSource != null) {
context.read<ContentManagementBloc>().add(
const LoadSourcesRequested(limit: kDefaultRowsPerPage),
);
context.read<DashboardBloc>().add(DashboardSummaryLoaded());
}
},
child: BlocBuilder<ArchivedSourcesBloc, ArchivedSourcesState>(
builder: (context, state) {
if (state.status == ArchivedSourcesStatus.loading &&
state.sources.isEmpty) {
return LoadingStateWidget(
icon: Icons.source,
headline: l10n.loadingArchivedSources,
Expand Down Expand Up @@ -116,7 +129,8 @@ class _ArchivedSourcesView extends StatelessWidget {
),
],
);
},
},
),
),
),
);
Expand Down
24 changes: 19 additions & 5 deletions lib/content_management/view/archived_topics_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:data_table_2/data_table_2.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/archived_topics/archived_topics_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/content_management_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/dashboard/bloc/dashboard_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/app_localizations.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
import 'package:intl/intl.dart';
Expand Down Expand Up @@ -35,10 +37,21 @@ class _ArchivedTopicsView extends StatelessWidget {
),
body: Padding(
padding: const EdgeInsets.all(AppSpacing.lg),
child: BlocBuilder<ArchivedTopicsBloc, ArchivedTopicsState>(
builder: (context, state) {
if (state.status == ArchivedTopicsStatus.loading &&
state.topics.isEmpty) {
child: BlocListener<ArchivedTopicsBloc, ArchivedTopicsState>(
listenWhen: (previous, current) =>
previous.restoredTopic != current.restoredTopic,
listener: (context, state) {
if (state.restoredTopic != null) {
context
.read<ContentManagementBloc>()
.add(const LoadTopicsRequested(limit: kDefaultRowsPerPage));
context.read<DashboardBloc>().add( DashboardSummaryLoaded());
}
},
child: BlocBuilder<ArchivedTopicsBloc, ArchivedTopicsState>(
builder: (context, state) {
if (state.status == ArchivedTopicsStatus.loading &&
state.topics.isEmpty) {
return LoadingStateWidget(
icon: Icons.topic,
headline: l10n.loadingArchivedTopics,
Expand Down Expand Up @@ -116,7 +129,8 @@ class _ArchivedTopicsView extends StatelessWidget {
),
],
);
},
},
),
),
),
);
Expand Down
2 changes: 2 additions & 0 deletions lib/content_management/view/create_headline_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/content_management_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/create_headline/create_headline_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/dashboard/bloc/dashboard_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/shared.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -88,6 +89,7 @@ class _CreateHeadlineViewState extends State<_CreateHeadlineView> {
// Refresh the list to show the new headline
const LoadHeadlinesRequested(limit: kDefaultRowsPerPage),
);
context.read<DashboardBloc>().add(DashboardSummaryLoaded());
context.pop();
}
if (state.status == CreateHeadlineStatus.failure) {
Expand Down
2 changes: 2 additions & 0 deletions lib/content_management/view/create_source_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/content_management_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/create_source/create_source_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/dashboard/bloc/dashboard_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/extensions/source_type_l10n.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/shared.dart';
Expand Down Expand Up @@ -88,6 +89,7 @@ class _CreateSourceViewState extends State<_CreateSourceView> {
// Refresh the list to show the new source
const LoadSourcesRequested(limit: kDefaultRowsPerPage),
);
context.read<DashboardBloc>().add(DashboardSummaryLoaded());
context.pop();
}
if (state.status == CreateSourceStatus.failure) {
Expand Down
2 changes: 2 additions & 0 deletions lib/content_management/view/create_topic_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/content_management_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/create_topic/create_topic_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/dashboard/bloc/dashboard_bloc.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/shared.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -85,6 +86,7 @@ class _CreateTopicViewState extends State<_CreateTopicView> {
// Refresh the list to show the new topic
const LoadTopicsRequested(limit: kDefaultRowsPerPage),
);
context.read<DashboardBloc>().add(DashboardSummaryLoaded());
context.pop();
}
if (state.status == CreateTopicStatus.failure) {
Expand Down
Loading
Loading