Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
flosse committed Aug 21, 2023
1 parent 45ce53f commit 633cf90
Show file tree
Hide file tree
Showing 10 changed files with 438 additions and 397 deletions.
345 changes: 167 additions & 178 deletions Cargo.lock

Large diffs are not rendered by default.

318 changes: 186 additions & 132 deletions ofdb-app-clearance/Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions ofdb-app-clearance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ ofdb-frontend-api = "=0.0.0"
console_error_panic_hook = "0.1.7"
console_log = "1.0.0"
difference = "2.0.0"
gloo-storage = "0.2.2"
leptos = { version = "0.4.3", features = ["csr"] }
leptos_router = { version = "0.4.3", features = ["csr"] }
log = "0.4.19"
gloo-storage = "0.3.0"
leptos = { version = "0.5.0-beta", features = ["csr"] }
leptos_router = { version = "0.5.0-beta", features = ["csr"] }
log = "0.4.20"
wasm-bindgen = "0.2.87"
web-sys = { version = "0.3.64", features = ["HtmlFormElement"] }

Expand Down
18 changes: 9 additions & 9 deletions ofdb-app-clearance/src/components/navbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use leptos_router::*;
use crate::page::Page;

#[component]
pub fn Navbar(cx: Scope, logged_in: Signal<bool>) -> impl IntoView {
let menu_is_active = create_rw_signal(cx, false);
pub fn Navbar(logged_in: Signal<bool>) -> impl IntoView {
let menu_is_active = create_rw_signal(false);

view! { cx,
view! {
<nav class="navbar" roler="navigation" aria-label="main navigation">
<div class="navbar-brand">
<A class="navbar-item" href=Page::Home.path()>
Expand All @@ -25,19 +25,19 @@ pub fn Navbar(cx: Scope, logged_in: Signal<bool>) -> impl IntoView {
<div class="buttons">
{move || {
if logged_in.get() {
view! { cx,
view! {
<A class="button is-light" href=Page::Logout.path()>
"Log out"
</A>
}
.into_view(cx)
.into_view()
} else {
view! { cx,
view! {
<A href=Page::Login.path() class="button is-light">
"Log in"
</A>
}
.into_view(cx)
.into_view()
}
}}
</div>
Expand All @@ -49,8 +49,8 @@ pub fn Navbar(cx: Scope, logged_in: Signal<bool>) -> impl IntoView {
}

#[component]
pub fn BurgerMenu(cx: Scope, menu_is_active: RwSignal<bool>) -> impl IntoView {
view! { cx,
pub fn BurgerMenu(menu_is_active: RwSignal<bool>) -> impl IntoView {
view! {
<a
on:click=move |_| {
menu_is_active.update(|v| *v = !*v);
Expand Down
37 changes: 18 additions & 19 deletions ofdb-app-clearance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ const TOKEN_KEY: &str = "org-token";
const TITLE: &str = "Clearance Center";

#[component]
fn App(cx: Scope) -> impl IntoView {
fn App() -> impl IntoView {
// -- signals -- //

let (token, set_token) = create_signal(cx, Option::<String>::None);
let logged_in = Signal::derive(cx, move || token.get().is_some());
let invalid_token = create_rw_signal(cx, false);
let place_clearances = create_rw_signal(cx, HashMap::<String, api::PlaceClearance>::new());
let (token, set_token) = create_signal(Option::<String>::None);
let logged_in = Signal::derive(move || token.get().is_some());
let invalid_token = create_rw_signal(false);
let place_clearances = create_rw_signal(HashMap::<String, api::PlaceClearance>::new());

// -- actions -- //

let get_place_history = create_action(cx, move |(token, id): &(String, String)| {
let get_place_history = create_action(move |(token, id): &(String, String)| {
let api = ClearanceApi::new(api::API_ROOT, token.clone());
let id = id.clone();
async move {
Expand All @@ -54,7 +54,7 @@ fn App(cx: Scope) -> impl IntoView {
}
});

let fetch_pending_clearances = create_action(cx, move |_: &()| async move {
let fetch_pending_clearances = create_action(move |_: &()| async move {
match token.get() {
Some(token) => {
let api = ClearanceApi::new(api::API_ROOT, token.clone());
Expand Down Expand Up @@ -111,46 +111,45 @@ fn App(cx: Scope) -> impl IntoView {

// -- effects -- //

view! { cx,
view! {
<Router>
<Navbar logged_in/>
<main>
<Routes>
<Route
path=Page::Home.path()
view=move |cx| {
view=move || {
if let Some(token) = token.get() {
view! { cx,
view! {
<Index token place_clearances fetch_pending_clearances/>
}
.into_view(cx)
.into_view()
} else {
let navigate = leptos_router::use_navigate(cx);
let navigate = leptos_router::use_navigate();
request_animation_frame(move || {
_ = navigate(Page::Login.path(), Default::default());
});
view! {
cx,
}
.into_view(cx)
.into_view()
}
}
/>
<Route
path=Page::Login.path()
view=move |cx| view! { cx, <Login invalid_token=invalid_token.into()/> }
view=move || view! { <Login invalid_token=invalid_token.into()/> }
/>
<Route
path=Page::Logout.path()
view=move |cx| {
view=move || {
SessionStorage::delete(TOKEN_KEY);
set_token.update(|x| *x = None);
let navigate = leptos_router::use_navigate(cx);
let navigate = leptos_router::use_navigate();
request_animation_frame(move || {
_ = navigate(Page::Login.path(), Default::default());
});
view! {
cx,

}
}
/>
Expand All @@ -164,5 +163,5 @@ pub fn run() {
let container = document()
.get_element_by_id("app")
.expect("container element");
mount_to(container.unchecked_into(), |cx| view! { cx, <App/> });
mount_to(container.unchecked_into(), || view! { <App/> });
}
82 changes: 39 additions & 43 deletions ofdb-app-clearance/src/page/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ use crate::api;

#[component]
pub fn Index(
cx: Scope,
token: String,
place_clearances: RwSignal<HashMap<String, api::PlaceClearance>>,
fetch_pending_clearances: Action<(), ()>,
) -> impl IntoView {
let expanded = create_rw_signal(cx, HashSet::<String>::new());
let selected = create_rw_signal(cx, HashSet::<String>::new());
let expanded = create_rw_signal(HashSet::<String>::new());
let selected = create_rw_signal(HashSet::<String>::new());

let handle_clearance_result = move |result| {
match result {
Expand All @@ -44,7 +43,7 @@ pub fn Index(

let accept = {
let token = token.clone();
create_action(cx, move |(id, rev_nr): &(String, u64)| {
create_action(move |(id, rev_nr): &(String, u64)| {
let c = ClearanceForPlace {
place_id: id.clone(),
cleared_revision: Some(*rev_nr),
Expand All @@ -60,7 +59,7 @@ pub fn Index(

let accept_all_selected = {
let token = token.clone();
create_action(cx, move |_: &()| {
create_action(move |_: &()| {
let place_clearances = place_clearances.get();
let clearances = selected
.get()
Expand All @@ -86,16 +85,16 @@ pub fn Index(
})
};

view! { cx,
view! {
<div>
<main>
<div class="container">
<div class="section">
{move || {
if place_clearances.get().is_empty() {
view! { cx, <p>"There is nothing to clear :)"</p> }.into_view(cx)
view! { <p>"There is nothing to clear :)"</p> }.into_view()
} else {
view! { cx,
view! {
<div class="panel">
<p class="panel-heading">
"Pending Clearances"
Expand All @@ -110,8 +109,8 @@ pub fn Index(
<For
each=move || place_clearances.get()
key=|(id, _)| id.clone()
view=move |cx, (_, place_clearance)| {
view! { cx,
view=move |(_, place_clearance)| {
view! {
<PanelBlock place_clearance expanded selected accept/>
}
}
Expand All @@ -128,7 +127,7 @@ pub fn Index(
</div>
</div>
}
.into_view(cx)
.into_view()
}
}}
</div>
Expand All @@ -140,7 +139,6 @@ pub fn Index(

#[component]
fn PanelBlock(
cx: Scope,
place_clearance: api::PlaceClearance,
expanded: RwSignal<HashSet<String>>,
selected: RwSignal<HashSet<String>>,
Expand All @@ -149,14 +147,14 @@ fn PanelBlock(
let id = place_clearance.pending.place_id.clone();
let is_expanded = {
let id = id.clone();
Signal::derive(cx, move || expanded.get().contains(&id))
Signal::derive(move || expanded.get().contains(&id))
};
let is_selected = {
let id = id.clone();
Signal::derive(cx, move || selected.get().contains(&id))
Signal::derive(move || selected.get().contains(&id))
};

view! { cx,
view! {
<li class="panel-block">
<div>
<div class="level">
Expand Down Expand Up @@ -350,7 +348,7 @@ fn PanelBlock(
.get()
.then(|| {
if let Some(curr_rev) = place_clearance.current_rev() {
view! { cx,
view! {
<div>
<DetailsTable
id=place_clearance.pending.place_id.clone()
Expand All @@ -361,9 +359,9 @@ fn PanelBlock(
/>
</div>
}
.into_view(cx)
.into_view()
} else {
view! { cx, <p>"Loading current revision ..."</p> }.into_view(cx)
view! { <p>"Loading current revision ..."</p> }.into_view()
}
})
}}
Expand All @@ -374,7 +372,6 @@ fn PanelBlock(

#[component]
fn PanelActions(
cx: Scope,
place_clearances: RwSignal<HashMap<String, api::PlaceClearance>>,
expanded: RwSignal<HashSet<String>>,
selected: RwSignal<HashSet<String>>,
Expand All @@ -395,7 +392,7 @@ fn PanelActions(
let collapse_all = move |_| {
expanded.update(|x| x.clear());
};
view! { cx,
view! {
<div class="field is-grouped">
<p class="control">
<button class="button" on:click=expand_all>
Expand Down Expand Up @@ -423,7 +420,6 @@ fn PanelActions(

#[component]
fn DetailsTable(
cx: Scope,
id: String,
last_cleared_rev_nr: Option<u64>,
lastrev: Option<PlaceRevision>,
Expand Down Expand Up @@ -451,7 +447,7 @@ fn DetailsTable(
String::new()
};

view! { cx,
view! {
<table class="details-table">
<col class="col-head"/>
<col class="col-last"/>
Expand All @@ -473,13 +469,13 @@ fn DetailsTable(
</button>
</th>
</tr>
{table_row_always(cx, "Title", &title_cs)}
{table_row_always(cx, "Description", &desc_cs)}
{table_row_always(cx, "Location", &location_cs)}
{table_row(cx, "Contact", &contact_cs)}
{table_row(cx, "Opening hours", &opening_cs)}
{table_row(cx, "Links", &links_cs)}
{table_row(cx, "Tags", &tags_cs)}
{table_row_always("Title", &title_cs)}
{table_row_always("Description", &desc_cs)}
{table_row_always("Location", &location_cs)}
{table_row("Contact", &contact_cs)}
{table_row("Opening hours", &opening_cs)}
{table_row("Links", &links_cs)}
{table_row("Tags", &tags_cs)}
</table>
}
}
Expand Down Expand Up @@ -592,44 +588,44 @@ where
Changeset::new(&slast, &scurr, split)
}

fn table_row_always(cx: Scope, title: &'static str, cs: &Changeset) -> impl IntoView {
view! { cx,
fn table_row_always(title: &'static str, cs: &Changeset) -> impl IntoView {
view! {
<tr>
<td>{title}</td>
<td>{diffy_last(cx, cs)}</td>
<td>{diffy_current(cx, cs)}</td>
<td>{diffy_last(cs)}</td>
<td>{diffy_current(cs)}</td>
</tr>
}
}

fn table_row(cx: Scope, title: &'static str, cs: &Changeset) -> impl IntoView {
fn table_row(title: &'static str, cs: &Changeset) -> impl IntoView {
if cs.distance == 0 {
None
} else {
Some(table_row_always(cx, title, cs))
Some(table_row_always(title, cs))
}
}

fn diffy_current(cx: Scope, cs: &Changeset) -> impl IntoView {
fn diffy_current(cs: &Changeset) -> impl IntoView {
let csm = cs.diffs.iter().map(|d| match d {
Difference::Same(s) => Some(view! { cx, <span inner_html=s></span> }.into_view(cx)),
Difference::Same(s) => Some(view! { <span inner_html=s></span> }.into_view()),
Difference::Add(s) => {
Some(view! { cx, <span class="diffadd" inner_html=s></span> }.into_view(cx))
Some(view! { <span class="diffadd" inner_html=s></span> }.into_view())
}
_ => None,
});
view! { cx, <span>{csm.collect_view(cx)}</span> }
view! { <span>{csm.collect_view()}</span> }
}

fn diffy_last(cx: Scope, cs: &Changeset) -> impl IntoView {
fn diffy_last(cs: &Changeset) -> impl IntoView {
let csm = cs.diffs.iter().map(|d| match d {
Difference::Same(s) => Some(view! { cx, <span inner_html=s></span> }.into_view(cx)),
Difference::Same(s) => Some(view! { <span inner_html=s></span> }.into_view()),
Difference::Rem(s) => {
Some(view! { cx, <span class="diffrem" inner_html=s></span> }.into_view(cx))
Some(view! { <span class="diffrem" inner_html=s></span> }.into_view())
}
_ => None,
});
view! { cx, <span>{csm.collect_view(cx)}</span> }
view! { <span>{csm.collect_view()}</span> }
}

#[derive(Clone, Debug)]
Expand Down
Loading

0 comments on commit 633cf90

Please sign in to comment.