feat: Added iced-ui and updated typegen for docs
This commit is contained in:
@@ -1,53 +1,33 @@
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
type SharedString = Arc<str>;
|
||||
|
||||
use iced::{Element, Task};
|
||||
|
||||
struct State {
|
||||
screen: Screen,
|
||||
loading: Option<Loading>,
|
||||
current: Screen,
|
||||
cache: ItemCache,
|
||||
}
|
||||
|
||||
enum Screen {
|
||||
Contacts(Contacts),
|
||||
Conversation(Conversation),
|
||||
pub struct ItemCache {
|
||||
pub items: BTreeMap<uuid::Uuid, Item>,
|
||||
}
|
||||
|
||||
enum Message {
|
||||
Contacts(contacts::Message),
|
||||
Conversation(conversation::Message),
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Item {
|
||||
pub id: SharedString,
|
||||
pub name: SharedString,
|
||||
pub item_type: SharedString,
|
||||
pub media_type: SharedString,
|
||||
}
|
||||
|
||||
fn update(state: &mut State, message: Message) -> Task<Message> {
|
||||
match message {
|
||||
Message::Contacts(message) => {
|
||||
if let Screen::Contacts(contacts) = &mut state.screen {
|
||||
let action = contacts.update(message);
|
||||
|
||||
match action {
|
||||
contacts::Action::None => Task::none(),
|
||||
contacts::Action::Run(task) => task.map(Message::Contacts),
|
||||
contacts::Action::Chat(contact) => {
|
||||
let (conversation, task) = Conversation::new(contact);
|
||||
|
||||
state.screen = Screen::Conversation(conversation);
|
||||
|
||||
task.map(Message::Conversation)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
Message::Conversation(message) => {
|
||||
if let Screen::Conversation(conversation) = &mut state.screen {
|
||||
conversation.update(message).map(Message::Conversation)
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
}
|
||||
pub enum Screen {
|
||||
Home,
|
||||
Settings,
|
||||
Profile,
|
||||
}
|
||||
|
||||
fn view(state: &State) -> Element<Message> {
|
||||
match &state.screen {
|
||||
Screen::Contacts(contacts) => contacts.view().map(Message::Contacts),
|
||||
Screen::Conversation(conversation) => conversation.view().map(Message::Conversation),
|
||||
}
|
||||
pub struct Loading {
|
||||
to: Screen,
|
||||
from: Screen,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user