about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2022-10-30 15:47:47 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2022-10-30 16:12:40 +0100
commit57e36c148c00c339d7b1b3426b7ca651edfc8a1b (patch)
treef2c52861821c97a419757f8d48e22fb38577f0e7
parentFrontend: Move app-specific code to app.rs (diff)
downloadOSSE-57e36c148c00c339d7b1b3426b7ca651edfc8a1b.tar.gz
OSSE-57e36c148c00c339d7b1b3426b7ca651edfc8a1b.tar.bz2
OSSE-57e36c148c00c339d7b1b3426b7ca651edfc8a1b.zip
Frontend: Setup skeleton route support
We now have the / and /search/ route boilerplate. This will allow us to
switch to the /search/ route when searching.
-rw-r--r--Cargo.lock41
-rw-r--r--frontend/Cargo.toml1
-rw-r--r--frontend/index.html4
-rw-r--r--frontend/src/main.rs35
4 files changed, 78 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0d2c505..86291f5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -624,6 +624,7 @@ dependencies = [
  "wasm-bindgen-futures",
  "web-sys",
  "yew",
+ "yew-router",
 ]
 
 [[package]]
@@ -824,6 +825,7 @@ version = "0.2.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a8d5564e570a38b43d78bdc063374a0c3098c4f0d64005b12f9bbe87e869b6d7"
 dependencies = [
+ "futures-channel",
  "gloo-events",
  "js-sys",
  "wasm-bindgen",
@@ -897,6 +899,8 @@ version = "0.2.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9"
 dependencies = [
+ "futures-channel",
+ "futures-core",
  "js-sys",
  "wasm-bindgen",
 ]
@@ -1910,6 +1914,12 @@ dependencies = [
 ]
 
 [[package]]
+name = "route-recognizer"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "afab94fb28594581f62d981211a9a4d53cc8130bbcbbb89a0440d9b8e81a7746"
+
+[[package]]
 name = "rustc_version"
 version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2768,6 +2778,37 @@ dependencies = [
 ]
 
 [[package]]
+name = "yew-router"
+version = "0.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "155804f6f3aa309f596d5c3fa14486a94e7756f1edd7634569949e401d5099f2"
+dependencies = [
+ "gloo 0.4.2",
+ "gloo-utils",
+ "js-sys",
+ "route-recognizer",
+ "serde",
+ "serde-wasm-bindgen",
+ "serde_urlencoded",
+ "thiserror",
+ "wasm-bindgen",
+ "web-sys",
+ "yew",
+ "yew-router-macro",
+]
+
+[[package]]
+name = "yew-router-macro"
+version = "0.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "39049d193b52eaad4ffc80916bf08806d142c90b5edcebd527644de438a7e19a"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
 name = "zstd"
 version = "0.11.2+zstd.1.5.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/frontend/Cargo.toml b/frontend/Cargo.toml
index e348451..7cc9e0b 100644
--- a/frontend/Cargo.toml
+++ b/frontend/Cargo.toml
@@ -7,6 +7,7 @@ edition = "2021"
 
 [dependencies]
 yew = "0.19"
+yew-router = "0.16"
 gloo = "0.8.0"
 web-sys = "0.3.60"
 wasm-bindgen = "0.2.83"
diff --git a/frontend/index.html b/frontend/index.html
index 35e10c8..abf3b18 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -7,7 +7,7 @@
     <title>OSSE</title>
     <link data-trunk rel="copy-dir" href="css">
     <link data-trunk rel="copy-dir" href="js">
-    <link href="./css/bootstrap.min.css" rel="stylesheet">
+    <link href="/css/bootstrap.min.css" rel="stylesheet">
     <style>
         body,
         html {
@@ -17,7 +17,7 @@
 </head>
 
 <body>
-    <script src="./js/bootstrap.bundle.min.js"></script>
+    <script src="/js/bootstrap.bundle.min.js"></script>
 </body>
 
 </html>
\ No newline at end of file
diff --git a/frontend/src/main.rs b/frontend/src/main.rs
index fd19fb4..95b52e5 100644
--- a/frontend/src/main.rs
+++ b/frontend/src/main.rs
@@ -1,6 +1,39 @@
 mod app;
 
-use app::App;
+use yew::prelude::*;
+use yew_router::prelude::*;
+use app::OSSE;
+
+
+#[derive(Clone, Routable, PartialEq)]
+enum Route {
+    #[at("/")]
+    OSSEHome,
+    #[at("/search/:query")]
+    OSSESearch { query: String },
+}
+
+fn switch_routes(routes: &Route) -> Html {
+    match routes {
+        Route::OSSEHome => html! {
+            <OSSE api_endpoint={"http://127.0.0.1:4444"}/>
+        },
+        Route::OSSESearch { query } => html! {
+            <OSSE api_endpoint={"http://127.0.0.1:4444"}/>
+        },
+    }
+}
+
+#[function_component(App)]
+fn yew_app() -> Html {
+    html! {
+        <>
+            <BrowserRouter>
+                <Switch<Route> render={Switch::render(switch_routes)} />
+            </BrowserRouter>
+        </>
+    }
+}
 
 fn main() {
     yew::start_app::<App>();