mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: show member count on mobile (#4991)
* feat: show member count on mobile * fix: favorite section not sync after switching workspace * fix: favorite page will throw an error * fix: flutter analyze
This commit is contained in:
@ -27,8 +27,8 @@ class FavoriteBloc extends Bloc<FavoriteEvent, FavoriteState> {
|
||||
void _dispatch() {
|
||||
on<FavoriteEvent>(
|
||||
(event, emit) async {
|
||||
await event.map(
|
||||
initial: (e) async {
|
||||
await event.when(
|
||||
initial: () async {
|
||||
_listener.start(
|
||||
favoritesUpdated: _onFavoritesUpdated,
|
||||
);
|
||||
@ -44,23 +44,23 @@ class FavoriteBloc extends Bloc<FavoriteEvent, FavoriteState> {
|
||||
),
|
||||
);
|
||||
},
|
||||
didFavorite: (e) {
|
||||
fetchFavorites: () async {
|
||||
final result = await _service.readFavorites();
|
||||
emit(
|
||||
state.copyWith(views: [...state.views, ...e.favorite.items]),
|
||||
result.fold(
|
||||
(view) => state.copyWith(
|
||||
views: view.items,
|
||||
),
|
||||
(error) => state.copyWith(
|
||||
views: [],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
didUnfavorite: (e) {
|
||||
final views = [...state.views]..removeWhere(
|
||||
(view) => e.favorite.items.any((item) => item.id == view.id),
|
||||
);
|
||||
emit(
|
||||
state.copyWith(views: views),
|
||||
);
|
||||
},
|
||||
toggle: (e) async {
|
||||
toggle: (view) async {
|
||||
await _service.toggleFavorite(
|
||||
e.view.id,
|
||||
!e.view.isFavorite,
|
||||
view.id,
|
||||
!view.isFavorite,
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -73,9 +73,7 @@ class FavoriteBloc extends Bloc<FavoriteEvent, FavoriteState> {
|
||||
bool didFavorite,
|
||||
) {
|
||||
favoriteOrFailed.fold(
|
||||
(favorite) => didFavorite
|
||||
? add(FavoriteEvent.didFavorite(favorite))
|
||||
: add(FavoriteEvent.didUnfavorite(favorite)),
|
||||
(favorite) => add(const FetchFavorites()),
|
||||
(error) => Log.error(error),
|
||||
);
|
||||
}
|
||||
@ -84,11 +82,8 @@ class FavoriteBloc extends Bloc<FavoriteEvent, FavoriteState> {
|
||||
@freezed
|
||||
class FavoriteEvent with _$FavoriteEvent {
|
||||
const factory FavoriteEvent.initial() = Initial;
|
||||
const factory FavoriteEvent.didFavorite(RepeatedViewPB favorite) =
|
||||
DidFavorite;
|
||||
const factory FavoriteEvent.didUnfavorite(RepeatedViewPB favorite) =
|
||||
DidUnfavorite;
|
||||
const factory FavoriteEvent.toggle(ViewPB view) = ToggleFavorite;
|
||||
const factory FavoriteEvent.fetchFavorites() = FetchFavorites;
|
||||
}
|
||||
|
||||
@freezed
|
||||
|
@ -37,24 +37,25 @@ class FavoriteListener {
|
||||
FolderNotification ty,
|
||||
FlowyResult<Uint8List, FlowyError> result,
|
||||
) {
|
||||
if (_favoriteUpdated == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final isFavorite = ty == FolderNotification.DidFavoriteView;
|
||||
result.fold(
|
||||
(payload) {
|
||||
final view = RepeatedViewPB.fromBuffer(payload);
|
||||
_favoriteUpdated!(
|
||||
FlowyResult.success(view),
|
||||
isFavorite,
|
||||
switch (ty) {
|
||||
case FolderNotification.DidFavoriteView:
|
||||
result.onSuccess(
|
||||
(success) => _favoriteUpdated?.call(
|
||||
FlowyResult.success(RepeatedViewPB.fromBuffer(success)),
|
||||
true,
|
||||
),
|
||||
);
|
||||
},
|
||||
(error) => _favoriteUpdated!(
|
||||
FlowyResult.failure(error),
|
||||
isFavorite,
|
||||
),
|
||||
);
|
||||
case FolderNotification.DidUnfavoriteView:
|
||||
result.map(
|
||||
(success) => _favoriteUpdated?.call(
|
||||
FlowyResult.success(RepeatedViewPB.fromBuffer(success)),
|
||||
false,
|
||||
),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> stop() async {
|
||||
|
@ -363,7 +363,7 @@ class ViewEvent with _$ViewEvent {
|
||||
ViewLayoutPB layoutType, {
|
||||
/// open the view after created
|
||||
@Default(true) bool openAfterCreated,
|
||||
required ViewSectionPB section,
|
||||
ViewSectionPB? section,
|
||||
}) = CreateView;
|
||||
const factory ViewEvent.viewDidUpdate(
|
||||
FlowyResult<ViewPB, FlowyError> result,
|
||||
|
Reference in New Issue
Block a user