Skip to content

Commit d178b15

Browse files
committed
refactor(overview): rename DashboardBloc to OverviewBloc
- Renamed DashboardBloc to OverviewBloc for better alignment with the overall structure and naming conventions of the app. - Updated related files and references to reflect the new name. - Changed event and state classes to use the new Overview prefix. - Updated the data loading status enum to reflect the new bloc name.
1 parent 0eb9e93 commit d178b15

File tree

5 files changed

+44
-45
lines changed

5 files changed

+44
-45
lines changed

lib/app/view/app.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class App extends StatelessWidget {
118118
)..add(const SharedDataRequested()),
119119
),
120120
BlocProvider(
121-
create: (context) => DashboardBloc(
121+
create: (context) => OverviewBloc(
122122
dashboardSummaryRepository: context
123123
.read<DataRepository<DashboardSummary>>(),
124124
headlinesRepository: context.read<DataRepository<Headline>>(),

lib/overview/bloc/overview_bloc.dart

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ import 'package:stream_transform/stream_transform.dart';
99
part 'overview_event.dart';
1010
part 'overview_state.dart';
1111

12-
/// A BLoC to manage the state of the dashboard.
13-
class DashboardBloc extends Bloc<DashboardEvent, DashboardState> {
14-
/// {@macro dashboard_bloc}
15-
DashboardBloc({
12+
/// A BLoC to manage the state of the dashboard overview.
13+
class OverviewBloc extends Bloc<OverviewEvent, OverviewState> {
14+
/// {@macro overview_bloc}
15+
OverviewBloc({
1616
required DataRepository<DashboardSummary> dashboardSummaryRepository,
1717
required DataRepository<Headline> headlinesRepository,
1818
required DataRepository<Topic> topicsRepository,
1919
required DataRepository<Source> sourcesRepository,
2020
}) : _dashboardSummaryRepository = dashboardSummaryRepository,
2121
_headlinesRepository = headlinesRepository,
22-
super(const DashboardState()) {
23-
on<DashboardSummaryRequested>(_onDashboardSummaryRequested);
24-
on<_DashboardEntityUpdated>(_onDashboardEntityUpdated);
22+
super(const OverviewState()) {
23+
on<OverviewSummaryRequested>(_onOverviewSummaryRequested);
24+
on<_OverviewEntityUpdated>(__onOverviewEntityUpdated);
2525

2626
_entityUpdatedSubscription = headlinesRepository.entityUpdated
2727
.merge(topicsRepository.entityUpdated)
2828
.merge(sourcesRepository.entityUpdated)
29-
.listen((_) => add(const _DashboardEntityUpdated()));
29+
.listen((_) => add(const _OverviewEntityUpdated()));
3030
}
3131

3232
final DataRepository<DashboardSummary> _dashboardSummaryRepository;
@@ -39,18 +39,18 @@ class DashboardBloc extends Bloc<DashboardEvent, DashboardState> {
3939
return super.close();
4040
}
4141

42-
void _onDashboardEntityUpdated(
43-
_DashboardEntityUpdated event,
44-
Emitter<DashboardState> emit,
42+
void __onOverviewEntityUpdated(
43+
_OverviewEntityUpdated event,
44+
Emitter<OverviewState> emit,
4545
) {
46-
add(DashboardSummaryRequested());
46+
add(OverviewSummaryRequested());
4747
}
4848

49-
Future<void> _onDashboardSummaryRequested(
50-
DashboardSummaryRequested event,
51-
Emitter<DashboardState> emit,
49+
Future<void> _onOverviewSummaryRequested(
50+
OverviewSummaryRequested event,
51+
Emitter<OverviewState> emit,
5252
) async {
53-
emit(state.copyWith(status: DashboardStatus.loading));
53+
emit(state.copyWith(status: OverviewStatus.loading));
5454
try {
5555
// Fetch summary and recent headlines concurrently
5656
final [summaryResponse, recentHeadlinesResponse] = await Future.wait([
@@ -67,17 +67,17 @@ class DashboardBloc extends Bloc<DashboardEvent, DashboardState> {
6767
(recentHeadlinesResponse as PaginatedResponse<Headline>).items;
6868
emit(
6969
state.copyWith(
70-
status: DashboardStatus.success,
70+
status: OverviewStatus.success,
7171
summary: summary,
7272
recentHeadlines: recentHeadlines,
7373
),
7474
);
7575
} on HttpException catch (e) {
76-
emit(state.copyWith(status: DashboardStatus.failure, exception: e));
76+
emit(state.copyWith(status: OverviewStatus.failure, exception: e));
7777
} catch (e) {
7878
emit(
7979
state.copyWith(
80-
status: DashboardStatus.failure,
80+
status: OverviewStatus.failure,
8181
exception: UnknownException('An unknown error occurred: $e'),
8282
),
8383
);
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
part of 'overview_bloc.dart';
22

3-
/// Base class for dashboard events.
4-
sealed class DashboardEvent extends Equatable {
5-
const DashboardEvent();
3+
/// Base class for dashboard overviews events.
4+
sealed class OverviewEvent extends Equatable {
5+
const OverviewEvent();
66

77
@override
88
List<Object> get props => [];
99
}
1010

11-
/// Event to load the dashboard summary data.
12-
final class DashboardSummaryRequested extends DashboardEvent {}
11+
/// Event to load the dashboard overview summary data.
12+
final class OverviewSummaryRequested extends OverviewEvent {}
1313

1414
/// Internal event triggered when a listened-to entity is updated.
15-
final class _DashboardEntityUpdated extends DashboardEvent {
16-
const _DashboardEntityUpdated();
15+
final class _OverviewEntityUpdated extends OverviewEvent {
16+
const _OverviewEntityUpdated();
1717
}

lib/overview/bloc/overview_state.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
part of 'overview_bloc.dart';
22

3-
/// Represents the status of the dashboard data loading.
4-
enum DashboardStatus {
3+
/// Represents the status of the dashboard overview data loading.
4+
enum OverviewStatus {
55
/// Initial state.
66
initial,
77

@@ -15,27 +15,27 @@ enum DashboardStatus {
1515
failure,
1616
}
1717

18-
/// The state for the [DashboardBloc].
19-
final class DashboardState extends Equatable {
20-
const DashboardState({
21-
this.status = DashboardStatus.initial,
18+
/// The state for the [OverviewBloc].
19+
final class OverviewState extends Equatable {
20+
const OverviewState({
21+
this.status = OverviewStatus.initial,
2222
this.summary,
2323
this.recentHeadlines = const [],
2424
this.exception,
2525
});
2626

27-
final DashboardStatus status;
27+
final OverviewStatus status;
2828
final DashboardSummary? summary;
2929
final List<Headline> recentHeadlines;
3030
final HttpException? exception;
3131

32-
DashboardState copyWith({
33-
DashboardStatus? status,
32+
OverviewState copyWith({
33+
OverviewStatus? status,
3434
DashboardSummary? summary,
3535
List<Headline>? recentHeadlines,
3636
HttpException? exception,
3737
}) {
38-
return DashboardState(
38+
return OverviewState(
3939
status: status ?? this.status,
4040
summary: summary ?? this.summary,
4141
recentHeadlines: recentHeadlines ?? this.recentHeadlines,

lib/overview/view/overview_page.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,32 @@ class _OverviewPageState extends State<OverviewPage> {
2323
void initState() {
2424
super.initState();
2525
// Dispatch the event to load dashboard data when the page is initialized.
26-
context.read<DashboardBloc>().add(DashboardSummaryRequested());
26+
context.read<OverviewBloc>().add(OverviewSummaryRequested());
2727
}
2828

2929
@override
3030
Widget build(BuildContext context) {
3131
final l10n = AppLocalizationsX(context).l10n;
3232
return Scaffold(
33-
body: BlocBuilder<DashboardBloc, DashboardState>(
33+
body: BlocBuilder<OverviewBloc, OverviewState>(
3434
builder: (context, state) {
35-
if (state.status == DashboardStatus.loading ||
36-
state.status == DashboardStatus.initial) {
35+
if (state.status == OverviewStatus.loading ||
36+
state.status == OverviewStatus.initial) {
3737
return LoadingStateWidget(
3838
icon: Icons.dashboard_outlined,
3939
headline: l10n.loadingDashboard,
4040
subheadline: l10n.loadingDashboardSubheadline,
4141
);
4242
}
43-
if (state.status == DashboardStatus.failure) {
43+
if (state.status == OverviewStatus.failure) {
4444
return FailureStateWidget(
4545
exception: state.exception!,
4646
onRetry: () {
47-
context.read<DashboardBloc>().add(DashboardSummaryRequested());
47+
context.read<OverviewBloc>().add(OverviewSummaryRequested());
4848
},
4949
);
5050
}
51-
if (state.status == DashboardStatus.success &&
52-
state.summary != null) {
51+
if (state.status == OverviewStatus.success && state.summary != null) {
5352
final summary = state.summary!;
5453
final recentHeadlines = state.recentHeadlines;
5554
return ListView(

0 commit comments

Comments
 (0)