Skip to content

Commit

Permalink
Tournament Schedules (#294)
Browse files Browse the repository at this point in the history
*Adds tournament schedules, refactors and styles tournament page
---------

Co-authored-by: ioni <[email protected]>
  • Loading branch information
PenguinWithATie and IongIer authored Aug 2, 2024
1 parent 6204ec6 commit a2335ae
Show file tree
Hide file tree
Showing 51 changed files with 1,361 additions and 404 deletions.
42 changes: 21 additions & 21 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions apis/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use crate::{
games::provide_games, navigation_controller::provide_navigation_controller,
online_users::provide_users, provide_alerts, provide_auth, provide_challenge_params,
provide_color_scheme, provide_config, provide_notifications, provide_ping, provide_sounds,
refocus::provide_refocus, timer::provide_timer, tournament_ready::provide_tournament_ready,
tournaments::provide_tournaments, user_search::provide_user_search,
websocket::provide_websocket,
refocus::provide_refocus, schedules::provide_schedules, timer::provide_timer,
tournament_ready::provide_tournament_ready, tournaments::provide_tournaments,
user_search::provide_user_search, websocket::provide_websocket,
},
};
use leptos::*;
Expand Down Expand Up @@ -47,6 +47,7 @@ pub fn App() -> impl IntoView {
provide_tournaments();
provide_notifications();
provide_tournament_ready();
provide_schedules();
provide_sounds();

view! {
Expand Down
2 changes: 2 additions & 0 deletions apis/src/common/client_message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::game_action::GameAction;
use super::schedule_action::ScheduleAction;
use super::{challenge_action::ChallengeAction, TournamentAction};
use serde::{Deserialize, Serialize};
use shared_types::{ChatMessageContainer, GameId};
Expand All @@ -10,6 +11,7 @@ pub enum ClientRequest {
Challenge(ChallengeAction),
Game { game_id: GameId, action: GameAction },
Pong(u64),
Schedule(ScheduleAction),
Tournament(TournamentAction),
// leptos-use idle or window unfocused will send
Away, // Online and Offline are not needed because they will be handled by the WS connection
Expand Down
4 changes: 3 additions & 1 deletion apis/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod hex_stack;
mod move_info;
mod piece_type;
mod rating_change_info;
mod schedule_action;
mod server_result;
mod svg_pos;
mod time_signals;
Expand All @@ -23,9 +24,10 @@ pub use hex_stack::HexStack;
pub use move_info::MoveInfo;
pub use piece_type::PieceType;
pub use rating_change_info::RatingChangeInfo;
pub use schedule_action::ScheduleAction;
pub use server_result::{
ChallengeUpdate, CommonMessage, ExternalServerError, GameActionResponse, GameUpdate,
ServerMessage, ServerResult, TournamentUpdate, UserStatus, UserUpdate,
ScheduleUpdate, ServerMessage, ServerResult, TournamentUpdate, UserStatus, UserUpdate,
};
pub use svg_pos::SvgPos;
pub use time_signals::TimeSignals;
Expand Down
26 changes: 26 additions & 0 deletions apis/src/common/schedule_action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use shared_types::{GameId, TournamentId};
use std::fmt;
use uuid::Uuid;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ScheduleAction {
Propose(DateTime<Utc>, GameId),
Accept(Uuid),
Cancel(Uuid),
TournamentPublic(TournamentId),
TournamentOwn(TournamentId),
}

impl fmt::Display for ScheduleAction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Propose(date, game_id) => write!(f, "Propose({date}, {game_id})"),
Self::Accept(game_id) => write!(f, "Accept({game_id})"),
Self::Cancel(game_id) => write!(f, "Cancel({game_id})"),
Self::TournamentPublic(id) => write!(f, "TournamentPublic({id})"),
Self::TournamentOwn(id) => write!(f, "TournamentOwn({id})"),
}
}
}
14 changes: 13 additions & 1 deletion apis/src/common/server_result.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use super::game_reaction::GameReaction;
use super::ClientRequest;
use crate::responses::{
ChallengeResponse, GameResponse, HeartbeatResponse, TournamentResponse, UserResponse,
ChallengeResponse, GameResponse, HeartbeatResponse, ScheduleResponse, TournamentResponse,
UserResponse,
};
use http::StatusCode;
use serde::{Deserialize, Serialize};
use shared_types::{ChallengeId, ChatMessageContainer};
use shared_types::{GameId, TournamentId};
use std::collections::HashMap;
use std::fmt;
use uuid::Uuid;

Expand Down Expand Up @@ -53,6 +55,7 @@ pub enum ServerMessage {
// sent to everyone in the game when a user joins the game
Join(UserResponse),
Error(String),
Schedule(ScheduleUpdate),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -107,3 +110,12 @@ pub enum UserStatus {
Offline,
Away,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ScheduleUpdate {
Proposed(ScheduleResponse),
Accepted(ScheduleResponse),
Deleted(ScheduleResponse),
TournamentSchedules(HashMap<GameId, HashMap<Uuid, ScheduleResponse>>),
OwnTournamentSchedules(HashMap<GameId, HashMap<Uuid, ScheduleResponse>>),
}
44 changes: 44 additions & 0 deletions apis/src/components/atoms/date_time_picker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use chrono::{DateTime, Duration, Local, NaiveDateTime, Utc};
use leptos::*;

#[component]
pub fn DateTimePicker(
text: &'static str,
min: DateTime<Local>,
max: DateTime<Local>,
success_callback: Callback<DateTime<Utc>>,
#[prop(optional)] failure_callback: Option<Callback<()>>,
) -> impl IntoView {
view! {
<label>{text}</label>
<input
type="datetime-local"
id="start-time"
name="start-time"
class="p-1 rounded-md"
attr:min=move || { min.format("%Y-%m-%dT%H:%M").to_string() }

attr:max=move || { max.format("%Y-%m-%dT%H:%M").to_string() }

value=(min + Duration::minutes(1)).format("%Y-%m-%dT%H:%M").to_string()
on:input=move |evt| {
if let Ok(date) = NaiveDateTime::parse_from_str(
&event_target_value(&evt),
"%Y-%m-%dT%H:%M",
) {
let dt = Local::now();
let offset = dt.offset();
if let chrono::LocalResult::Single(local) = NaiveDateTime::and_local_timezone(
&date,
*offset,
) {
let utc = local.to_utc();
success_callback(utc);
}
} else if let Some(failure_callback) = failure_callback {
failure_callback(());
}
}
/>
}
}
3 changes: 3 additions & 0 deletions apis/src/components/atoms/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod active;
pub mod create_challenge_button;
pub mod date_time_picker;
pub mod direct_challenge_button;
pub mod download_pgn;
pub mod game_type;
Expand All @@ -17,6 +18,7 @@ pub mod piece;
pub mod profile_link;
pub mod progress_bar;
pub mod rating;
pub mod schedule_controls;
pub mod select_options;
pub mod simple_hex;
pub mod simple_switch;
Expand All @@ -25,3 +27,4 @@ pub mod target;
pub mod title;
pub mod toggle_controls;
pub mod uninvite_button;
// pub mod typed_select_option;
9 changes: 2 additions & 7 deletions apis/src/components/atoms/piece.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,7 @@ pub fn Piece(
// TODO: hand in tile_design and don't get it all the time from config
) -> impl IntoView {
if simple {
return view! {
<PieceWithoutOnClick piece position level />
};
}
view! {
<PieceWithOnClick piece position level piece_type/>
return view! { <PieceWithoutOnClick piece position level/> };
}
.into_view()
view! { <PieceWithOnClick piece position level piece_type/> }.into_view()
}
34 changes: 19 additions & 15 deletions apis/src/components/atoms/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ pub fn ProgressBar(current: Signal<usize>, total: usize) -> impl IntoView {
Signal::derive(move || format!("transform: translateX(-{}%)", 100.0 - progress.get()));
view! {
<Show when=move || { total > 0 }>
<div class="w-4/5">
<span class="font-bold text-md">Progress:</span>
{current}
/
{total}
<ProgressRoot
attr:class="relative overflow-hidden bg-white rounded-full w-full h-[20px] drop-shadow-md"
attr:style="transform: translateZ(0)"
value=progress
>
<ProgressIndicator
attr:class="bg-orange-twilight w-full h-full transition-transform duration-[660ms] ease-[cubic-bezier(0.65, 0, 0.35, 1)]"
attr:style=indicator_style
/>
</ProgressRoot>
<div class="flex flex-col gap-1 justify-center items-center w-full">
<div class="flex gap-1">
<span class="font-bold text-md">Games played:</span>
{current}
/
{total}
</div>
<div class="w-4/5">
<ProgressRoot
attr:class="relative overflow-hidden bg-white rounded-full w-full h-[20px] drop-shadow-md"
attr:style="transform: translateZ(0)"
value=progress
>
<ProgressIndicator
attr:class="bg-orange-twilight w-full h-full transition-transform duration-[660ms] ease-[cubic-bezier(0.65, 0, 0.35, 1)]"
attr:style=indicator_style
/>
</ProgressRoot>
</div>
</div>
</Show>
}
Expand Down
Loading

0 comments on commit a2335ae

Please sign in to comment.