Skip to content

Commit

Permalink
add history controls to chat, add analysis button to history (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
PenguinWithATie authored Aug 20, 2024
1 parent ac950f9 commit f45a7d3
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 124 deletions.
80 changes: 60 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ opt-level = 'z'

[workspace.dependencies]
leptos = { version = "0.6" , features = ["nightly"] }
leptos-use = { version = "0.11" }
leptos-use = { version = "0.12" }
leptos_meta = { version = "0.6" , features = ["nightly"] }
leptos_router = { version = "0.6" , features = ["nightly"] }
leptos_actix = { version = "0.6" }
leptos_icons = { version = "0.3"}
icondata = {version = "0.3"}
icondata = {version = "0.4"}
actix-web = { version = "4", features = ["macros"] }
actix-files = { version = "0.6" }
actix-web-actors = { version = "4.3.0" }
Expand All @@ -40,9 +40,9 @@ simple_logger = "5.0"
thiserror = "1"
anyhow = "1"
tokio = { version = "1.39.2", features = ["full"] }
wasm-bindgen = "0.2.92"
wasm-bindgen = "0.2.93"
wasm-bindgen-futures = "0.4"
web-sys = {version = "0.3.69", features = ["AbortController", "AbortSignal", "AudioContext", "AudioBuffer", "AudioBufferSourceNode", "AudioDestinationNode", "Blob", "Clipboard", "HtmlDocument", "SvgPoint", "SvgsvgElement", "SvgGraphicsElement", "SvgRect", "SvgMatrix", "Url", "Window"] }
web-sys = {version = "0.3.70", features = ["AbortController", "AbortSignal", "AudioContext", "AudioBuffer", "AudioBufferSourceNode", "AudioDestinationNode", "Blob", "Clipboard", "HtmlDocument", "SvgPoint", "SvgsvgElement", "SvgGraphicsElement", "SvgRect", "SvgMatrix", "Url", "Window"] }
bb8 = { version = "0.8" }
diesel = { version = "2.2", features = ["postgres", "chrono", "uuid", "serde_json"] }
diesel-async = { version = "0.5", features = ["postgres", "bb8"] }
Expand Down
3 changes: 1 addition & 2 deletions apis/src/components/molecules/challenge_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ pub fn ChallengeRow(challenge: StoredValue<ChallengeResponse>, single: bool) ->
.as_ref()
.expect("window to exist")
.navigator()
.clipboard()
.expect("to have clipboard permission");
.clipboard();
let _ = clipboard.write_text(&challenge_address());
let class_list = button_ref
.get_untracked()
Expand Down
92 changes: 92 additions & 0 deletions apis/src/components/molecules/history_controls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use crate::components::atoms::history_button::{HistoryButton, HistoryNavigation};
use crate::components::organisms::reserve::{Alignment, Reserve};
use crate::providers::game_state::GameStateSignal;
use ev::keydown;
use hive_lib::Color;
use leptos::*;
use leptos_use::{use_event_listener, use_window};

#[component]
pub fn HistoryControls(#[prop(optional)] parent: MaybeProp<NodeRef<html::Div>>) -> impl IntoView {
let game_state = expect_context::<GameStateSignal>();
let window = use_window();
let active = Signal::derive(move || {
window.as_ref().and_then(|w| {
w.document()
.expect("window to have a document")
.query_selector(".bg-orange-twilight")
.expect("to have an Element")
})
});
let focus = Callback::new(move |()| {
if let Some(elem) = active.get_untracked() {
elem.scroll_into_view_with_bool(false);
}
});
let prev_button = create_node_ref::<html::Button>();
let next_button = create_node_ref::<html::Button>();
_ = use_event_listener(document().body(), keydown, move |evt| {
if evt.key() == "ArrowLeft" {
evt.prevent_default();
if let Some(prev) = prev_button.get_untracked() {
prev.click()
};
} else if evt.key() == "ArrowRight" {
evt.prevent_default();
if let Some(next) = next_button.get_untracked() {
next.click()
};
}
});

let go_to_end = Callback::new(move |()| {
if let Some(parent) = parent.get() {
let parent = parent.get_untracked().expect("div to be loaded");
parent.set_scroll_top(parent.scroll_height());
}
game_state.show_history_turn(game_state.signal.get_untracked().state.turn - 1);
});
let if_last_go_to_end = Callback::new(move |()| {
focus(());
let gamestate = game_state.signal.get_untracked();
{
if let Some(turn) = gamestate.history_turn {
if turn == gamestate.state.turn - 1 {
go_to_end(());
}
}
}
});
view! {
<div>
<div class="flex gap-1 min-h-0 [&>*]:grow">
<HistoryButton

action=HistoryNavigation::First
post_action=focus
/>

<HistoryButton
node_ref=prev_button
action=HistoryNavigation::Previous
post_action=focus
/>
<HistoryButton
node_ref=next_button
action=HistoryNavigation::Next
post_action=if_last_go_to_end
/>

<HistoryButton

action=HistoryNavigation::Last
post_action=go_to_end
/>
</div>
<div class="flex p-2">
<Reserve alignment=Alignment::DoubleRow color=Color::White analysis=false/>
<Reserve alignment=Alignment::DoubleRow color=Color::Black analysis=false/>
</div>
</div>
}
}
1 change: 1 addition & 0 deletions apis/src/components/molecules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod game_previews;
pub mod game_row;
pub mod hamburger;
pub mod hex_stack;
pub mod history_controls;
pub mod history_pieces;
pub mod hover_ratings;
pub mod invite_user;
Expand Down
Loading

0 comments on commit f45a7d3

Please sign in to comment.