|
| 1 | +part of 'content_management_bloc.dart'; |
| 2 | + |
| 3 | + |
| 4 | +/// Represents the status of content loading and operations. |
| 5 | +enum ContentManagementStatus { |
| 6 | + /// The operation is in its initial state. |
| 7 | + initial, |
| 8 | + |
| 9 | + /// Data is currently being loaded or an operation is in progress. |
| 10 | + loading, |
| 11 | + |
| 12 | + /// Data has been successfully loaded or an operation completed. |
| 13 | + success, |
| 14 | + |
| 15 | + /// An error occurred during data loading or an operation. |
| 16 | + failure, |
| 17 | +} |
| 18 | + |
| 19 | +/// Defines the state for the content management feature. |
| 20 | +class ContentManagementState extends Equatable { |
| 21 | + /// {@macro content_management_state} |
| 22 | + const ContentManagementState({ |
| 23 | + this.activeTab = ContentManagementTab.headlines, |
| 24 | + this.headlinesStatus = ContentManagementStatus.initial, |
| 25 | + this.headlines = const [], |
| 26 | + this.headlinesCursor, |
| 27 | + this.headlinesHasMore = false, |
| 28 | + this.categoriesStatus = ContentManagementStatus.initial, |
| 29 | + this.categories = const [], |
| 30 | + this.categoriesCursor, |
| 31 | + this.categoriesHasMore = false, |
| 32 | + this.sourcesStatus = ContentManagementStatus.initial, |
| 33 | + this.sources = const [], |
| 34 | + this.sourcesCursor, |
| 35 | + this.sourcesHasMore = false, |
| 36 | + this.errorMessage, |
| 37 | + }); |
| 38 | + |
| 39 | + /// The currently active tab in the content management section. |
| 40 | + final ContentManagementTab activeTab; |
| 41 | + |
| 42 | + /// Status of headline data operations. |
| 43 | + final ContentManagementStatus headlinesStatus; |
| 44 | + |
| 45 | + /// List of headlines. |
| 46 | + final List<Headline> headlines; |
| 47 | + |
| 48 | + /// Cursor for headline pagination. |
| 49 | + final String? headlinesCursor; |
| 50 | + |
| 51 | + /// Indicates if there are more headlines to load. |
| 52 | + final bool headlinesHasMore; |
| 53 | + |
| 54 | + /// Status of category data operations. |
| 55 | + final ContentManagementStatus categoriesStatus; |
| 56 | + |
| 57 | + /// List of categories. |
| 58 | + final List<Category> categories; |
| 59 | + |
| 60 | + /// Cursor for category pagination. |
| 61 | + final String? categoriesCursor; |
| 62 | + |
| 63 | + /// Indicates if there are more categories to load. |
| 64 | + final bool categoriesHasMore; |
| 65 | + |
| 66 | + /// Status of source data operations. |
| 67 | + final ContentManagementStatus sourcesStatus; |
| 68 | + |
| 69 | + /// List of sources. |
| 70 | + final List<Source> sources; |
| 71 | + |
| 72 | + /// Cursor for source pagination. |
| 73 | + final String? sourcesCursor; |
| 74 | + |
| 75 | + /// Indicates if there are more sources to load. |
| 76 | + final bool sourcesHasMore; |
| 77 | + |
| 78 | + /// Error message if an operation fails. |
| 79 | + final String? errorMessage; |
| 80 | + |
| 81 | + /// Creates a copy of this [ContentManagementState] with updated values. |
| 82 | + ContentManagementState copyWith({ |
| 83 | + ContentManagementTab? activeTab, |
| 84 | + ContentManagementStatus? headlinesStatus, |
| 85 | + List<Headline>? headlines, |
| 86 | + String? headlinesCursor, |
| 87 | + bool? headlinesHasMore, |
| 88 | + ContentManagementStatus? categoriesStatus, |
| 89 | + List<Category>? categories, |
| 90 | + String? categoriesCursor, |
| 91 | + bool? categoriesHasMore, |
| 92 | + ContentManagementStatus? sourcesStatus, |
| 93 | + List<Source>? sources, |
| 94 | + String? sourcesCursor, |
| 95 | + bool? sourcesHasMore, |
| 96 | + String? errorMessage, |
| 97 | + }) { |
| 98 | + return ContentManagementState( |
| 99 | + activeTab: activeTab ?? this.activeTab, |
| 100 | + headlinesStatus: headlinesStatus ?? this.headlinesStatus, |
| 101 | + headlines: headlines ?? this.headlines, |
| 102 | + headlinesCursor: headlinesCursor ?? this.headlinesCursor, |
| 103 | + headlinesHasMore: headlinesHasMore ?? this.headlinesHasMore, |
| 104 | + categoriesStatus: categoriesStatus ?? this.categoriesStatus, |
| 105 | + categories: categories ?? this.categories, |
| 106 | + categoriesCursor: categoriesCursor ?? this.categoriesCursor, |
| 107 | + categoriesHasMore: categoriesHasMore ?? this.categoriesHasMore, |
| 108 | + sourcesStatus: sourcesStatus ?? this.sourcesStatus, |
| 109 | + sources: sources ?? this.sources, |
| 110 | + sourcesCursor: sourcesCursor ?? this.sourcesCursor, |
| 111 | + sourcesHasMore: sourcesHasMore ?? this.sourcesHasMore, |
| 112 | + errorMessage: errorMessage, |
| 113 | + ); |
| 114 | + } |
| 115 | + |
| 116 | + @override |
| 117 | + List<Object?> get props => [ |
| 118 | + activeTab, |
| 119 | + headlinesStatus, |
| 120 | + headlines, |
| 121 | + headlinesCursor, |
| 122 | + headlinesHasMore, |
| 123 | + categoriesStatus, |
| 124 | + categories, |
| 125 | + categoriesCursor, |
| 126 | + categoriesHasMore, |
| 127 | + sourcesStatus, |
| 128 | + sources, |
| 129 | + sourcesCursor, |
| 130 | + sourcesHasMore, |
| 131 | + errorMessage, |
| 132 | + ]; |
| 133 | +} |
0 commit comments