diff --git a/web/src/api.rs b/web/src/api.rs
index 9a01279..5422125 100644
--- a/web/src/api.rs
+++ b/web/src/api.rs
@@ -17,7 +17,7 @@ use base64::{self, Engine};
use chrono::NaiveDate;
use gloo_net;
// TODO(jwall): Remove this when we have gone a few migrations past.
-//use serde_json::{from_str, to_string};
+use serde_json::{from_str, to_string};
use sycamore::prelude::*;
use tracing::{debug, error, instrument};
@@ -26,6 +26,7 @@ use client_api::*;
use recipes::{IngredientKey, RecipeEntry};
use serde_wasm_bindgen::{from_value, to_value};
use wasm_bindgen::JsValue;
+use web_sys::Storage;
// TODO(jwall): Remove this when we have gone a few migrations past.
//use web_sys::Storage;
@@ -90,21 +91,38 @@ fn token68(user: String, pass: String) -> String {
#[derive(Clone, Debug)]
pub struct LocalStore {
- // FIXME(zaphar): Migration from local storage to indexed db
- //old_store: Storage,
+ // TODO(zaphar): Remove this when it's safe to delete the migration
+ old_store: Storage,
store: DBFactory<'static>,
}
const APP_STATE_KEY: &'static str = "app-state";
+const USER_DATA_KEY: &'static str = "user_data";
impl LocalStore {
pub fn new() -> Self {
Self {
store: DBFactory::default(),
- //old_store: js_lib::get_storage(),
+ old_store: js_lib::get_storage(),
}
}
+ pub async fn migrate(&self) {
+ // 1. migrate app-state from localstore to indexeddb
+ if let Ok(Some(v)) = self.old_store.get("app_state") {
+ if let Ok(Some(local_state)) = from_str::