-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
96 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::types::Product; | ||
use anyhow::Error; | ||
use yew::callback::Callback; | ||
use yew::format::{Json, Nothing}; | ||
use yew::services::fetch::{FetchService, FetchTask, Request, Response}; | ||
|
||
pub type FetchResponse<T> = Response<Json<Result<T, Error>>>; | ||
type FetchCallback<T> = Callback<FetchResponse<T>>; | ||
|
||
pub fn get_products(callback: FetchCallback<Vec<Product>>) -> FetchTask { | ||
let req = Request::get("/products/products.json") | ||
.body(Nothing) | ||
.unwrap(); | ||
|
||
FetchService::fetch(req, callback).unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod api; | ||
mod types; | ||
mod pages; | ||
|
||
use pages::Home; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Deserialize, Serialize, Clone, Debug)] | ||
pub struct Product { | ||
pub id: i32, | ||
pub name: String, | ||
pub description: String, | ||
pub image: String, | ||
pub price: f64, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct CartProduct { | ||
pub product: Product, | ||
pub quantity: i32, | ||
} |