Skip to content

Commit 941fd24

Browse files
committed
feat: send a request to the API to track the previous url
1 parent a268f4a commit 941fd24

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/main.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ mod pages;
77

88
use app::*;
99
use leptos::{logging::log, *};
10-
use log::info;
10+
use log::{error, info};
11+
use web_sys::Url;
12+
13+
static API_URL: &str = "https://rust-lang-en-espanol-api.shuttleapp.rs";
1114

1215
pub fn main() {
16+
let _ = create_local_resource(move || (), |_| track_previous_url());
17+
1318
_ = console_log::init_with_level(log::Level::Debug);
1419
console_error_panic_hook::set_once();
1520

@@ -21,3 +26,19 @@ pub fn main() {
2126
view! { <App/> }
2227
});
2328
}
29+
30+
pub async fn track_previous_url() {
31+
let previous_domain = if document().referrer() == "" {
32+
"Undefined".to_owned()
33+
} else {
34+
let address = document().referrer();
35+
let url = Url::new(&address).unwrap();
36+
url.host()
37+
};
38+
39+
let endpoint = format!("{API_URL}/track/count?reference={previous_domain}");
40+
match reqwasm::http::Request::post(&endpoint).send().await {
41+
Ok(_) => log!("Tracking previous url"),
42+
Err(_) => error!("Error tracking previous url"),
43+
};
44+
}

style/output.css

+21
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,10 @@ video {
787787
border-radius: 9999px;
788788
}
789789

790+
.rounded-md {
791+
border-radius: 0.375rem;
792+
}
793+
790794
.rounded-r-full {
791795
border-top-right-radius: 9999px;
792796
border-bottom-right-radius: 9999px;
@@ -852,6 +856,10 @@ video {
852856
background-color: rgb(124 45 18 / var(--tw-bg-opacity));
853857
}
854858

859+
.bg-slate-200\/20 {
860+
background-color: rgb(226 232 240 / 0.2);
861+
}
862+
855863
.bg-white {
856864
--tw-bg-opacity: 1;
857865
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
@@ -869,10 +877,18 @@ video {
869877
fill: currentColor;
870878
}
871879

880+
.p-1 {
881+
padding: 0.25rem;
882+
}
883+
872884
.p-2 {
873885
padding: 0.5rem;
874886
}
875887

888+
.p-4 {
889+
padding: 1rem;
890+
}
891+
876892
.p-6 {
877893
padding: 1.5rem;
878894
}
@@ -959,6 +975,11 @@ video {
959975
line-height: 1;
960976
}
961977

978+
.text-sm {
979+
font-size: 0.875rem;
980+
line-height: 1.25rem;
981+
}
982+
962983
.text-xl {
963984
font-size: 1.25rem;
964985
line-height: 1.75rem;

0 commit comments

Comments
 (0)