about summary refs log tree commit diff
path: root/corp/rih/frontend/src/main.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-06-09T12·52+0300
committertazjin <tazjin@tvl.su>2023-06-10T11·23+0000
commita970de336574e046e63763d93f9a70d5b1e8464b (patch)
treea700d4c1a983bd4a4be24b50c84d39351c732fdb /corp/rih/frontend/src/main.rs
parentd925ec34cd6625b211c4f5dfe66937d7f3d6a0d6 (diff)
feat(corp/rih): add UUIDs to records from frontend r/6254
This UUID stays the same even if a user submits the form multiple
times (unless they edit it manually in local storage, of course).

Change-Id: I4190fbfeb1027ce8a8d87bc283099539e8722b39
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8733
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'corp/rih/frontend/src/main.rs')
-rw-r--r--corp/rih/frontend/src/main.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/corp/rih/frontend/src/main.rs b/corp/rih/frontend/src/main.rs
index 9b7e38422ac2..efccaaece287 100644
--- a/corp/rih/frontend/src/main.rs
+++ b/corp/rih/frontend/src/main.rs
@@ -10,6 +10,7 @@ use rand::thread_rng;
 use serde::{Deserialize, Serialize};
 use static_markdown::markdown;
 use std::collections::BTreeSet;
+use uuid::Uuid;
 use wasm_bindgen::closure::Closure;
 use wasm_bindgen::{JsCast, JsValue};
 use web_sys::{HtmlInputElement, HtmlTextAreaElement, KeyboardEvent};
@@ -94,6 +95,9 @@ enum Route {
 /// primary data structure we want to populate and persist somewhere.
 #[derive(Clone, Default, Debug, Deserialize, Serialize)]
 struct Record {
+    // Record-specific metadata
+    uuid: Uuid,
+
     // Personal information
     name: String,
     email: String,
@@ -362,7 +366,11 @@ impl Component for App {
 
     fn create(ctx: &Context<Self>) -> Self {
         App {
-            record: LocalStorage::get("record").unwrap_or_default(),
+            record: LocalStorage::get("record").unwrap_or_else(|_| {
+                let mut new_record = Record::default();
+                new_record.uuid = Uuid::new_v4();
+                new_record
+            }),
             citizenship_focus: false,
             citizenship_query: String::default(),
             history: BrowserHistory::default(),