Skip to content

Commit

Permalink
Generate API URLs on the client during compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanja-4732 committed Sep 7, 2023
1 parent 24c2789 commit 952b29c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
mod projector;
mod sound_button;
mod sounds;

use leptos::{ev::close, *};
use leptos_router::*;

use crate::app::sound_button::SoundButton;
use crate::app::sounds::Sounds;
use crate::app::{projector::Projector, sounds::Sounds};
use crate::core::{
get_sounds, get_sounds_strings, kill_mplayer, parse_sounds, Sound, HL_SOUNDS_STRING,
};
Expand Down Expand Up @@ -41,15 +42,14 @@ pub fn App(cx: Scope) -> impl IntoView {
</button>
</div>

// <Sounds />

<Router>
<main id="router-outlet">
<Routes>
// <Route path="/welcome" view=Welcome/>
// <Route path="/collaboration" view=Collaboration/>
// <Route path="/settings" view=Settings/>
<Route path="/sounds" view=Sounds/>
<Route path="/projector" view=Projector/>
<Route
path="/*any"
view=|cx| {
Expand Down
34 changes: 34 additions & 0 deletions src/app/projector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use leptos::*;
use leptos_router::*;

use crate::{
app::sound_button::SoundButton,
core::{get_sounds, Sound, HL_SOUNDS_STRING},
projector_commands,
};

#[component]
pub fn Projector(cx: Scope) -> impl IntoView {
log!("Projector");

log!("{}", projector_commands::power::on);

view! { cx,
<div class="
grid gap-2
grid-cols-2 sm:grid-cols-3 md:grid-cols-4
m-2 max-w-[1400px] min-[1416px]:mx-auto
">
// <For
// each=async_result
// key=|sound| sound.name.clone()
// view=move |cx, sound: Sound| {
// view! { cx,
// // <button>"Value: " {move || counter.count.get()}</button>
// <SoundButton sound/>
// }
// }
// />
</div>
}
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod app;
mod core;
mod license_notice;
mod projector_commands;
// mod components;

use leptos::*;
Expand Down
53 changes: 53 additions & 0 deletions src/projector_commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#![allow(non_upper_case_globals)]

const BASE_URL: &str = "http://licht.realraum.at:4201/api/v1/";

macro_rules! make_api_urls {
// Match the list of identifiers and the module name and assign them to $name and $module
($($name:ident),*; $module:ident) => {
// For each identifier in the list, expand to a constant declaration
$(pub const $name: &str = concat!("http://licht.realraum.at:4201/api/v1/", stringify!($module), "/", stringify!($name));)*
};
}

pub mod input {
// FIXME these may not work on all projectors

make_api_urls!(
vga_a,
vga_b,
composite,
s_video,
hdmi,
wireless,
usb_display,
usb_viewer;
input
);
}

pub mod volume {
make_api_urls!(up, down, mute, un_mute; volume);
}

pub mod power {
make_api_urls!(on, off; power);
}

pub mod menu {
make_api_urls!(menu_button, up, down, left, right, ok; menu);
}

pub mod picture {
make_api_urls!(
blank,
un_blank,
freeze,
un_freeze,
contrast_up,
contrast_down,
brightness_up,
brightness_down;
picture
);
}

0 comments on commit 952b29c

Please sign in to comment.