Skip to content

Refactor remove country from search and headline details page #30

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
Show file tree
Hide file tree
Changes from all commits
Commits
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
379 changes: 195 additions & 184 deletions lib/account/bloc/account_bloc.dart

Large diffs are not rendered by default.

74 changes: 20 additions & 54 deletions lib/account/bloc/account_event.dart
Original file line number Diff line number Diff line change
@@ -1,92 +1,58 @@
part of 'account_bloc.dart';

/// {@template account_event}
/// Base class for Account events.
/// {@endtemplate}
sealed class AccountEvent extends Equatable {
/// {@macro account_event}
abstract class AccountEvent extends Equatable {
const AccountEvent();

@override
List<Object?> get props => [];
}

/// {@template _account_user_changed}
/// Internal event triggered when the authenticated user changes.
/// {@endtemplate}
final class _AccountUserChanged extends AccountEvent {
/// {@macro _account_user_changed}
const _AccountUserChanged({required this.user});

/// The current authenticated user, or null if unauthenticated.
class AccountUserChanged extends AccountEvent { // Corrected name
const AccountUserChanged(this.user);
final User? user;

@override
List<Object?> get props => [user];
}

/// {@template account_load_content_preferences_requested}
/// Event triggered when the user's content preferences need to be loaded.
/// {@endtemplate}
final class AccountLoadContentPreferencesRequested extends AccountEvent {
/// {@macro account_load_content_preferences_requested}
const AccountLoadContentPreferencesRequested({required this.userId});

/// The ID of the user whose content preferences should be loaded.
class AccountLoadUserPreferences extends AccountEvent { // Corrected name
const AccountLoadUserPreferences({required this.userId});
final String userId;

@override
List<Object> get props => [userId];
}

/// {@template account_follow_category_toggled}
/// Event triggered when a user toggles following a category.
/// {@endtemplate}
final class AccountFollowCategoryToggled extends AccountEvent {
/// {@macro account_follow_category_toggled}
const AccountFollowCategoryToggled({required this.category});
class AccountSaveHeadlineToggled extends AccountEvent {
const AccountSaveHeadlineToggled({required this.headline});
final Headline headline;

@override
List<Object> get props => [headline];
}

class AccountFollowCategoryToggled extends AccountEvent {
const AccountFollowCategoryToggled({required this.category});
final Category category;

@override
List<Object> get props => [category];
}

/// {@template account_follow_source_toggled}
/// Event triggered when a user toggles following a source.
/// {@endtemplate}
final class AccountFollowSourceToggled extends AccountEvent {
/// {@macro account_follow_source_toggled}
class AccountFollowSourceToggled extends AccountEvent {
const AccountFollowSourceToggled({required this.source});

final Source source;

@override
List<Object> get props => [source];
}

/// {@template account_follow_country_toggled}
/// Event triggered when a user toggles following a country.
/// {@endtemplate}
final class AccountFollowCountryToggled extends AccountEvent {
/// {@macro account_follow_country_toggled}
const AccountFollowCountryToggled({required this.country});
// AccountFollowCountryToggled event correctly removed previously

final Country country;

@override
List<Object> get props => [country];
}

/// {@template account_save_headline_toggled}
/// Event triggered when a user toggles saving a headline.
/// {@endtemplate}
final class AccountSaveHeadlineToggled extends AccountEvent {
/// {@macro account_save_headline_toggled}
const AccountSaveHeadlineToggled({required this.headline});

final Headline headline;
class AccountClearUserPreferences extends AccountEvent {
const AccountClearUserPreferences({required this.userId});
final String userId;

@override
List<Object> get props => [headline];
List<Object> get props => [userId];
}
40 changes: 10 additions & 30 deletions lib/account/bloc/account_state.dart
Original file line number Diff line number Diff line change
@@ -1,56 +1,36 @@
part of 'account_bloc.dart';

/// Defines the status of the account state.
enum AccountStatus {
/// The initial state.
initial,
enum AccountStatus { initial, loading, success, failure }

/// An operation is in progress.
loading,

/// An operation was successful.
success,

/// An operation failed.
failure,
}

/// {@template account_state}
/// State for the Account feature.
/// {@endtemplate}
final class AccountState extends Equatable {
/// {@macro account_state}
class AccountState extends Equatable {
const AccountState({
this.status = AccountStatus.initial,
this.user,
this.preferences,
this.errorMessage,
});

/// The current status of the account state.
final AccountStatus status;

/// The currently authenticated user.
final User? user;

/// The user's content preferences.
final UserContentPreferences? preferences;

/// An error message if an operation failed.
final String? errorMessage;

/// Creates a copy of this [AccountState] with the given fields replaced.
AccountState copyWith({
AccountStatus? status,
User? user,
UserContentPreferences? preferences,
String? errorMessage,
bool clearUser = false,
bool clearPreferences = false,
bool clearErrorMessage = false,
}) {
return AccountState(
status: status ?? this.status,
user: user ?? this.user,
preferences: preferences ?? this.preferences,
errorMessage: errorMessage ?? this.errorMessage,
user: clearUser ? null : user ?? this.user,
preferences:
clearPreferences ? null : preferences ?? this.preferences,
errorMessage:
clearErrorMessage ? null : errorMessage ?? this.errorMessage,
);
}

Expand Down
56 changes: 0 additions & 56 deletions lib/account/bloc/available_countries_bloc.dart

This file was deleted.

12 changes: 0 additions & 12 deletions lib/account/bloc/available_countries_event.dart

This file was deleted.

47 changes: 0 additions & 47 deletions lib/account/bloc/available_countries_state.dart

This file was deleted.

Loading
Loading