parent
38b3797304
commit
13687748e0
@ -1,2 +1,3 @@
|
||||
pub mod dark_mode_btn;
|
||||
pub mod user_header;
|
||||
pub mod user_icon;
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
use lazy_static::lazy_static;
|
||||
use perseus::prelude::*;
|
||||
use sycamore::{prelude::*, rt::Event};
|
||||
|
||||
use crate::global_state::AppStateRx;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref USER_HEADER: Capsule<PerseusNodeType, ()> = get_capsule();
|
||||
}
|
||||
|
||||
fn user_header<G: Html>(cx: Scope, _props: ()) -> View<G> {
|
||||
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
|
||||
|
||||
view! { cx,
|
||||
(if *global_state.logged_in.get() {
|
||||
view! { cx,
|
||||
div (class="px-6 text-left border-l border-slate-700 dark:border-slate-300") {
|
||||
a (id="header-followed-companies", href="/user_transactions", class="hover:underline") {
|
||||
"Followed companies"
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
view!{cx, }
|
||||
})
|
||||
div (class="grow") {}
|
||||
}
|
||||
}
|
||||
|
||||
fn fallback<G: Html>(cx: Scope, _props: ()) -> View<G> {
|
||||
view! { cx,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_capsule<G: Html>() -> Capsule<G, ()> {
|
||||
Capsule::build(Template::build("user_header"))
|
||||
.fallback(fallback)
|
||||
.view(user_header)
|
||||
.build()
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
use perseus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sycamore::prelude::*;
|
||||
|
||||
use crate::{
|
||||
components::{
|
||||
base_async_select::{AsyncSelectRx, BaseAsyncSelect},
|
||||
base_button::{BaseButton, BaseButtonStateRx},
|
||||
main_content_container::MainContentContainer,
|
||||
paginated_data_table::{PaginatedTable, PaginatedTableStateRx},
|
||||
the_header::TheHeader,
|
||||
},
|
||||
global_state::AppStateRx,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
||||
#[rx(alias = "TransactionsPageStateRx")]
|
||||
pub struct TransactionsPageState {
|
||||
pub company_slug: Option<String>,
|
||||
}
|
||||
|
||||
fn user_transactions_page<'a, G: Html>(cx: Scope) -> View<G> {
|
||||
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
|
||||
let api = global_state.api.get();
|
||||
let api_scope_ref = create_ref(cx, api);
|
||||
|
||||
let expand = create_signal(cx, false);
|
||||
let filter_expand = BaseButtonStateRx {
|
||||
label: create_signal(cx, "Filters".to_string()),
|
||||
disabled: create_signal(cx, false),
|
||||
clicked: create_signal(cx, false),
|
||||
};
|
||||
|
||||
create_effect(cx, move || {
|
||||
if *filter_expand.clicked.get() {
|
||||
filter_expand.clicked.set(false);
|
||||
expand.set(!*expand.get());
|
||||
}
|
||||
});
|
||||
|
||||
let route_ref = create_ref(cx, move |_, p, s| api_scope_ref.get_user_transactions(p, s));
|
||||
let paginated_table_state: PaginatedTableStateRx<_, _, _> = PaginatedTableStateRx {
|
||||
record_label: "transactions".to_owned(),
|
||||
route: route_ref,
|
||||
filter: None,
|
||||
table_class: create_ref(cx, "".to_string()),
|
||||
refresh: create_signal(cx, true),
|
||||
};
|
||||
|
||||
let dark_mode_class = create_memo(cx, || {
|
||||
if *global_state.dark_mode.get() {
|
||||
"dark"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
});
|
||||
|
||||
view! {cx,
|
||||
main (class=format!("{} flex flex-1", dark_mode_class)) {
|
||||
div (class="flex-1 font-sans bg-slate-200 text-slate-700 dark:bg-slate-700 dark:text-slate-100") {
|
||||
TheHeader()
|
||||
MainContentContainer(useless_prop=1) {
|
||||
a (class="hover:underline", href="/user_transactions") {
|
||||
h1 (
|
||||
class="text-lg text-center"
|
||||
) {
|
||||
"Latest transactions from your followed companies"
|
||||
}
|
||||
}
|
||||
PaginatedTable(paginated_table_state)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_template<G: Html>() -> Template<G> {
|
||||
Template::build("user_transactions")
|
||||
.head(head)
|
||||
.view(user_transactions_page)
|
||||
.build()
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
fn head(cx: Scope) -> View<SsrNode> {
|
||||
view! {cx,
|
||||
title { "Fast Insiders" }
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue