-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from DELTSV/profile-refactoring
Profile is not stored by a single bloc state anymore
- Loading branch information
Showing
18 changed files
with
419 additions
and
222 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/app/lib/profile/bloc/profile_bloc/events/profile_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
part of '../profile_bloc.dart'; | ||
|
||
@immutable | ||
abstract class ProfileEvent { | ||
const ProfileEvent(); | ||
} | ||
|
||
class SubscribeToCurrentSessionChange extends ProfileEvent {} | ||
|
||
extension ProfileEventOperations<T extends ProfileEvent> on List<T> { | ||
int? elementIndex(T profileEvent) { | ||
for (int i = 0; i < length; i++) { | ||
if (profileEvent == this[i]) return i; | ||
} | ||
return null; | ||
} | ||
|
||
copyUpdatedFromNullable(T? profileEvent) { | ||
final copy = [...this]; | ||
if (profileEvent == null) return copy; | ||
|
||
final alreadyExistingLoadEvent = elementIndex(profileEvent); | ||
if (alreadyExistingLoadEvent is int) { | ||
copy[alreadyExistingLoadEvent] = profileEvent; | ||
} else { | ||
copy.add(profileEvent); | ||
} | ||
|
||
return copy; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
packages/app/lib/profile/bloc/profile_bloc/events/profile_load_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
part of '../profile_bloc.dart'; | ||
|
||
abstract class ProfileLoadEvent extends ProfileEvent { | ||
final AuthSession session; | ||
|
||
const ProfileLoadEvent({required this.session}) : super(); | ||
|
||
@override | ||
bool operator ==(covariant ProfileLoadEvent other) { | ||
return session == other.session; | ||
} | ||
|
||
@override | ||
int get hashCode => Object.hash(session, super.hashCode); | ||
} | ||
|
||
class ProfileLoadingEvent extends ProfileLoadEvent { | ||
const ProfileLoadingEvent({required super.session}); | ||
|
||
ProfileLoadSuccessEvent succeeded(Profile profile) => | ||
ProfileLoadSuccessEvent(session: session, profile: profile); | ||
|
||
ProfileLoadErrorEvent failed(Error error) => | ||
ProfileLoadErrorEvent(session: session, error: error); | ||
} | ||
|
||
class ProfileLoadSuccessEvent extends ProfileLoadEvent { | ||
final Profile profile; | ||
|
||
const ProfileLoadSuccessEvent({ | ||
required super.session, | ||
required this.profile, | ||
}); | ||
} | ||
|
||
class ProfileLoadErrorEvent extends ProfileLoadEvent { | ||
final Error error; | ||
|
||
const ProfileLoadErrorEvent({ | ||
required super.session, | ||
required this.error, | ||
}); | ||
} | ||
|
||
extension ProfileLoadEventFactories on ProfileLoadEvent { | ||
static ProfileLoadingEvent loading({ | ||
required AuthSession session, | ||
}) => | ||
ProfileLoadingEvent(session: session); | ||
|
||
static ProfileLoadSuccessEvent success({ | ||
required AuthSession session, | ||
required Profile profile, | ||
}) => | ||
ProfileLoadSuccessEvent(session: session, profile: profile); | ||
|
||
static ProfileLoadErrorEvent error({ | ||
required AuthSession session, | ||
required Error error, | ||
}) => | ||
ProfileLoadErrorEvent(session: session, error: error); | ||
} | ||
|
83 changes: 83 additions & 0 deletions
83
packages/app/lib/profile/bloc/profile_bloc/events/user_load_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
part of '../profile_bloc.dart'; | ||
|
||
abstract class UserLoadEvent extends ProfileEvent { | ||
final AuthSession observerSession; | ||
final int id; | ||
|
||
const UserLoadEvent({required this.observerSession, required this.id}) | ||
: super(); | ||
|
||
@override | ||
bool operator ==(covariant UserLoadEvent other) { | ||
return observerSession == other.observerSession && id == other.id; | ||
} | ||
|
||
@override | ||
int get hashCode => Object.hash(observerSession, id.hashCode); | ||
} | ||
|
||
class UserLoadingEvent extends UserLoadEvent { | ||
const UserLoadingEvent({required super.observerSession, required super.id}); | ||
|
||
UserLoadSuccessEvent succeeded(MinimalUser user) => UserLoadSuccessEvent( | ||
observerSession: observerSession, | ||
id: id, | ||
user: user, | ||
); | ||
|
||
UserLoadErrorEvent failed(Error error) => UserLoadErrorEvent( | ||
observerSession: observerSession, | ||
id: id, | ||
error: error, | ||
); | ||
} | ||
|
||
class UserLoadSuccessEvent extends UserLoadEvent { | ||
final MinimalUser user; | ||
|
||
const UserLoadSuccessEvent({ | ||
required super.observerSession, | ||
required super.id, | ||
required this.user, | ||
}); | ||
} | ||
|
||
class UserLoadErrorEvent extends UserLoadEvent { | ||
final Error error; | ||
|
||
const UserLoadErrorEvent({ | ||
required super.observerSession, | ||
required super.id, | ||
required this.error, | ||
}); | ||
} | ||
|
||
extension UserLoadEventFactories on UserLoadEvent { | ||
static UserLoadingEvent loading({ | ||
required AuthSession observerSession, | ||
required int id, | ||
}) => | ||
UserLoadingEvent(observerSession: observerSession, id: id); | ||
|
||
static UserLoadSuccessEvent success({ | ||
required AuthSession observerSession, | ||
required int id, | ||
required MinimalUser user, | ||
}) => | ||
UserLoadSuccessEvent( | ||
observerSession: observerSession, | ||
id: id, | ||
user: user, | ||
); | ||
|
||
static UserLoadErrorEvent error({ | ||
required AuthSession observerSession, | ||
required int id, | ||
required Error error, | ||
}) => | ||
UserLoadErrorEvent( | ||
observerSession: observerSession, | ||
id: id, | ||
error: error, | ||
); | ||
} |
Oops, something went wrong.