Skip to content

Commit

Permalink
newer leptosfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
akarras committed Jun 20, 2024
1 parent 0d1f35f commit 76a3360
Show file tree
Hide file tree
Showing 33 changed files with 492 additions and 176 deletions.
3 changes: 3 additions & 0 deletions ultros-frontend/ultros-app/src/components/add_to_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn AddToList(#[prop(into)] item_id: MaybeSignal<i32>) -> impl IntoView {
set_modal_visible(!modal_visible());
}
>

<Icon icon=RiPlayListAddMediaLine/>
<div class="sr-only">"Add To List"</div>
{move || {
Expand Down Expand Up @@ -69,6 +70,7 @@ fn AddToListModal(
set_quantity(quantity);
}
/>

</div>
<div class="flex flex-row">
<Toggle
Expand Down Expand Up @@ -117,6 +119,7 @@ fn AddToListModal(
});
}
>

{move || {
if saved() {
view! { <div class="mx-1">"Saved"</div> }.into_view()
Expand Down
1 change: 1 addition & 0 deletions ultros-frontend/ultros-app/src/components/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub fn Clipboard(#[prop(into)] clipboard_text: MaybeSignal<String>) -> impl Into
}
}
>

<Tooltip tooltip_text=MaybeSignal::derive(move || {
if !copied() {
Oco::Owned(format!("Copy '{}' to clipboard", clipboard_text()))
Expand Down
1 change: 1 addition & 0 deletions ultros-frontend/ultros-app/src/components/item_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub fn ItemIcon(#[prop(into)] item_id: MaybeSignal<i32>, icon_size: IconSize) ->
"/static/itemicon/fallback".to_string()
}
}

loading="lazy"
on:error=move |_| {
set_failed(item_id.get_untracked());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub fn LiveSaleTicker() -> impl IntoView {
}
}
>

<For each=sales key=|sale| sale.sold_date let:sale>
<A href=move || {
format!(
Expand Down
12 changes: 11 additions & 1 deletion ultros-frontend/ultros-app/src/components/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,15 @@ pub fn Loading() -> impl IntoView {

#[component]
pub fn LargeLoading(#[prop(into)] pending: Signal<bool>) -> impl IntoView {
view! {<div class:opacity-50=pending class:opacity-0=move || !pending() class="bg-violet-950 absolute left-0 right-0 z-40 transition ease-in-out delay-250"><div class="ml-[50%]"><Loading/></div></div>}
view! {
<div
class:opacity-50=pending
class:opacity-0=move || !pending()
class="bg-violet-950 absolute left-0 right-0 z-40 transition ease-in-out delay-250"
>
<div class="ml-[50%]">
<Loading/>
</div>
</div>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ where
add_items_to_list.dispatch(list);
}
}

class="btn"
>
"Bulk add"
Expand Down
1 change: 1 addition & 0 deletions ultros-frontend/ultros-app/src/components/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn Modal(
e.stop_propagation();
}
>

<div
class="self-end ml-auto cursor-pointer hover:text-neutral-200"
on:click=move |_| set_visible(false)
Expand Down
1 change: 1 addition & 0 deletions ultros-frontend/ultros-app/src/components/number_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ where
"border rounded border-violet-950"
}
}

prop:value=move || input().map(|value| value.into()).unwrap_or(JsValue::NULL)
on:input=move |e| {
let value = event_target_value(&e);
Expand Down
3 changes: 1 addition & 2 deletions ultros-frontend/ultros-app/src/components/profile_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ pub fn ProfileDisplay() -> impl IntoView {
view! {
<Suspense fallback=Loading>
{move || {
user
.get()
user.get()
.map(|user| match user {
Some(auth) => {
view! {
Expand Down
1 change: 1 addition & 0 deletions ultros-frontend/ultros-app/src/components/query_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn QueryButton(
format!("{}{}", pathname(), query.to_query_string())
}
>

{children}
</a>
}
Expand Down
1 change: 1 addition & 0 deletions ultros-frontend/ultros-app/src/components/related_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ pub fn RelatedItems(#[prop(into)] item_id: Signal<i32>) -> impl IntoView {
item.key_id.0,
)
>

<div class="flex flex-row">
<ItemIcon item_id=item.key_id.0 icon_size=IconSize::Medium/>
<span style="width: 300px;">{&item.name}</span>
Expand Down
2 changes: 2 additions & 0 deletions ultros-frontend/ultros-app/src/components/reorderable_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ where
log::warn!("no item dragging?");
}
}

on:dragend=move |_| set_dragging(None)
on:dragstart=move |_| set_dragging(Some(id))
on:dragover=move |e| e.prevent_default()
Expand All @@ -44,6 +45,7 @@ where
dragging().map(|drag| drag == id).unwrap_or_default()
}
>

// if this is the drag object, leave the view the same, otherwise swap it out.
{item_view(child)}
</div>
Expand Down
69 changes: 58 additions & 11 deletions ultros-frontend/ultros-app/src/components/sale_history_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,66 @@ fn WindowStats(#[prop(into)] sales: Signal<SalesWindow>) -> impl IntoView {
let guessed_next_sale_price = create_memo(move |_| sales.with(|s| s.guessed_next_sale_price));
let time_between_sales = create_memo(move |_| sales.with(|s| s.time_between_sales));
let p_value = create_memo(move |_| sales.with(|s| s.p_value));
view ![
view! {
<table>
<tr><td>"Total gil"</td><td><GenericGil<u64> amount=total_gil /></td></tr>
<tr><td>"Average unit price"</td><td><GenericGil<f64> amount=average_unit_price /></td></tr>
<tr><td>"Max unit price"</td><td><Gil amount=max_unit_price/></td></tr>
<tr><td>"Median unit price"</td><td><Gil amount=median_unit_price/></td></tr>
<tr><td>"Min unit price unit price"</td><td><Gil amount=min_unit_price/></td></tr>
<tr><td>"Median stack size"</td><td>{median_stack_size}</td></tr>
<tr><td>"Guessed next sale price"</td><td><GenericGil<f64> amount=guessed_next_sale_price/></td></tr>
<tr><td>"p-value"</td><td>{move || format!("{:.4}", p_value())}</td></tr>
<tr><td>"Average sale within period"</td><td>{move || time_between_sales().abs().to_std().map(|d| format_duration(d).to_string()).unwrap_or_default()}</td></tr>
<tr>
<td>"Total gil"</td>
<td>
<GenericGil<u64> amount=total_gil />
</td>
</tr>
<tr>
<td>"Average unit price"</td>
<td>
<GenericGil<f64> amount=average_unit_price />
</td>
</tr>
<tr>
<td>"Max unit price"</td>
<td>
<Gil amount=max_unit_price />
</td>
</tr>
<tr>
<td>"Median unit price"</td>
<td>
<Gil amount=median_unit_price />
</td>
</tr>
<tr>
<td>"Min unit price unit price"</td>
<td>
<Gil amount=min_unit_price />
</td>
</tr>
<tr>
<td>"Median stack size"</td>
<td>{median_stack_size}</td>
</tr>
<tr>
<td>"Guessed next sale price"</td>
<td>
<GenericGil<f64> amount=guessed_next_sale_price/>
</td>
</tr>
<tr>
<td>"p-value"</td>
<td>{move || format!("{:.4}", p_value())}</td>
</tr>
<tr>
<td>"Average sale within period"</td>
<td>
{move || {
time_between_sales()
.abs()
.to_std()
.map(|d| format_duration(d).to_string())
.unwrap_or_default()
}}
</td>
</tr>
</table>
]
}
}

#[component]
Expand Down
4 changes: 2 additions & 2 deletions ultros-frontend/ultros-app/src/components/search_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn MatchFormatter(m: Match, target: String) -> impl IntoView {
for c in m.continuous_matches() {
// Piece between last match and this match
pieces.push(
view! { {target.chars().skip(last_end).take(c.start() - last_end).collect::<String>()} }
target.chars().skip(last_end).take(c.start() - last_end).collect::<String>()
.into_view(),
);

Expand Down Expand Up @@ -69,6 +69,7 @@ pub fn ItemSearchResult(
format!("/item/{price_zone}/{item_id}")
}
>

// this needs to be updated to be able to point to any region
<div class="search-result">
<ItemIcon item_id icon_size=IconSize::Small/>
Expand Down Expand Up @@ -120,7 +121,6 @@ pub fn ItemSearchResult(
} else {
view! {
// this needs to be updated to be able to point to any region

<a class="search-result">"Invalid result"</a>
}
}}
Expand Down
104 changes: 71 additions & 33 deletions ultros-frontend/ultros-app/src/components/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,52 +82,90 @@ where
};
view! {
<div class="relative">
<input node_ref=input
<input
node_ref=input
class:cursor=move || !has_focus()
class="p-2 rounded-md bg-violet-950
border-solid border border-violet-600 w-96
hover:bg-violet-800 hover:border-violet-950
focus:bg-violet-700 active:border-violet-400"
on:focus=move |_| set_focused(true)
on:focusout=move |_| set_focused(false)
on:input=move |e| { set_current_input(event_target_value(&e)); }
on:input=move |e| {
set_current_input(event_target_value(&e));
}
on:keydown=keydown
prop:value=current_input />
<div class="absolute top-2 left-2 select-none cursor" class:invisible=move || has_focus() || !current_input().is_empty() on:click=move |_| {
if let Some(input) = input() {
let _ = input.focus();
prop:value=current_input
/>
<div
class="absolute top-2 left-2 select-none cursor"
class:invisible=move || has_focus() || !current_input().is_empty()
on:click=move |_| {
if let Some(input) = input() {
let _ = input.focus();
}
}
}>
{move || choice().map(|c| {
children(c.clone(), as_label(&c).into_view())
})}
>
{move || choice().map(|c| { children(c.clone(), as_label(&c).into_view()) })}

</div>
<div node_ref=dropdown class:invisible=move || !has_focus() && !hovered()
class="focus-within:visible absolute w-96 h-96 overflow-y-auto top-10 bg-purple-950 z-20">
<For each=final_result
key=move |(l, _)| *l
let:data
>
<button class="flex flex-col w-full" on:click=move |_| {
if let Some(item) = items.with(|i| i.get(data.0).cloned()) {
set_choice(Some(item));
set_focused(false);
set_current_input("".to_string());
if let Some(element) = document().active_element().and_then(|e| e.dyn_into::<web_sys::HtmlElement>().ok()) {
element.blur().unwrap();
<div
node_ref=dropdown
class:invisible=move || !has_focus() && !hovered()
class="focus-within:visible absolute w-96 h-96 overflow-y-auto top-10 bg-purple-950 z-20"
>
<For each=final_result key=move |(l, _)| *l let:data>
<button
class="flex flex-col w-full"
on:click=move |_| {
if let Some(item) = items.with(|i| i.get(data.0).cloned()) {
set_choice(Some(item));
set_focused(false);
set_current_input("".to_string());
if let Some(element) = document()
.active_element()
.and_then(|e| e.dyn_into::<web_sys::HtmlElement>().ok())
{
element.blur().unwrap();
}
}
}
}>
<div class="hover:bg-purple-700 hover:border-solid hover:border-violet-600 rounded-sm p-2 transition-all ease-in-out duration-500" class:bg-purple-500=move || {
choice.with(|choice| choice.as_ref().and_then(|choice| items.with(|i| i.get(data.0).map(|item| item == choice)))).unwrap_or_default()
}>{items.with(|i| i.get(data.0).cloned()).map(|c| children(c, {move || {
if let Some(m) = fuzzy_search(&current_input(), &data.1){
let target = data.1.clone();
view!{ <div class="flex flex-row gap-1"><MatchFormatter m=m target=target /></div> }
} else {
view!{ <div class="flex flex-row">{&data.1}</div>}
>
<div
class="hover:bg-purple-700 hover:border-solid hover:border-violet-600 rounded-sm p-2 transition-all ease-in-out duration-500"
class:bg-purple-500=move || {
choice
.with(|choice| {
choice
.as_ref()
.and_then(|choice| {
items.with(|i| i.get(data.0).map(|item| item == choice))
})
})
.unwrap_or_default()
}
}}.into_view()))}</div>
>
{items
.with(|i| i.get(data.0).cloned())
.map(|c| children(
c,
{
move || {
if let Some(m) = fuzzy_search(&current_input(), &data.1) {
let target = data.1.clone();
view! {
<div class="flex flex-row gap-1">
<MatchFormatter m=m target=target/>
</div>
}
} else {
view! { <div class="flex flex-row">{&data.1}</div> }
}
}
}
.into_view(),
))}
</div>
</button>
</For>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn SmallItemDisplay(item: &'static Item) -> impl IntoView {
item.key_id.0,
)
>

<ItemDetails item/>
</A>
}
Expand Down
1 change: 1 addition & 0 deletions ultros-frontend/ultros-app/src/components/stats_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn ParamView(data: ParamData) -> impl IntoView {
{data.normal_value + special}
}
})}

</Tooltip>
</div>
}
Expand Down
2 changes: 2 additions & 0 deletions ultros-frontend/ultros-app/src/components/toggle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn Toggle(
set_checked(!checked);
}
/>

<div class="w-11 h-6 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-800 rounded-full peer bg-gray-700
peer-checked:after:translate-x-full peer-checked:after:border-white after:content-['']
after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border
Expand All @@ -27,6 +28,7 @@ pub fn Toggle(
{move || {
if checked() { checked_label.to_string() } else { unchecked_label.to_string() }
}}

</span>
</label>
}
Expand Down
Loading

0 comments on commit 76a3360

Please sign in to comment.