use chrono::{Datelike, Days, Months, NaiveDate}; use common::ron_api; use gloo::storage::{LocalStorage, Storage}; use ron::ser::{PrettyConfig, to_string_pretty}; use serde::{Deserialize, Serialize}; use thiserror::Error; use crate::{calendar, request}; #[derive(Error, Debug)] pub enum Error { #[error("Request error: {0}")] Request(#[from] request::Error), } type Result = std::result::Result; #[derive(Clone, Copy)] pub struct ShoppingList { is_local: bool, } impl ShoppingList { pub fn new(is_local: bool) -> Self { Self { is_local } } pub async fn get_items(&self) -> Result> { if self.is_local { Ok(vec![]) // TODO } else { Ok(request::get("shopping_list", ()).await?) } } pub async fn set_item_checked(&self, item_id: i64, is_checked: bool) -> Result<()> { if self.is_local { todo!(); } else { request::patch( "shopping_list/checked", ron_api::Value { id: item_id, value: is_checked, }, ) .await .map_err(Error::from) } } }