@@ -3,9 +3,11 @@ import 'dart:async';
3
3
import 'package:bloc/bloc.dart' ;
4
4
import 'package:bloc_concurrency/bloc_concurrency.dart' ;
5
5
import 'package:equatable/equatable.dart' ;
6
- import 'package:ht_categories_client/ht_categories_client.dart' ;
7
- import 'package:ht_categories_repository/ht_categories_repository.dart' ;
8
- // For PaginatedResponse
6
+ import 'package:ht_data_repository/ht_data_repository.dart' ; // Generic Data Repository
7
+ import 'package:ht_shared/ht_shared.dart'
8
+ show
9
+ Category,
10
+ HtHttpException; // Shared models, including Category and standardized exceptions
9
11
10
12
part 'categories_filter_event.dart' ;
11
13
part 'categories_filter_state.dart' ;
@@ -14,16 +16,17 @@ part 'categories_filter_state.dart';
14
16
/// Manages the state for fetching and displaying categories for filtering.
15
17
///
16
18
/// Handles initial fetching and pagination of categories using the
17
- /// provided [HtCategoriesRepository ] .
19
+ /// provided [HtDataRepository ] .
18
20
/// {@endtemplate}
19
21
class CategoriesFilterBloc
20
22
extends Bloc <CategoriesFilterEvent , CategoriesFilterState > {
21
23
/// {@macro categories_filter_bloc}
22
24
///
23
- /// Requires a [HtCategoriesRepository] to interact with the data layer.
24
- CategoriesFilterBloc ({required HtCategoriesRepository categoriesRepository})
25
- : _categoriesRepository = categoriesRepository,
26
- super (const CategoriesFilterState ()) {
25
+ /// Requires a [HtDataRepository<Category>] to interact with the data layer.
26
+ CategoriesFilterBloc ({
27
+ required HtDataRepository <Category > categoriesRepository,
28
+ }) : _categoriesRepository = categoriesRepository,
29
+ super (const CategoriesFilterState ()) {
27
30
on < CategoriesFilterRequested > (
28
31
_onCategoriesFilterRequested,
29
32
transformer: restartable (), // Only process the latest request
@@ -34,7 +37,7 @@ class CategoriesFilterBloc
34
37
);
35
38
}
36
39
37
- final HtCategoriesRepository _categoriesRepository;
40
+ final HtDataRepository < Category > _categoriesRepository;
38
41
39
42
/// Number of categories to fetch per page.
40
43
static const _categoriesLimit = 20 ;
@@ -54,7 +57,7 @@ class CategoriesFilterBloc
54
57
emit (state.copyWith (status: CategoriesFilterStatus .loading));
55
58
56
59
try {
57
- final response = await _categoriesRepository.getCategories (
60
+ final response = await _categoriesRepository.readAll (
58
61
limit: _categoriesLimit,
59
62
);
60
63
emit (
@@ -66,7 +69,7 @@ class CategoriesFilterBloc
66
69
clearError: true , // Clear any previous error
67
70
),
68
71
);
69
- } on GetCategoriesFailure catch (e) {
72
+ } on HtHttpException catch (e) {
70
73
emit (state.copyWith (status: CategoriesFilterStatus .failure, error: e));
71
74
} catch (e) {
72
75
// Catch unexpected errors
@@ -87,7 +90,7 @@ class CategoriesFilterBloc
87
90
emit (state.copyWith (status: CategoriesFilterStatus .loadingMore));
88
91
89
92
try {
90
- final response = await _categoriesRepository.getCategories (
93
+ final response = await _categoriesRepository.readAll (
91
94
limit: _categoriesLimit,
92
95
startAfterId: state.cursor, // Use the cursor from the current state
93
96
);
@@ -100,7 +103,7 @@ class CategoriesFilterBloc
100
103
cursor: response.cursor,
101
104
),
102
105
);
103
- } on GetCategoriesFailure catch (e) {
106
+ } on HtHttpException catch (e) {
104
107
// Keep existing data but indicate failure
105
108
emit (
106
109
state.copyWith (
0 commit comments