diff --git a/src/AppWindow.h b/src/AppWindow.h index da501ae..97b63af 100644 --- a/src/AppWindow.h +++ b/src/AppWindow.h @@ -141,6 +141,11 @@ public: addAnimeWindow->show(); }); + ui->global().on_remove_anime([&](int animeIndex) { + int currentListIndex = ui->global().get_current_list().index; + removeAnimeFromList(currentListIndex, animeIndex); + }); + addAnimeWindow->on_import_anilist_anime([&] (slint::SharedString animeIdStr) { int animeId = stoi(std::string(animeIdStr)); int currentListIndex = ui->global().get_current_list().index; @@ -280,6 +285,14 @@ public: save(); } + + void removeAnimeFromList(int currentListIndex, int animeIndex) { + rei::json::JsonArray& listJson = json.getArray("lists").getObject(currentListIndex).getArray("animes"); + listJson.remove(animeIndex); + selectList(currentListIndex); + save(); + } + slint::Image getAnimeImage(int animeId, std::string imageUrl) { //std::println("Get image for anime {}", animeId); std::string imagePath = imageDirectory + "/" + std::to_string(animeId); diff --git a/src/AppWindow.slint b/src/AppWindow.slint index 42dc918..8fc0c87 100644 --- a/src/AppWindow.slint +++ b/src/AppWindow.slint @@ -176,7 +176,7 @@ export component AppWindow inherits Window { icon-size: 1.5rem; border-radius: 0; clicked => { - // TODO : Missing feature to delete json value in rei-json + State.remove-anime(index) } } } diff --git a/src/state.slint b/src/state.slint index 92ae0a5..a9ece9a 100644 --- a/src/state.slint +++ b/src/state.slint @@ -44,6 +44,7 @@ export global State { callback add-local-list(AddLocalListParams); callback open-add-anime-window(); + callback remove-anime(int); callback config-changed(); }