Skip to content

Commit

Permalink
Removed unnecessary dereferences and applied formatting fixes
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Cretin <github@ia0.eu>
  • Loading branch information
chris-dietz and ia0 authored Jun 1, 2024
1 parent a0f7c26 commit f2f71f1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/runner-host/crates/web-client/src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn Board(Props { command_state, on_board_ready, on_event }: &Props) -> Html
board_config.iter().map(|component| match component {
Component::Button{id} => html!(<Button id={id} on_event={on_event} />),
Component::MonochromeLed{id} => html! {
<LED id={id} command_state={command_state.clone()}/>
<LED id={id} command_state={command_state.clone()} />
}
}).collect::<Html>()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub struct Props {

#[function_component]
pub fn Button(Props { id, on_event }: &Props) -> Html {
let id = *id;
let pressed = use_state(|| false);
let press = Callback::from({
let pressed = pressed.clone();
let on_event = on_event.clone();
let id = *id;
move |_| {
info!("Pressed button id: {id}");
pressed.set(true);
Expand All @@ -40,11 +40,10 @@ pub fn Button(Props { id, on_event }: &Props) -> Html {
let unpress = Callback::from({
let pressed = pressed.clone();
let on_event = on_event.clone();
let id = *id;
move |_| {
info!("Unpressed button id: {id}");
// Necessary because it may also be triggered when the mouse
// stops hovering over the button.
// Necessary because it may also be triggered when the mouse stops hovering over the
// button.
if *pressed {
pressed.set(false);
on_event.emit(Event::Button { component_id: id, state: ButtonState::Released });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub struct Props {

#[function_component]
pub fn LED(Props { id, command_state }: &Props) -> Html {
let id = *id;
let lit = use_state(|| false);
let command_state = command_state.clone();
use_effect_with(command_state, {
let lit = lit.clone();
let id = *id;
move |command_state| {
if let Some(Command::Set { component_id, state }) = &**command_state {
if *component_id == id {
Expand All @@ -47,7 +47,6 @@ pub fn LED(Props { id, command_state }: &Props) -> Html {
data="components/monochrome_led_on.svg"
style={if *lit { "" } else { "display: none;" }}
/>

<object
class="led"
type="image/svg+xml"
Expand Down
1 change: 1 addition & 0 deletions crates/runner-host/crates/web-client/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use log::{info, warn};
use web_common::{Command, Event};
use yew::prelude::*;
Expand Down

0 comments on commit f2f71f1

Please sign in to comment.