Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ssr/src/page/src/post_view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub fn PostView() -> impl IntoView {
.max_age(consts::auth::REFRESH_MAX_AGE.as_secs() as i64)
.same_site(leptos_use::SameSite::Lax),
);
Effect::new(move |_| {
Effect::new_isomorphic(move |_| {
if home_page_viewed_sent.get_untracked() {
return;
}
Expand Down
9 changes: 7 additions & 2 deletions ssr/src/page/src/root.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use candid::Principal;
use codee::string::FromToStringCodec;
use component::spinner::FullScreenSpinner;
use consts::NSFW_ENABLED_COOKIE;
use consts::{NSFW_ENABLED_COOKIE, USER_PRINCIPAL_STORE};
use leptos::prelude::*;
use leptos_meta::*;
use leptos_router::components::Redirect;
use leptos_router::hooks::use_query_map;
use leptos_use::{use_cookie_with_options, UseCookieOptions};
use leptos_use::{use_cookie, use_cookie_with_options, UseCookieOptions};
use utils::host::show_nsfw_content;
use utils::mixpanel::mixpanel_events::init_event;
use utils::ml_feed::{get_ml_feed_coldstart_clean, get_ml_feed_coldstart_nsfw};
use yral_types::post::PostItemV3;

Expand Down Expand Up @@ -61,6 +62,8 @@ pub fn YralRootPage() -> impl IntoView {
.same_site(leptos_use::SameSite::Lax),
);

let (user_principal, _) = use_cookie::<Principal, FromToStringCodec>(USER_PRINCIPAL_STORE);

let full_info = Resource::new_blocking(params, move |params_map| async move {
// Check query param first, then cookie, then show_nsfw_content
let nsfw_from_query = params_map.get("nsfw").map(|s| s == "true").unwrap_or(false);
Expand All @@ -71,6 +74,8 @@ pub fn YralRootPage() -> impl IntoView {
"NSFW enabled: {nsfw_enabled} (query: {nsfw_from_query}, cookie: {:?})",
nsfw_cookie_enabled.get_untracked()
);
let user_principal = user_principal.get_untracked().map(|f| f.to_text());
init_event(user_principal).await;
let post = if nsfw_enabled {
get_top_post_id_global_nsfw_feed().await
} else {
Expand Down
2 changes: 1 addition & 1 deletion ssr/src/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub mod event_streaming;
pub mod health;
pub mod host;
pub mod icon;
pub mod local_storage;
pub mod mixpanel;
pub mod ml_feed;
pub mod notifications;
Expand All @@ -19,6 +18,7 @@ pub mod qstash;
pub mod report;
pub mod route;
pub mod sentry;
pub mod storage;
pub mod time;
pub mod types;
pub mod web;
Expand Down
19 changes: 0 additions & 19 deletions ssr/src/utils/src/local_storage.rs

This file was deleted.

19 changes: 16 additions & 3 deletions ssr/src/utils/src/mixpanel/mixpanel_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::mixpanel::state::MixpanelState;

#[server]
async fn track_event_server_fn(props: Value) -> Result<(), ServerFnError> {
leptos::logging::log!("Init event served");
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug log message is misleading as it appears in the general track_event_server_fn function, not specifically for init events. This will log for all events tracked through this function, which could be confusing when debugging.

Suggested change
leptos::logging::log!("Init event served");
leptos::logging::log!("Event tracked via track_event_server_fn");

Copilot uses AI. Check for mistakes.
use axum::http::HeaderMap;
use axum_extra::headers::UserAgent;
use axum_extra::TypedHeader;
Expand Down Expand Up @@ -130,10 +131,23 @@ pub fn parse_query_params_utm() -> Result<Vec<(String, String)>, String> {
Ok(Vec::new())
}

pub async fn init_event(user_principal: Option<String>) {
leptos::logging::log!("Init event {:?})", user_principal);
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing closing quote in the log message format string. It should be "Init event {:?})""Init event {:?}".

Suggested change
leptos::logging::log!("Init event {:?})", user_principal);
leptos::logging::log!("Init event {:?}", user_principal);

Copilot uses AI. Check for mistakes.
let mut props = Value::Object(serde_json::Map::new());
props["event"] = "init".into();
if let Some(user_principal) = user_principal {
props["principal"] = user_principal.into();
}
props["$device_id"] = MixpanelGlobalProps::get_device_id().into();
props["custom_device_id"] = MixpanelGlobalProps::get_custom_device_id().into();
let _ = track_event_server_fn(props).await;
}

pub(super) fn send_event_to_server<T>(event_name: &str, props: T)
where
T: Serialize,
{
logging::log!("Sending Mixpanel event: {}", event_name);
let payload = get_event_payload(event_name, props);
spawn_local(async {
let res = track_event_server_fn(payload).await;
Expand Down Expand Up @@ -273,7 +287,7 @@ impl MixpanelGlobalProps {
if let Some(device_id) = device_id.get_untracked() {
device_id
} else {
let device_id_val = crate::local_storage::LocalStorage::uuid_get_or_init(DEVICE_ID);
let device_id_val = crate::storage::Storage::uuid_get_or_init(DEVICE_ID);
device_id.set(Some(device_id_val.clone()));
device_id_val
}
Expand All @@ -284,8 +298,7 @@ impl MixpanelGlobalProps {
if let Some(custom_device_id) = custom_device_id.get_untracked() {
custom_device_id
} else {
let custom_device_id_val =
crate::local_storage::LocalStorage::uuid_get_or_init(CUSTOM_DEVICE_ID);
let custom_device_id_val = crate::storage::Storage::uuid_get_or_init(CUSTOM_DEVICE_ID);
custom_device_id.set(Some(custom_device_id_val.clone()));
custom_device_id_val
}
Expand Down
25 changes: 25 additions & 0 deletions ssr/src/utils/src/storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use codee::string::FromToStringCodec;
use consts::AUTH_UTIL_COOKIES_MAX_AGE_MS;
use leptos::prelude::*;
use leptos_use::{use_cookie_with_options, UseCookieOptions};

pub struct Storage;

impl Storage {
pub fn uuid_get_or_init(key: &str) -> String {
let (uuid, set_uuid) = use_cookie_with_options::<String, FromToStringCodec>(
key,
UseCookieOptions::default()
.path("/")
.max_age(AUTH_UTIL_COOKIES_MAX_AGE_MS),
);
let uuid_value = uuid.get_untracked();
if let Some(uuid) = uuid_value {
uuid
Comment on lines +17 to +18
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function logic is inconsistent with the removed LocalStorage implementation. The original code checked uuid_value.is_empty() for an empty string, but this code checks for None. This could cause issues if cookies return empty strings instead of None, leading to unnecessary UUID regeneration.

Suggested change
if let Some(uuid) = uuid_value {
uuid
if let Some(ref uuid) = uuid_value {
if !uuid.is_empty() {
uuid.clone()
} else {
let new_device_id = uuid::Uuid::new_v4().to_string();
set_uuid.set(Some(new_device_id.clone()));
new_device_id
}

Copilot uses AI. Check for mistakes.
} else {
let new_device_id = uuid::Uuid::new_v4().to_string();
set_uuid.set(Some(new_device_id.clone()));
new_device_id
}
}
}