Skip to content

Commit

Permalink
chore: add remaining pages
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed Jul 7, 2024
1 parent 46ff890 commit 0439524
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/ui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use std::collections::HashMap;

use crate::pages::clone;
use crate::{fl, pages};
use cosmic::app::{Command, Core};
use cosmic::iced::alignment::{Horizontal, Vertical};
Expand All @@ -19,6 +18,9 @@ pub struct Devmode {
context_page: ContextPage,
page: Page,
clone: pages::clone::ClonePage,
workspaces: pages::workspaces::WorkspacesPage,
open: pages::open::OpenPage,
config: pages::config::ConfigPage,
key_binds: HashMap<menu::KeyBind, MenuAction>,
nav: nav_bar::Model,
}
Expand All @@ -30,10 +32,14 @@ pub struct Devmode {
pub enum Message {
LaunchUrl(String),
ToggleContextPage(ContextPage),
Clone(clone::Message),
Clone(pages::clone::Message),
Workspaces(pages::workspaces::Message),
Open(pages::open::Message),
Config(pages::config::Message),
}

/// Identifies a page in the application.
#[derive(Debug, Clone, Copy)]
pub enum Page {
Clone,
Workspaces,
Expand Down Expand Up @@ -137,6 +143,9 @@ impl Application for Devmode {
context_page: ContextPage::default(),
page: Page::Clone,
clone: pages::clone::ClonePage::new(),
workspaces: pages::workspaces::WorkspacesPage::new(),
open: pages::open::OpenPage::new(),
config: pages::config::ConfigPage::new(),
key_binds: HashMap::new(),
nav,
};
Expand All @@ -162,9 +171,9 @@ impl Application for Devmode {

let page: Element<Self::Message> = match self.page {
Page::Clone => self.clone.view().map(Message::Clone),
Page::Workspaces => todo!(),
Page::Open => todo!(),
Page::Config => todo!(),
Page::Workspaces => self.workspaces.view().map(Message::Workspaces),
Page::Open => self.open.view().map(Message::Open),
Page::Config => self.config.view().map(Message::Config),
};

widget::container(page)
Expand All @@ -185,16 +194,18 @@ impl Application for Devmode {
Message::Clone(message) => {
for command in self.clone.update(message) {
match command {
clone::Command::Clone(_repository, _workspace) => {
pages::clone::Command::Clone(_repository, _workspace) => {
todo!("Implement cloning mechanism.")
}
}
}
}
Message::Workspaces(message) => for command in self.workspaces.update(message) {},
Message::Open(message) => for command in self.open.update(message) {},
Message::Config(message) => for command in self.config.update(message) {},
Message::LaunchUrl(url) => {
let _result = open::that_detached(url);
}

Message::ToggleContextPage(context_page) => {
if self.context_page == context_page {
// Close the context drawer if the toggled context page is the same.
Expand Down Expand Up @@ -228,6 +239,10 @@ impl Application for Devmode {
// Activate the page in the model.
self.nav.activate(id);

if let Some(page) = self.nav.active_data::<Page>() {
self.page = *page;
}

Command::none()
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/ui/src/pages.rs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pub mod clone;
pub mod config;
pub mod open;
pub mod workspaces;
40 changes: 40 additions & 0 deletions src/ui/src/pages/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use cosmic::{iced::Length, theme, widget, Apply, Element};

#[derive(Debug, Default)]
pub struct ConfigPage {}

#[derive(Debug, Clone)]
pub enum Message {}

pub enum Command {}

impl ConfigPage {
pub fn new() -> Self {
Self::default()
}

fn header(&self) -> Element<Message> {
widget::row::with_capacity(2)
.push(widget::text::title2("Config"))
.into()
}

pub fn view(&self) -> Element<Message> {
let spacing = theme::active().cosmic().spacing;

widget::column::with_capacity(2)
.push(self.header())
.spacing(spacing.space_xxs)
.apply(widget::container)
.height(Length::Shrink)
.apply(widget::scrollable)
.height(Length::Fill)
.into()
}

pub fn update(&self, message: Message) -> Vec<Command> {
let mut commands = vec![];
match message {}
commands
}
}
74 changes: 74 additions & 0 deletions src/ui/src/pages/open.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use cosmic::{
iced::{Alignment, Length},
theme, widget, Apply, Element,
};
use slotmap::{DefaultKey, SecondaryMap, SlotMap};

#[derive(Debug, Default)]
pub struct Repository {
url: String,
selected: bool,
}

#[derive(Debug, Default)]
pub struct OpenPage {
projects: Vec<String>,
}

#[derive(Debug, Clone)]
pub enum Message {
Select(String),
}

pub enum Command {}

impl OpenPage {
pub fn new() -> Self {
Self::default()
}

fn header(&self) -> Element<Message> {
widget::row::with_capacity(2)
.push(widget::text::title2("Open"))
.into()
}

pub fn view(&self) -> Element<Message> {
let spacing = theme::active().cosmic().spacing;

let mut items = widget::list::list_column()
.style(theme::Container::ContextDrawer)
.spacing(spacing.space_xxxs)
.padding([spacing.space_none, spacing.space_xxs]);

for item in &self.projects {
let item_text = widget::text(item).width(Length::Fill);

let row = widget::row::with_capacity(4)
.align_items(Alignment::Center)
.spacing(spacing.space_xxs)
.padding([spacing.space_xxxs, spacing.space_xxs])
.push(item_text);

items = items.add(row);
}

widget::column::with_capacity(2)
.push(self.header())
.push(items)
.spacing(spacing.space_xxs)
.apply(widget::container)
.height(Length::Shrink)
.apply(widget::scrollable)
.height(Length::Fill)
.into()
}

pub fn update(&self, message: Message) -> Vec<Command> {
let mut commands = vec![];
match message {
Message::Select(_) => todo!(),
}
commands
}
}
89 changes: 89 additions & 0 deletions src/ui/src/pages/workspaces.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use cosmic::{
iced::{Alignment, Length},
theme, widget, Apply, Element,
};
use slotmap::{DefaultKey, SecondaryMap, SlotMap};

#[derive(Debug, Default)]
pub struct WorkspacesPage {
workspaces: SlotMap<DefaultKey, String>,
editing: SecondaryMap<DefaultKey, bool>,
workspace_input_ids: SecondaryMap<DefaultKey, widget::Id>,
}

#[derive(Debug, Clone)]
pub enum Message {
EditMode(DefaultKey, bool),
TitleUpdate(DefaultKey, String),
TitleSubmit(DefaultKey),
}

pub enum Command {}

impl WorkspacesPage {
pub fn new() -> Self {
let mut workspaces = SlotMap::new();
let mut workspace_input_ids = SecondaryMap::new();
let id = workspaces.insert("tasks".into());
workspace_input_ids.insert(id, widget::Id::unique());
Self {
workspaces,
workspace_input_ids,
..Default::default()
}
}

fn header(&self) -> Element<Message> {
widget::row::with_capacity(2)
.push(widget::text::title2("Workspaces"))
.into()
}

pub fn view(&self) -> Element<Message> {
let spacing = theme::active().cosmic().spacing;

let mut items = widget::list::list_column()
.style(theme::Container::ContextDrawer)
.spacing(spacing.space_xxxs)
.padding([spacing.space_none, spacing.space_xxs]);

for (id, item) in &self.workspaces {
let item_text = widget::editable_input(
"",
item,
*self.editing.get(id).unwrap_or(&false),
move |editing| Message::EditMode(id, editing),
)
.id(self.workspace_input_ids[id].clone())
.on_submit(Message::TitleSubmit(id))
.on_input(move |text| Message::TitleUpdate(id, text))
.width(Length::Fill);

let row = widget::row::with_capacity(4)
.align_items(Alignment::Center)
.spacing(spacing.space_xxs)
.padding([spacing.space_xxxs, spacing.space_xxs])
.push(item_text);

items = items.add(row);
}

widget::column::with_capacity(2)
.push(self.header())
.push(items)
.spacing(spacing.space_xxs)
.apply(widget::container)
.height(Length::Shrink)
.apply(widget::scrollable)
.height(Length::Fill)
.into()
}

pub fn update(&self, message: Message) -> Vec<Command> {
match message {
Message::TitleSubmit(_) => todo!(),
Message::TitleUpdate(_, _) => todo!(),
Message::EditMode(_, _) => todo!(),
}
}
}

0 comments on commit 0439524

Please sign in to comment.