feat(meta): Implement removing tracking items
This commit is contained in:
@@ -24,6 +24,8 @@ class AnimeListBloc extends Bloc<AnimeListEvent, AnimeListState> {
|
||||
on<MangaChapterDecrementedEvent>(_onMangaDecremented);
|
||||
on<AnimeUpdatedEvent>(_onAnimeUpdated);
|
||||
on<MangaUpdatedEvent>(_onMangaUpdated);
|
||||
on<AnimeRemovedEvent>(_onAnimeRemoved);
|
||||
on<MangaRemovedEvent>(_onMangaRemoved);
|
||||
}
|
||||
|
||||
Future<void> _onAnimeAdded(AnimeAddedEvent event, Emitter<AnimeListState> emit) async {
|
||||
@@ -206,4 +208,30 @@ class AnimeListBloc extends Bloc<AnimeListEvent, AnimeListState> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onAnimeRemoved(AnimeRemovedEvent event, Emitter<AnimeListState> emit) async {
|
||||
emit(
|
||||
state.copyWith(
|
||||
animes: List.from(
|
||||
state.animes.where((anime) => anime.id != event.id),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Update the database
|
||||
await GetIt.I.get<DatabaseService>().deleteAnime(event.id);
|
||||
}
|
||||
|
||||
Future<void> _onMangaRemoved(MangaRemovedEvent event, Emitter<AnimeListState> emit) async {
|
||||
emit(
|
||||
state.copyWith(
|
||||
mangas: List.from(
|
||||
state.mangas.where((manga) => manga.id != event.id),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Update the database
|
||||
await GetIt.I.get<DatabaseService>().deleteManga(event.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,13 @@ class AnimeUpdatedEvent extends AnimeListEvent {
|
||||
final AnimeTrackingData anime;
|
||||
}
|
||||
|
||||
class AnimeRemovedEvent extends AnimeListEvent {
|
||||
AnimeRemovedEvent(this.id);
|
||||
|
||||
/// The ID of the anime to be removed from the list.
|
||||
final String id;
|
||||
}
|
||||
|
||||
class MangaAddedEvent extends AnimeListEvent {
|
||||
MangaAddedEvent(this.data);
|
||||
|
||||
@@ -82,3 +89,10 @@ class MangaUpdatedEvent extends AnimeListEvent {
|
||||
|
||||
final MangaTrackingData manga;
|
||||
}
|
||||
|
||||
class MangaRemovedEvent extends AnimeListEvent {
|
||||
MangaRemovedEvent(this.id);
|
||||
|
||||
/// The ID of the manga to be removed from the list.
|
||||
final String id;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ class DetailsBloc extends Bloc<DetailsEvent, DetailsState> {
|
||||
on<AnimeDetailsRequestedEvent>(_onAnimeRequested);
|
||||
on<MangaDetailsRequestedEvent>(_onMangaRequested);
|
||||
on<DetailsUpdatedEvent>(_onDetailsUpdated);
|
||||
on<ItemRemovedEvent>(_onItemRemoved);
|
||||
}
|
||||
|
||||
Future<void> _onAnimeRequested(AnimeDetailsRequestedEvent event, Emitter<DetailsState> emit) async {
|
||||
@@ -77,4 +78,26 @@ class DetailsBloc extends Bloc<DetailsEvent, DetailsState> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onItemRemoved(ItemRemovedEvent event, Emitter<DetailsState> emit) async {
|
||||
emit(
|
||||
state.copyWith(
|
||||
data: null,
|
||||
),
|
||||
);
|
||||
|
||||
/// Remove the item from the database
|
||||
final bloc = GetIt.I.get<AnimeListBloc>();
|
||||
switch (event.trackingType) {
|
||||
case TrackingMediumType.anime:
|
||||
bloc.add(AnimeRemovedEvent(event.id));
|
||||
break;
|
||||
case TrackingMediumType.manga:
|
||||
bloc.add(MangaRemovedEvent(event.id));
|
||||
break;
|
||||
}
|
||||
|
||||
// Navigate back
|
||||
GetIt.I.get<NavigationBloc>().add(PoppedRouteEvent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,5 +19,15 @@ class MangaDetailsRequestedEvent extends DetailsEvent {
|
||||
class DetailsUpdatedEvent extends DetailsEvent {
|
||||
DetailsUpdatedEvent(this.data);
|
||||
|
||||
final dynamic data;
|
||||
final TrackingMedium data;
|
||||
}
|
||||
|
||||
class ItemRemovedEvent extends DetailsEvent {
|
||||
ItemRemovedEvent(this.id, this.trackingType);
|
||||
|
||||
/// The ID of the item to be removed
|
||||
final String id;
|
||||
|
||||
/// The type of medium of the item
|
||||
final TrackingMediumType trackingType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user