Skip to content

Commit

Permalink
✨ adds points component
Browse files Browse the repository at this point in the history
  • Loading branch information
chriamue committed Jun 15, 2024
1 parent 896ddb0 commit 907a6d0
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "konnektoren-mini-app"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
description = "Telegram Mini App for Konnektoren"

Expand Down
2 changes: 2 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::challenge::ChallengeComp;
use crate::footer::Footer;
use crate::points::PointsComp;
use crate::telegram;
use crate::version::VersionComp;
use crate::wallet::WalletComp;
Expand All @@ -25,6 +26,7 @@ pub fn app() -> Html {
<div>
<h1>{"Konnektoren"}</h1>
<VersionComp />
<PointsComp />
<WalletComp {on_address} />
<ChallengeComp id={"konnektoren-1"} address={(*address).clone()} />
<Footer />
Expand Down
1 change: 1 addition & 0 deletions src/js/telegram.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export function tma_ready() {
console.log(Telegram.WebApp.version);
return Telegram.WebApp.ready();
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod challenge;
pub mod claim;
pub mod footer;
pub mod is_correct;
pub mod points;
pub mod telegram;
pub mod version;
pub mod wallet;
Expand All @@ -11,6 +12,7 @@ pub mod prelude {
pub use crate::app::App;
pub use crate::challenge::{ChallengeComp, ChallengeCompProps};
pub use crate::footer::Footer;
pub use crate::points::PointsComp;
pub use crate::version::VersionComp;
pub use crate::wallet::{WalletComp, WalletCompProps};
}
32 changes: 32 additions & 0 deletions src/points.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::telegram::get_item;
use yew::prelude::*;

#[function_component(PointsComp)]
pub fn points() -> Html {
let points = use_state(|| 0);
{
let points = points.clone();
use_effect(move || {
let points = points.clone();
wasm_bindgen_futures::spawn_local(async move {
match get_item("points").await {
Ok(result) => {
let points_value = result.as_f64().unwrap_or(0.0) as i32;
points.set(points_value);
}
Err(error) => {
log::error!("Error getting points: {:?}", error);
}
}
});
|| ()
});
}

html! {
<div class="points">
<span class="symbol">{"★"}</span>
<span class="value">{*points}</span>
</div>
}
}
1 change: 1 addition & 0 deletions styles/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@forward "claim";
@forward "footer";
@forward "multiple_choice_options";
@forward "points";
@forward "progress_bar";
@forward "result_summary";
@forward "version";
Expand Down
24 changes: 24 additions & 0 deletions styles/components/_points.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.points {
position: fixed;
top: 10px;
right: 10px;
background-color: rgba(240, 240, 240, 0.8);
padding: 10px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
display: vertical;

.value {
font-size: 1.5em;
font-weight: bold;
color: #333;
display: flex;
align-items: center;
}

.symbol {
margin-right: 5px;
color: gold;
font-size: 0.8em;
}
}

0 comments on commit 907a6d0

Please sign in to comment.