Skip to content

Commit

Permalink
fix(replies): refresh replies when selection date is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
mforesti authored and borgoat committed Nov 19, 2024
1 parent dfd8f69 commit 8c8f936
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/epics/groups.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ createGroupsEpics(GroupsRepository groups) => combineEpics<AppState>([
_createRetrieveOneGroupEpic(groups),
_createCreateOneGroupEpic(groups),
_createUpdateOneGroupEpic(groups),
_reloadGroupOnScheduleDateChange,
_loadGroupsOnSignInEpic,
_loadGroupsOnAppInitEpic,
_loadGroupsOnInviteCodeUseEpic,
Expand Down Expand Up @@ -50,6 +51,17 @@ Stream<dynamic> _loadGroupOnGroupDetailsOpenEpic(
.whereType<GroupDetailsOpenAction>()
.map((action) => RequestRetrieveOne<Group>(action.groupId));

/// Refresh the group details when the user changes the schedule date
Stream<dynamic> _reloadGroupOnScheduleDateChange(
Stream<dynamic> actions, EpicStore<AppState> store) =>
actions.whereType<SelectDateAction>().switchMap((_) async* {
final selectedGroupId = store.state.selectedGroupId;
if (selectedGroupId != null) {
yield GroupDetailsOpenAction(selectedGroupId);
}
yield null; // or handle the null case appropriately
}).where((action) => action != null);

/// Load all groups for the current user, together with their members and profiles.
/// If the action includes a Completer, complete, to handle the refresh indicator.
Epic<AppState> _createRetrieveAllGroupsEpic(GroupsRepository groups) {
Expand Down
2 changes: 2 additions & 0 deletions lib/reducers/root_reducer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'groups.dart';
import 'locale.dart';
import 'remote_entities.dart';
import 'selected_date.dart';
import 'selected_group_id.dart';
import 'theme.dart';

/// The root reducer combines all the reducers for the app into one.
Expand All @@ -28,5 +29,6 @@ AppState rootReducer(AppState state, dynamic action) {
themeMode: themeReducer(state.themeMode, action),
locale: localeReducer(state.locale, action),
selectedDate: selectedDateReducer(state.selectedDate, action),
selectedGroupId: selectedGroupIdReducer(state.selectedGroupId, action),
);
}
10 changes: 10 additions & 0 deletions lib/reducers/selected_group_id.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:parousia/actions/actions.dart';
import 'package:redux/redux.dart';

final selectedGroupIdReducer = combineReducers<String?>([
TypedReducer<String?, GroupDetailsOpenAction>(_changeGroup).call,
]);

String _changeGroup(String? currentGroupId, GroupDetailsOpenAction action) {
return action.groupId;
}
2 changes: 2 additions & 0 deletions lib/state/app_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'auth_state.dart';
import 'locale_state.dart';

part 'app_state.freezed.dart';

part 'app_state.g.dart';

@freezed
Expand All @@ -25,6 +26,7 @@ sealed class AppState with _$AppState {
@Default(AuthState(status: AuthStatus.initial)) AuthState auth,
@Default(ThemeMode.system) ThemeMode themeMode,
required DateTime selectedDate,
String? selectedGroupId,
LocaleState? locale,
}) = _AppState;

Expand Down
25 changes: 24 additions & 1 deletion lib/state/app_state.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mixin _$AppState {
AuthState get auth => throw _privateConstructorUsedError;
ThemeMode get themeMode => throw _privateConstructorUsedError;
DateTime get selectedDate => throw _privateConstructorUsedError;
String? get selectedGroupId => throw _privateConstructorUsedError;
LocaleState? get locale => throw _privateConstructorUsedError;

/// Serializes this AppState to a JSON map.
Expand Down Expand Up @@ -60,6 +61,7 @@ abstract class $AppStateCopyWith<$Res> {
AuthState auth,
ThemeMode themeMode,
DateTime selectedDate,
String? selectedGroupId,
LocaleState? locale});

$AuthStateCopyWith<$Res> get auth;
Expand Down Expand Up @@ -91,6 +93,7 @@ class _$AppStateCopyWithImpl<$Res, $Val extends AppState>
Object? auth = null,
Object? themeMode = null,
Object? selectedDate = null,
Object? selectedGroupId = freezed,
Object? locale = freezed,
}) {
return _then(_value.copyWith(
Expand Down Expand Up @@ -134,6 +137,10 @@ class _$AppStateCopyWithImpl<$Res, $Val extends AppState>
? _value.selectedDate
: selectedDate // ignore: cast_nullable_to_non_nullable
as DateTime,
selectedGroupId: freezed == selectedGroupId
? _value.selectedGroupId
: selectedGroupId // ignore: cast_nullable_to_non_nullable
as String?,
locale: freezed == locale
? _value.locale
: locale // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -185,6 +192,7 @@ abstract class _$$AppStateImplCopyWith<$Res>
AuthState auth,
ThemeMode themeMode,
DateTime selectedDate,
String? selectedGroupId,
LocaleState? locale});

@override
Expand Down Expand Up @@ -216,6 +224,7 @@ class __$$AppStateImplCopyWithImpl<$Res>
Object? auth = null,
Object? themeMode = null,
Object? selectedDate = null,
Object? selectedGroupId = freezed,
Object? locale = freezed,
}) {
return _then(_$AppStateImpl(
Expand Down Expand Up @@ -259,6 +268,10 @@ class __$$AppStateImplCopyWithImpl<$Res>
? _value.selectedDate
: selectedDate // ignore: cast_nullable_to_non_nullable
as DateTime,
selectedGroupId: freezed == selectedGroupId
? _value.selectedGroupId
: selectedGroupId // ignore: cast_nullable_to_non_nullable
as String?,
locale: freezed == locale
? _value.locale
: locale // ignore: cast_nullable_to_non_nullable
Expand All @@ -281,6 +294,7 @@ class _$AppStateImpl with DiagnosticableTreeMixin implements _AppState {
this.auth = const AuthState(status: AuthStatus.initial),
this.themeMode = ThemeMode.system,
required this.selectedDate,
this.selectedGroupId,
this.locale});

factory _$AppStateImpl.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -316,11 +330,13 @@ class _$AppStateImpl with DiagnosticableTreeMixin implements _AppState {
@override
final DateTime selectedDate;
@override
final String? selectedGroupId;
@override
final LocaleState? locale;

@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'AppState(profiles: $profiles, groups: $groups, members: $members, invites: $invites, schedules: $schedules, defaultReplies: $defaultReplies, replies: $replies, auth: $auth, themeMode: $themeMode, selectedDate: $selectedDate, locale: $locale)';
return 'AppState(profiles: $profiles, groups: $groups, members: $members, invites: $invites, schedules: $schedules, defaultReplies: $defaultReplies, replies: $replies, auth: $auth, themeMode: $themeMode, selectedDate: $selectedDate, selectedGroupId: $selectedGroupId, locale: $locale)';
}

@override
Expand All @@ -338,6 +354,7 @@ class _$AppStateImpl with DiagnosticableTreeMixin implements _AppState {
..add(DiagnosticsProperty('auth', auth))
..add(DiagnosticsProperty('themeMode', themeMode))
..add(DiagnosticsProperty('selectedDate', selectedDate))
..add(DiagnosticsProperty('selectedGroupId', selectedGroupId))
..add(DiagnosticsProperty('locale', locale));
}

Expand All @@ -361,6 +378,8 @@ class _$AppStateImpl with DiagnosticableTreeMixin implements _AppState {
other.themeMode == themeMode) &&
(identical(other.selectedDate, selectedDate) ||
other.selectedDate == selectedDate) &&
(identical(other.selectedGroupId, selectedGroupId) ||
other.selectedGroupId == selectedGroupId) &&
(identical(other.locale, locale) || other.locale == locale));
}

Expand All @@ -378,6 +397,7 @@ class _$AppStateImpl with DiagnosticableTreeMixin implements _AppState {
auth,
themeMode,
selectedDate,
selectedGroupId,
locale);

/// Create a copy of AppState
Expand Down Expand Up @@ -408,6 +428,7 @@ abstract class _AppState implements AppState {
final AuthState auth,
final ThemeMode themeMode,
required final DateTime selectedDate,
final String? selectedGroupId,
final LocaleState? locale}) = _$AppStateImpl;

factory _AppState.fromJson(Map<String, dynamic> json) =
Expand All @@ -434,6 +455,8 @@ abstract class _AppState implements AppState {
@override
DateTime get selectedDate;
@override
String? get selectedGroupId;
@override
LocaleState? get locale;

/// Create a copy of AppState
Expand Down
2 changes: 2 additions & 0 deletions lib/state/app_state.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c8f936

Please sign in to comment.