user-auth store frontend and backend v2
This commit is contained in:
@@ -118,7 +118,7 @@ async fn logout_user() -> Result<reqwasm::http::Response, reqwasm::Error> {
|
||||
async fn list_users() -> Result<HashMap<String,i32>, reqwasm::Error> {
|
||||
let backend_url : &'static str = dotenv!("BACKEND_URL");
|
||||
let url = format!("{}/api/list_users", backend_url);
|
||||
let resp = Request::post(&url).send().await?;
|
||||
let resp = Request::get(&url).send().await?;
|
||||
let users = resp.json::<Vec<AxumUser>>().await?;
|
||||
let mut res = HashMap::new();
|
||||
for user in users {
|
||||
@@ -202,7 +202,7 @@ async fn list_books(page: u32, userid: i32, sort: String) -> Result<PaginatedBoo
|
||||
let url = format!("{}/api/list?page={}&userid={}&sort={}", backend_url, page, userid, sort);
|
||||
let resp = Request::get(&url).send().await?;
|
||||
println!("Fetching books\n");
|
||||
info!("BACKEND{}",backend_url);
|
||||
//info!("BACKEND{}",backend_url);
|
||||
|
||||
let body = resp.json::<PaginatedBookUIList>().await?;
|
||||
Ok(body)
|
||||
@@ -219,7 +219,7 @@ pub fn Header<G: Html>(cx: Scope) -> View<G> {
|
||||
|
||||
let value3 = create_signal(cx, String::new());
|
||||
let input_ref3 = create_node_ref(cx);
|
||||
|
||||
let completed = create_selector(cx, || *app_state.editmode.get());
|
||||
let editchecked = create_signal(cx, false);
|
||||
|
||||
let handle_submit = |event: Event| {
|
||||
@@ -233,6 +233,7 @@ pub fn Header<G: Html>(cx: Scope) -> View<G> {
|
||||
app_state.search.set(task.clone());
|
||||
app_state.openlibrary.set(true);
|
||||
app_state.internalsearch.set(false);
|
||||
app_state.refreshing.set(false);
|
||||
|
||||
info!("Fetching search {}\n", task.clone());
|
||||
app_state.books.set(Vec::new());
|
||||
@@ -322,6 +323,11 @@ pub fn Header<G: Html>(cx: Scope) -> View<G> {
|
||||
app_state.dropdownselect.set(true);
|
||||
};
|
||||
|
||||
create_effect(cx, || {
|
||||
// Calling checked.set will also update the `checked` property on the input element.
|
||||
editchecked.set(*completed.get())
|
||||
});
|
||||
|
||||
// let users = create_memo(cx, || app_state.userlist.get().keys().cloned().map(|x| StringProp{value: x}).collect::<Vec<StringProp>>());
|
||||
let users = create_memo(cx, || app_state.userlist.get().keys().cloned().collect::<Vec<String>>());
|
||||
|
||||
@@ -341,7 +347,7 @@ pub fn Header<G: Html>(cx: Scope) -> View<G> {
|
||||
type="checkbox",
|
||||
on:input=toggle_editmode,
|
||||
bind:checked=editchecked
|
||||
)
|
||||
)("EDIT")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -362,6 +368,8 @@ pub fn Header<G: Html>(cx: Scope) -> View<G> {
|
||||
div(class="header-column"){
|
||||
(if *app_state.editmode.get() == false {
|
||||
view!{ cx,
|
||||
div(class="dropdown"){
|
||||
|
||||
button(on:click=dropdown_userselect) { "Select User" }
|
||||
(if *app_state.dropdownselect.get() == true {
|
||||
view!{ cx,
|
||||
@@ -377,6 +385,7 @@ pub fn Header<G: Html>(cx: Scope) -> View<G> {
|
||||
} else {
|
||||
view!{cx, ""}
|
||||
})
|
||||
}
|
||||
}} else {
|
||||
view!{cx, ""}
|
||||
})
|
||||
@@ -425,16 +434,15 @@ pub fn DropDownUser<G: Html>(cx: Scope, value: StringProp) -> View<G> {
|
||||
};
|
||||
|
||||
view! { cx,
|
||||
button(class="delete", on:click=handle_select_user){ (buttontext) }
|
||||
button(class="dropdown-item", on:click=handle_select_user){ (buttontext) }br{}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
async fn ListDB<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
let app_state = use_context::<AppState>(cx);
|
||||
let callback_signal = use_context::<RcSignal<bool>>(cx);
|
||||
let csignal = callback_signal.clone();
|
||||
//callback_signal.clone().set(false);
|
||||
//let callback_signal = use_context::<RcSignal<bool>>(cx);
|
||||
/*
|
||||
create_effect(cx, || {
|
||||
let app_state = app_state.clone();
|
||||
let cxsignal = callback_signal.clone();
|
||||
@@ -446,7 +454,7 @@ async fn ListDB<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
create_effect(cx, || {
|
||||
let app_state = app_state.clone();
|
||||
app_state.search.track();
|
||||
@@ -455,6 +463,7 @@ async fn ListDB<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
app_state.internalsearch.track();
|
||||
app_state.refreshing.track();
|
||||
//let csignal = csignals2.clone();
|
||||
//info!("Something triggered{}",*app_state.clone().search.clone());
|
||||
|
||||
//let tempb = app_state.books.get();
|
||||
//spawn_local( async move { info!(
|
||||
@@ -533,7 +542,9 @@ async fn ListDB<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
}
|
||||
|
||||
} else {
|
||||
//info!("LibrarySearch triggered?");
|
||||
if *app_state.refreshing.get() == false {
|
||||
info!("LibrarySearch triggered");
|
||||
spawn_local(async move {
|
||||
if *app_state.search.get() != "" {
|
||||
if *app_state.openlibrary.get() == true {
|
||||
@@ -553,7 +564,6 @@ async fn ListDB<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
|
||||
let callback: Closure<dyn FnMut()> = Closure::new(move || {
|
||||
//let csignal = callback_signal.clone();
|
||||
csignal.set(true);
|
||||
info!("Got scroll event");
|
||||
});
|
||||
|
||||
@@ -1126,7 +1136,11 @@ async fn SelectedUI<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
div(class="more-info"){
|
||||
div(class="more-info-buttons"){
|
||||
button(class="close", on:click=handle_close){ "CLOSE" }
|
||||
button(class="close", on:click=handle_edit){ "EDIT" }
|
||||
(if *app_state.editmode.get() == true {
|
||||
view!{ cx,button(class="close", on:click=handle_edit){ "EDIT" }}
|
||||
} else {
|
||||
view!{cx, ""}
|
||||
})
|
||||
}
|
||||
img(src=coverurl.get(),width="200")
|
||||
label{"Title: "}
|
||||
@@ -1279,8 +1293,6 @@ async fn LoginScreenUI<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
spawn_local(async move {
|
||||
login_user(user)
|
||||
.await.expect("Couldn't login user");
|
||||
});
|
||||
spawn_local(async move {
|
||||
let auth = authentication_check().await.unwrap_or(false);
|
||||
app_state.loggedin.set(auth);
|
||||
if auth == true {
|
||||
@@ -1320,7 +1332,7 @@ async fn LoginScreenUI<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
view!{cx,
|
||||
div(class="modal-content"){
|
||||
input(ref=input_refU,bind:value=userval)
|
||||
input(ref=input_refP,bind:value=passval)
|
||||
input(ref=input_refP,bind:value=passval,type="password")
|
||||
|
||||
button(on:click=handle_login){ "LOGIN" }
|
||||
button(on:click=handle_register){ "REGISTER" }
|
||||
|
||||
Reference in New Issue
Block a user