From 2c6c529cc6acddccfa3acc35764343a254802164 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Sun, 8 Oct 2023 15:40:32 +0200 Subject: [PATCH] feat: added storing if the preview popup was already shown this session --- Cargo.lock | 1 + Cargo.toml | 3 ++- src/main.rs | 22 ++++++++++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 13cf9cb..b9d3149 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,6 +131,7 @@ dependencies = [ "futures-channel", "gloo 0.10.0", "gloo-net 0.4.0", + "gloo-storage 0.3.0", "serde", "serde_json", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 3b21a1f..97e270c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,4 +21,5 @@ wasm-bindgen = "0.2.87" wasm-bindgen-futures = "0.4" web-sys = { version = "0.3.64", features = ["HtmlInputElement", "HtmlDocument"] } gloo = "0.10.0" -gloo-net = "0.4.0" \ No newline at end of file +gloo-net = "0.4.0" +gloo-storage = "0.3.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index deb0912..88f72b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,10 +2,10 @@ mod backend; mod content; mod topbar; -use anyhow::Result; use backend::Session; use content::{about::About, error, home::Home}; use gloo::dialogs::alert; +use gloo_storage::{SessionStorage, Storage}; use std::ops::Deref; use topbar::TopBar; use yew::prelude::*; @@ -70,8 +70,22 @@ fn App() -> Html { } fn main() { - if option_env!("NC_BETA_BUILD").is_some() { - alert("This is a beta preview!\nThe UI and the backend are subjects to change. Data persistence can't be guaranteed."); - } + preview_alert(); yew::Renderer::::new().render(); } + +fn preview_alert() { + if option_env!("NC_BETA_BUILD").is_none() { + return; + } + + if let Ok(value) = SessionStorage::get::("nc-preview-alert-shown") { + if value { + return; + } + } + + SessionStorage::set("nc-preview-alert-shown", true).expect("Failed to set session storage!"); + + alert("This is a beta preview!\nThe UI and the backend are subjects to change. Data persistence can't be guaranteed."); +}