DefaultView now lists localstorage keys

This commit is contained in:
Yash Karandikar 2021-10-23 18:57:55 -05:00
parent ea1c1b9408
commit 6309c90f34
Signed by: karx
GPG key ID: A794DA2529474BA5
2 changed files with 22 additions and 20 deletions

View file

@ -1,9 +1,29 @@
use sycamore::prelude::*;
use crate::local_storage;
#[component(DefaultView<G>)]
pub fn default_view() -> Template<G> {
let templates = Template::new_fragment({
let mut new_vec: Vec<Template<G>> = Vec::new();
let keys = local_storage::list_local_storage_keys().to_vec();
for val in keys {
if val.is_string() {
if let Some(res) = val.as_string() {
new_vec.push(template! { li { (res) } });
}
}
}
new_vec
});
template! {
p { "Hello, world!" }
ul {
(templates)
}
}
}

View file

@ -4,7 +4,7 @@ mod local_storage;
use sycamore::prelude::*;
#[allow(unused_macros)]
macro_rules! log {
($($t:tt)*) => (console::log_raw(&format_args!($($t)*).to_string()))
}
@ -15,24 +15,6 @@ pub enum AppMode {
}
fn main() {
#[allow(unused_variables)] // Allow because localStorage might be empty
let keys = {
let mut new_vec: Vec<String> = Vec::new();
let keys_raw = local_storage::list_local_storage_keys().to_vec();
for val in keys_raw {
if val.is_string() {
if let Some(res) = val.as_string() {
log!("{}", res);
new_vec.push(res);
}
}
}
new_vec
};
let mode = Signal::new(AppMode::Default);
sycamore::render(|| template! {