-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ssnover/flesh-out-control-page
Flesh out control page
- Loading branch information
Showing
38 changed files
with
1,102 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<html lang="en" style="margin: 0; height: 100%"> | ||
<head> | ||
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon"> | ||
<link data-trunk rel="css" href="vendor/bootstrap-5.3.3-dist/css/bootstrap.min.css"/> | ||
</head> | ||
<body> | ||
<body class="text-light bg-dark" style="margin: 0; height: 100%"> | ||
<script data-trunk src="vendor/bootstrap-5.3.3-dist/js/bootstrap.min.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use yew::{ | ||
function_component, hook, html, use_context, Children, ContextProvider, Html, Properties, | ||
}; | ||
|
||
const DEFAULT_WIDTH: u32 = 64; | ||
const DEFAULT_HEIGHT: u32 = 32; | ||
|
||
#[hook] | ||
pub fn use_app_config() -> AppConfig { | ||
use_context().unwrap() | ||
} | ||
|
||
#[derive(Clone, PartialEq)] | ||
pub struct AppConfig { | ||
display_width: u32, | ||
display_height: u32, | ||
} | ||
|
||
impl AppConfig { | ||
pub fn width(&self) -> u32 { | ||
self.display_width | ||
} | ||
|
||
pub fn height(&self) -> u32 { | ||
self.display_height | ||
} | ||
} | ||
|
||
#[function_component] | ||
pub fn AppConfigProvider(props: &AppConfigProviderProps) -> Html { | ||
let context = AppConfig { | ||
display_width: DEFAULT_WIDTH, | ||
display_height: DEFAULT_HEIGHT, | ||
}; | ||
|
||
html! { | ||
<ContextProvider<AppConfig> {context}>{props.children.clone()}</ContextProvider<AppConfig>> | ||
} | ||
} | ||
|
||
#[derive(Properties, PartialEq)] | ||
pub struct AppConfigProviderProps { | ||
pub children: Children, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
mod app_config_provider; | ||
mod msg_subscriber_provider; | ||
mod websocket_provider; | ||
pub use app_config_provider::{use_app_config, AppConfigProvider}; | ||
pub use msg_subscriber_provider::{use_subscription_manager, MsgSubscriberProvider}; | ||
pub use websocket_provider::{use_websocket, WebsocketProvider}; | ||
use yew::{function_component, html, Children, Html, Properties}; | ||
|
||
#[function_component(ConsoleProviders)] | ||
pub fn console_providers(props: &ConsoleProvidersProps) -> Html { | ||
html! { | ||
<MsgSubscriberProvider> | ||
<WebsocketProvider> | ||
<AppConfigProvider> | ||
{ props.children.clone() } | ||
</AppConfigProvider> | ||
</WebsocketProvider> | ||
</MsgSubscriberProvider> | ||
} | ||
} | ||
|
||
#[derive(PartialEq, Properties)] | ||
pub struct ConsoleProvidersProps { | ||
pub children: Children, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use megabit_runner_msgs::ConsoleMessage; | ||
use std::{cell::RefCell, collections::HashMap, rc::Rc}; | ||
use yew::{ | ||
function_component, hook, html, use_context, Callback, Children, ContextProvider, Html, | ||
Properties, | ||
}; | ||
|
||
#[hook] | ||
pub fn use_subscription_manager() -> SubscriptionManager { | ||
use_context().unwrap() | ||
} | ||
|
||
type SubscriptionKey = &'static str; | ||
type MsgCallback = Callback<ConsoleMessage>; | ||
type SubscriptionRegistry = HashMap<SubscriptionKey, Vec<(String, MsgCallback)>>; | ||
|
||
#[derive(Clone, PartialEq)] | ||
pub struct SubscriptionManager { | ||
registry: Rc<RefCell<SubscriptionRegistry>>, | ||
} | ||
|
||
impl SubscriptionManager { | ||
pub fn subscribe(&self, client: &str, message_kind: &'static str, callback: MsgCallback) { | ||
log::debug!("Adding subscription for kind {message_kind} for client {client}"); | ||
let mut registry = self.registry.borrow_mut(); | ||
match registry.get_mut(message_kind) { | ||
Some(subscriptions) => { | ||
if let Some((_, existing_cb)) = subscriptions | ||
.iter_mut() | ||
.find(|(sub_client, _)| client == sub_client.as_str()) | ||
{ | ||
*existing_cb = callback; | ||
} else { | ||
subscriptions.push((client.into(), callback)); | ||
} | ||
} | ||
None => { | ||
let _ = registry.insert(message_kind, vec![(client.to_string(), callback)]); | ||
} | ||
} | ||
} | ||
|
||
pub fn handle_message(&self, msg: ConsoleMessage) -> bool { | ||
log::debug!("Handling message: {}", msg.as_ref()); | ||
let registry = self.registry.borrow(); | ||
if let Some(subscriptions) = registry.get(msg.as_ref()) { | ||
for (_, cb) in subscriptions { | ||
cb.emit(msg.clone()); | ||
} | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
} | ||
|
||
#[function_component] | ||
pub fn MsgSubscriberProvider(props: &Props) -> Html { | ||
let context = SubscriptionManager { | ||
registry: Rc::new(RefCell::new(HashMap::new())), | ||
}; | ||
|
||
html! { | ||
<ContextProvider<SubscriptionManager> {context}>{props.children.clone()}</ContextProvider<SubscriptionManager>> | ||
} | ||
} | ||
|
||
#[derive(Properties, PartialEq)] | ||
pub struct Props { | ||
pub children: Children, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.