about summary refs log tree commit diff
path: root/corp
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-05-27T10·48+0300
committertazjin <tazjin@tvl.su>2023-05-27T11·40+0000
commitc7e7f6d682a3e45e41698f3f47ab9439b36145c3 (patch)
tree462c907668cafbcb94fc8176ef7da43d13b2227e /corp
parentf2ed94b9d725b5767024eec62fe0eec420cb6389 (diff)
feat(corp/rih): implement routing support for privacy policy r/6212
Mounts the privacy policy at `/privacy-policy`. Using yew_router
"properly" is difficult in components that don't make use of macros
and context magic, so I've opted to use the gloo history handling
directly to parse the location here.

Change-Id: Icde11485f9947bc860a7b2c43772bb0f4cdf2ea1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8653
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'corp')
-rw-r--r--corp/rih/src/main.rs29
1 files changed, 27 insertions, 2 deletions
diff --git a/corp/rih/src/main.rs b/corp/rih/src/main.rs
index 5cad294a8e02..7360a6979d76 100644
--- a/corp/rih/src/main.rs
+++ b/corp/rih/src/main.rs
@@ -1,6 +1,8 @@
 use fuzzy_matcher::skim::SkimMatcherV2;
 use fuzzy_matcher::FuzzyMatcher;
 use gloo::console;
+use gloo::history::BrowserHistory;
+use gloo::history::History;
 use gloo::storage::{LocalStorage, Storage};
 use rand::seq::IteratorRandom;
 use rand::thread_rng;
@@ -12,6 +14,7 @@ use wasm_bindgen::JsCast;
 use web_sys::{HtmlInputElement, HtmlTextAreaElement, KeyboardEvent};
 use yew::html::Scope;
 use yew::prelude::*;
+use yew_router::prelude::*;
 
 /// This code ends up being compiled for the native and for the
 /// webassembly architectures during the build & test process.
@@ -59,6 +62,17 @@ impl CountryCodeAccess for rust_iso3166::CountryCode {
 
 const VISTA_URL: &'static str = "https://vista-immigration.ru/";
 
+#[derive(Debug, Clone, Copy, PartialEq, Routable)]
+enum Route {
+    #[at("/")]
+    Home,
+    #[at("/privacy-policy")]
+    PrivacyPolicy,
+    #[not_found]
+    #[at("/404")]
+    NotFound,
+}
+
 /// Represents a single record as filled in by a user. This is the
 /// primary data structure we want to populate and persist somewhere.
 #[derive(Default, Debug, Deserialize, Serialize)]
@@ -86,6 +100,9 @@ struct App {
 
     // Current query in the citizenship field.
     citizenship_query: String,
+
+    // History handler.
+    history: BrowserHistory,
 }
 
 #[derive(Clone, Debug)]
@@ -360,8 +377,16 @@ impl Component for App {
 
     fn view(&self, ctx: &Context<Self>) -> Html {
         let link = ctx.link();
-
-        include!("home.html")
+        let location = self.history.location();
+        let route = Route::recognize(location.path()).unwrap_or(Route::NotFound);
+
+        match route {
+            Route::Home => include!("home.html"),
+            Route::PrivacyPolicy => html! {
+                <main>{include!("privacy-policy.md")}</main>
+            },
+            Route::NotFound => todo!(),
+        }
     }
 }