skeleton code for fetching channel data
Ready for open_channel to be implemented
This commit is contained in:
parent
c32afc6dab
commit
9b4909963d
@ -1,8 +1,9 @@
|
||||
use cursive::Cursive;
|
||||
use reqwest;
|
||||
use crate::types::Channel;
|
||||
|
||||
pub async fn fetch_channels(domain: &str) -> Option<Vec<Channel>>{
|
||||
if let Ok(resp) = reqwest::get(format!("{}/channels/list", domain)).await {
|
||||
if let Ok(resp) = reqwest::get(&format!("{}/channels/list", domain)).await {
|
||||
let bytes = resp.bytes().await.unwrap();
|
||||
let res: Result<Vec<Channel>, serde_json::Error> = serde_json::from_slice(&bytes);
|
||||
return match res {
|
||||
@ -12,3 +13,13 @@ pub async fn fetch_channels(domain: &str) -> Option<Vec<Channel>>{
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
pub mod sync {
|
||||
use cursive::Cursive;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
pub fn open_channel(ip: Ipv4Addr, name: &str, s: &mut Cursive) {
|
||||
}
|
||||
|
||||
}
|
@ -10,7 +10,8 @@ use std::path::PathBuf;
|
||||
|
||||
use clap::{Arg, App};
|
||||
use cursive::Cursive;
|
||||
use cursive::views::Dialog;
|
||||
use cursive::views::{Dialog, TextView};
|
||||
use cursive::menu::MenuTree;
|
||||
use cursive::event::Key;
|
||||
|
||||
use serde_json;
|
||||
@ -66,6 +67,7 @@ async fn main() {
|
||||
|
||||
app.add_global_callback('q', Cursive::quit);
|
||||
app.add_global_callback(Key::Esc, |s| s.select_menubar());
|
||||
app.set_autohide_menu(false); // don't hide the menubar all the time
|
||||
|
||||
|
||||
|
||||
@ -73,23 +75,24 @@ async fn main() {
|
||||
for server in config.servers.iter() {
|
||||
let name = match &server.name {
|
||||
Some(name) => name.to_string(),
|
||||
//None => String::from(&format!("{}", server.ip))
|
||||
None => String::from("None")
|
||||
};
|
||||
|
||||
match http::fetch_channels(&server.ip).await {
|
||||
Some(channels) => {
|
||||
// add the channels to the current sub tree
|
||||
app.menubar().add_subtree(&name, MenuTree::new()); // add server name
|
||||
// on action:
|
||||
// open up search able list of channels
|
||||
// choose from that list of channels which one you want to see
|
||||
|
||||
if let Some(channels) = http::fetch_channels(&server.ip).await {
|
||||
// add a bunch of actionable leafs to our sub tree
|
||||
for channel in channels {
|
||||
app.menubar().add_leaf(&name, move |appref| {
|
||||
let address = format!("{}", channel.ip);
|
||||
appref.add_layer(Dialog::info(address));
|
||||
app.menubar().find_subtree(name.as_ref()).unwrap().add_leaf(channel.name.clone(), move |s| {
|
||||
let (ip, name) = channel.parts();
|
||||
http::sync::open_channel(ip, name, s);
|
||||
});
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
app.menubar().add_leaf(name, |_| {/* */});
|
||||
}
|
||||
|
||||
app.run();
|
||||
|
Loading…
Reference in New Issue
Block a user