Add support for local lists
This commit is contained in:
parent
7861b5b5b1
commit
4fec086508
4 changed files with 36 additions and 2 deletions
|
@ -27,7 +27,7 @@ target_link_libraries(lali PRIVATE Slint::Slint)
|
||||||
slint_target_sources(
|
slint_target_sources(
|
||||||
lali ui/app-window.slint
|
lali ui/app-window.slint
|
||||||
NAMESPACE ui
|
NAMESPACE ui
|
||||||
LIBRARY_PATHS selenite=${CMAKE_CURRENT_SOURCE_DIR}/external/selenite/index.slint
|
LIBRARY_PATHS selenite=${CMAKE_CURRENT_SOURCE_DIR}/external/selenite/components/index.slint
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(external/rei-json)
|
add_subdirectory(external/rei-json)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include "app-window.h"
|
#include "app-window.h"
|
||||||
|
#include "rei-json/Array.h"
|
||||||
#include "rei-json/json.h"
|
#include "rei-json/json.h"
|
||||||
#include "slint_string.h"
|
#include "slint_string.h"
|
||||||
#include "slint.h"
|
#include "slint.h"
|
||||||
|
@ -131,6 +132,10 @@ public:
|
||||||
ui->global<ui::State>().on_add_anilist_list([&](ui::AddAnilistListParams params) {
|
ui->global<ui::State>().on_add_anilist_list([&](ui::AddAnilistListParams params) {
|
||||||
addAnilistList(std::string(params.name), std::string(params.anilist_user_name), std::string(params.anilist_list_name));
|
addAnilistList(std::string(params.name), std::string(params.anilist_user_name), std::string(params.anilist_list_name));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ui->global<ui::State>().on_add_local_list([&](ui::AddLocalListParams params) {
|
||||||
|
addLocalList(std::string(params.name));
|
||||||
|
});
|
||||||
|
|
||||||
ui->global<ui::State>().on_sync_list([&](slint::SharedString name) {
|
ui->global<ui::State>().on_sync_list([&](slint::SharedString name) {
|
||||||
//std::println("{}",res->body);
|
//std::println("{}",res->body);
|
||||||
|
@ -221,6 +226,7 @@ public:
|
||||||
}
|
}
|
||||||
listJson.set("name", listName);
|
listJson.set("name", listName);
|
||||||
listJson.set("source", "anilist");
|
listJson.set("source", "anilist");
|
||||||
|
listJson.set("type", "animes");
|
||||||
listJson.set("anilistUserName", anilistUserName);
|
listJson.set("anilistUserName", anilistUserName);
|
||||||
listJson.set("anilistListName", anilistListName);
|
listJson.set("anilistListName", anilistListName);
|
||||||
|
|
||||||
|
@ -240,6 +246,25 @@ public:
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addLocalList(const std::string& listName) {
|
||||||
|
|
||||||
|
rei::json::JsonObject saveJson{};
|
||||||
|
saveJson.set("version", 1);
|
||||||
|
|
||||||
|
rei::json::JsonObject listJson{};
|
||||||
|
listJson.set("name", listName);
|
||||||
|
listJson.set("source", "local");
|
||||||
|
listJson.set("type", "animes");
|
||||||
|
listJson.addArray("animes", rei::json::JsonArray{});
|
||||||
|
|
||||||
|
json.getArray("lists").pushObject(listJson);
|
||||||
|
listsSlint->push_back(ui::List{
|
||||||
|
.name = slint::SharedString(listName),
|
||||||
|
.selected = false
|
||||||
|
});
|
||||||
|
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 = "./imgs/" + std::to_string(animeId);
|
std::string imagePath = "./imgs/" + std::to_string(animeId);
|
||||||
|
|
|
@ -56,7 +56,7 @@ export component AppWindow inherits Window {
|
||||||
in-out property <string> anilist-list-name;
|
in-out property <string> anilist-list-name;
|
||||||
|
|
||||||
list-type := ComboBox {
|
list-type := ComboBox {
|
||||||
model: ["Anilist"];
|
model: ["Anilist", "Local"];
|
||||||
}
|
}
|
||||||
VTextInput {
|
VTextInput {
|
||||||
label: "List name";
|
label: "List name";
|
||||||
|
@ -79,6 +79,10 @@ export component AppWindow inherits Window {
|
||||||
anilist-user-name: parent.anilist-user-name,
|
anilist-user-name: parent.anilist-user-name,
|
||||||
anilist-list-name: parent.anilist-list-name
|
anilist-list-name: parent.anilist-list-name
|
||||||
});
|
});
|
||||||
|
} else if list-type.current-value == "Local" {
|
||||||
|
State.add-local-list({
|
||||||
|
name: parent.name,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
show-add-list-form = false;
|
show-add-list-form = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,10 @@ export struct AddAnilistListParams {
|
||||||
anilist-list-name: string
|
anilist-list-name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export struct AddLocalListParams {
|
||||||
|
name: string,
|
||||||
|
}
|
||||||
|
|
||||||
export global State {
|
export global State {
|
||||||
|
|
||||||
in-out property <[List]> lists;
|
in-out property <[List]> lists;
|
||||||
|
@ -30,6 +34,7 @@ export global State {
|
||||||
callback select-list(int);
|
callback select-list(int);
|
||||||
callback sync-list(string);
|
callback sync-list(string);
|
||||||
callback add-anilist-list(AddAnilistListParams);
|
callback add-anilist-list(AddAnilistListParams);
|
||||||
|
callback add-local-list(AddLocalListParams);
|
||||||
|
|
||||||
callback config-changed();
|
callback config-changed();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue