Skip to content

Commit

Permalink
fix sign up missing subscribed feel
Browse files Browse the repository at this point in the history
  • Loading branch information
The-DevBlog committed Feb 11, 2024
1 parent ca5cf1f commit 28966d7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
6 changes: 4 additions & 2 deletions devblog/devblog/client/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// use gloo::console::log;
use crate::store::Store;
use crate::{helpers, Api};
use crate::{router::Route, User, UserField};
use gloo::console::log;
use gloo_net::http::{Headers, Method, Response};
use serde::de::DeserializeOwned;
use serde::Serialize;
Expand Down Expand Up @@ -35,7 +35,8 @@ pub fn onsubmit(
e.prevent_default();
let dispatch_clone = dispatch.clone();
let nav = nav.clone();
let user = user.deref().clone();
let mut user = user.deref().clone();
user.subscribed = true;
let hdrs = Headers::new();
hdrs.append("content-type", "application/json");
wasm_bindgen_futures::spawn_local(async move {
Expand Down Expand Up @@ -81,5 +82,6 @@ where
T: DeserializeOwned,
{
let txt = response.text().await.unwrap();
log!("Response: ", &txt);
callback.emit(serde_json::from_str::<T>(&txt).unwrap());
}
16 changes: 6 additions & 10 deletions devblog/devblog/client/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ pub struct DownVoteModel {

#[derive(Clone, Serialize, Deserialize, PartialEq, Debug, Default)]
pub struct User {
#[serde(rename = "userName")]
#[serde(default, rename = "userName")]
pub username: String,
#[serde(default)]
pub email: String,
#[serde(default)]
pub password: String,
#[serde(rename = "passwordHash")]
#[serde(default, rename = "passwordHash")]
pub password_hash: String,
#[serde(default)]
pub subscribed: bool,
}

impl User {
Expand All @@ -76,11 +80,3 @@ pub enum UserField {
PasswordHash,
Email,
}

#[derive(Clone, Serialize, Deserialize, PartialEq, Debug, Default)]
pub struct UserInfo {
#[serde(rename = "userName")]
pub username: String,
pub subscribed: bool,
pub email: String,
}
1 change: 1 addition & 0 deletions devblog/devblog/client/src/pages/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn home() -> Html {
let latest_post_cb = CustomCallback::new(&latest_post);
let total_posts_count_cb = CustomCallback::new(&total_posts_count);

// get latest page and posts count
use_effect_with((), move |_| {
wasm_bindgen_futures::spawn_local(async move {
let res = Api::GetPost(-1).fetch(None, None, Method::GET).await;
Expand Down
5 changes: 3 additions & 2 deletions devblog/devblog/client/src/pages/insights.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
helpers::{self, CustomCallback},
store::Store,
Api, UserInfo,
Api, User,
};
use gloo_net::http::{Headers, Method};
use stylist::Style;
Expand All @@ -13,10 +13,11 @@ const STYLE: &str = include_str!("styles/insights.css");
#[function_component(Insights)]
pub fn insights() -> Html {
let style = Style::new(STYLE).unwrap();
let users = use_state(|| vec![UserInfo::default()]);
let users = use_state(|| vec![User::default()]);
let users_cb = CustomCallback::new(&users);
let store = use_store_value::<Store>();

// get all users
use_effect_with((), move |_| {
wasm_bindgen_futures::spawn_local(async move {
let hdrs = Headers::new();
Expand Down
2 changes: 2 additions & 0 deletions devblog/devblog/client/src/pages/posts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn posts() -> Html {
let total_posts_count_cb = CustomCallback::new(&total_posts_count);
let total_pages_count_cb = CustomCallback::new(&total_pages_count);

// get pages count and posts count
use_effect_with((), move |_| {
wasm_bindgen_futures::spawn_local(async move {
let res = Api::GetPostsCount.fetch(None, None, Method::GET).await;
Expand All @@ -32,6 +33,7 @@ pub fn posts() -> Html {
});
});

// get posts for current page
let page_num_clone = page_num.clone();
let loading_clone = loading.clone();
use_effect_with(page_num_clone.clone(), move |_| {
Expand Down

0 comments on commit 28966d7

Please sign in to comment.