Replace Command with a new Task API with chain support

This commit is contained in:
Héctor Ramón Jiménez 2024-06-14 01:47:39 +02:00
parent e6d0b3bda5
commit a25b1af456
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
74 changed files with 1351 additions and 1767 deletions

View file

@ -1,6 +1,6 @@
use iced::futures;
use iced::widget::{self, center, column, image, row, text};
use iced::{Alignment, Command, Element, Length};
use iced::{Alignment, Element, Length, Task};
pub fn main() -> iced::Result {
iced::program(Pokedex::title, Pokedex::update, Pokedex::view)
@ -25,8 +25,8 @@ enum Message {
}
impl Pokedex {
fn search() -> Command<Message> {
Command::perform(Pokemon::search(), Message::PokemonFound)
fn search() -> Task<Message> {
Task::perform(Pokemon::search(), Message::PokemonFound)
}
fn title(&self) -> String {
@ -39,20 +39,20 @@ impl Pokedex {
format!("{subtitle} - Pokédex")
}
fn update(&mut self, message: Message) -> Command<Message> {
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::PokemonFound(Ok(pokemon)) => {
*self = Pokedex::Loaded { pokemon };
Command::none()
Task::none()
}
Message::PokemonFound(Err(_error)) => {
*self = Pokedex::Errored;
Command::none()
Task::none()
}
Message::Search => match self {
Pokedex::Loading => Command::none(),
Pokedex::Loading => Task::none(),
_ => {
*self = Pokedex::Loading;