Add button to delete an anime from a list

This commit is contained in:
Vyn 2024-11-22 18:11:58 +01:00
parent 4c6942552d
commit fa5fb4edad
3 changed files with 15 additions and 1 deletions

View file

@ -141,6 +141,11 @@ public:
addAnimeWindow->show(); addAnimeWindow->show();
}); });
ui->global<ui::State>().on_remove_anime([&](int animeIndex) {
int currentListIndex = ui->global<ui::State>().get_current_list().index;
removeAnimeFromList(currentListIndex, animeIndex);
});
addAnimeWindow->on_import_anilist_anime([&] (slint::SharedString animeIdStr) { addAnimeWindow->on_import_anilist_anime([&] (slint::SharedString animeIdStr) {
int animeId = stoi(std::string(animeIdStr)); int animeId = stoi(std::string(animeIdStr));
int currentListIndex = ui->global<ui::State>().get_current_list().index; int currentListIndex = ui->global<ui::State>().get_current_list().index;
@ -280,6 +285,14 @@ public:
save(); 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) { slint::Image getAnimeImage(int animeId, std::string imageUrl) {
//std::println("Get image for anime {}", animeId); //std::println("Get image for anime {}", animeId);
std::string imagePath = imageDirectory + "/" + std::to_string(animeId); std::string imagePath = imageDirectory + "/" + std::to_string(animeId);

View file

@ -176,7 +176,7 @@ export component AppWindow inherits Window {
icon-size: 1.5rem; icon-size: 1.5rem;
border-radius: 0; border-radius: 0;
clicked => { clicked => {
// TODO : Missing feature to delete json value in rei-json State.remove-anime(index)
} }
} }
} }

View file

@ -44,6 +44,7 @@ export global State {
callback add-local-list(AddLocalListParams); callback add-local-list(AddLocalListParams);
callback open-add-anime-window(); callback open-add-anime-window();
callback remove-anime(int);
callback config-changed(); callback config-changed();
} }