Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWA logo config and host state #637

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
87 changes: 0 additions & 87 deletions ssr/public/app.webmanifest

This file was deleted.

23 changes: 23 additions & 0 deletions ssr/public/hotornot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"short_name": "HotOrNot",
"name": "Hot Or Not",
"description": "Vote on the hottest content and earn rewards",
"icons": [
{
"src": "/img/hotornot/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/img/hotornot/android-chrome-384x384.png",
"sizes": "384x384",
"type": "image/png"
}
],
"theme_color": "#FF4500",
"background_color": "#000",
"start_url": "/",
"display": "standalone",
"orientation": "portrait",
"scope": "/"
}
23 changes: 23 additions & 0 deletions ssr/public/icpump.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"short_name": "ICPump",
"name": "ICPump Token Platform",
"description": "Create and trade tokens on the Internet Computer",
"icons": [
{
"src": "/img/icpump/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/img/icpump/android-chrome-384x384.png",
"sizes": "384x384",
"type": "image/png"
}
],
"theme_color": "#4CAF50",
"background_color": "#000",
"start_url": "/board",
"display": "standalone",
"orientation": "portrait",
"scope": "/"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ssr/public/img/icpump/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ssr/public/img/icpump/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions ssr/public/yral.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"short_name": "Yral",
"name": "Yral Platform",
"description": "The First App to Host Creative Short Video Challenges - Participate, Speculate, Gain Fame, Earn In Cryptocurrency",
"icons": [
{
"src": "/img/yral/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/img/yral/android-chrome-384x384.png",
"sizes": "384x384",
"type": "image/png"
}
],
"theme_color": "#E20479",
"background_color": "#000",
"start_url": "/",
"display": "standalone",
"orientation": "portrait",
"scope": "/"
}
66 changes: 42 additions & 24 deletions ssr/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::page::icpump::ai::ICPumpAi;
use crate::page::icpump::ICPumpLanding;

use crate::state::app_type::AppType;
use crate::utils::host::show_preview_component;
// use crate::page::wallet::TestIndex;
use crate::state::app_state::AppState;
use crate::{
component::{base_route::BaseRoute, nav::NavBar},
error_template::{AppError, ErrorTemplate},
Expand Down Expand Up @@ -81,10 +82,30 @@ fn GoogleAuthRedirectorRoute() -> impl IntoView {
}
}

fn get_app_type() -> AppType {
#[cfg(feature = "hydrate")]
{
let hostname = window().location().hostname().unwrap_or_default();
AppType::from_host(&hostname)
}

#[cfg(not(feature = "hydrate"))]
{
use crate::utils::host::get_host;
let host = get_host();
AppType::from_host(&host)
}
}

#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();

let app_type = get_app_type();
let app_state = AppState::from_type(&app_type);
provide_context(app_state.clone());

// Existing context providers
provide_context(Canisters::default());
provide_context(ContentSeedClient::default());
provide_context(PostViewCtx::default());
Expand Down Expand Up @@ -116,35 +137,32 @@ pub fn App() -> impl IntoView {
}

view! {
<Stylesheet id="leptos" href="/pkg/hot-or-not-leptos-ssr.css"/>

// sets the document title
<Title text="Yral"/>

<Link rel="manifest" href="/app.webmanifest"/>

// GA4 Global Site Tag (gtag.js) - Google Analytics
// G-6W5Q2MRX0E to test locally | G-PLNNETMSLM
<Show when=enable_ga4_script>
<Script
async_="true"
src=concat!("https://www.googletagmanager.com/gtag/js?id=", "G-PLNNETMSLM")
/>
<Script>
{r#"
<Stylesheet id="leptos" href="/pkg/hot-or-not-leptos-ssr.css"/>
<Title text=app_state.name/>
<Link rel="manifest" href=app_state.manifest_config()/>

// GA4 Global Site Tag (gtag.js) - Google Analytics
// G-6W5Q2MRX0E to test locally | G-PLNNETMSLM
<Show when=enable_ga4_script>
<Script
async_="true"
src=concat!("https://www.googletagmanager.com/gtag/js?id=", "G-PLNNETMSLM")
/>
<Script>
{r#"
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-PLNNETMSLM');
"#}
</Script>
</Show>
</Script>
</Show>

// <Script src="https://www.gstatic.com/firebasejs/10.14.1/firebase-app.js"></Script>
// <Script src="https://www.gstatic.com/firebasejs/10.14.1/firebase-firestore.js"></Script>
// <Script src="https://www.gstatic.com/firebasejs/10.14.1/firebase-app.js"></Script>
// <Script src="https://www.gstatic.com/firebasejs/10.14.1/firebase-firestore.js"></Script>

// content for this welcome page
<Router fallback=|| view! { <NotFound/> }.into_view()>
// content for this welcome page
<Router fallback=|| view! { <NotFound/> }.into_view()>
<main>
<Routes>
// auth redirect routes exist outside main context
Expand Down
46 changes: 46 additions & 0 deletions ssr/src/state/app_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use super::app_type::AppType;

#[derive(Clone)]
pub struct AppState {
pub app_type: AppType,
pub id: &'static str,
pub name: &'static str,
pub description: &'static str,
pub theme_color: &'static str,
pub manifest_path: &'static str,
}

impl AppState {
pub fn from_type(app_type: &AppType) -> Self {
match app_type {
AppType::HotOrNot => Self {
app_type: AppType::HotOrNot,
id: "hotornot",
name: "Hot Or Not",
description: "Vote on the hottest content and earn rewards",
theme_color: "#FF4500",
manifest_path: "hotornot.json",
},
AppType::ICPump => Self {
app_type: AppType::ICPump,
id: "icpump",
name: "ICPump Token Platform",
description: "Create and trade tokens on the Internet Computer",
theme_color: "#4CAF50",
manifest_path: "icpump.json",
},
AppType::YRAL => Self {
app_type: AppType::YRAL,
id: "yral",
name: "YRAL Platform",
description: "The First App to Host Creative Short Video Challenges",
theme_color: "#E20479",
manifest_path: "yral.json",
},
}
}

pub fn manifest_config(&self) -> &'static str {
self.manifest_path
}
}
18 changes: 18 additions & 0 deletions ssr/src/state/app_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[derive(Clone, Debug, PartialEq)]
pub enum AppType {
YRAL,
HotOrNot,
ICPump,
}

impl AppType {
pub fn from_host(host: &str) -> Self {
if host.contains("hotornot") {
AppType::HotOrNot
} else if host.contains("icpump") {
AppType::ICPump
} else {
AppType::YRAL
}
}
}
2 changes: 2 additions & 0 deletions ssr/src/state/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(feature = "backend-admin")]
pub mod admin_canisters;
pub mod app_state;
pub mod app_type;
pub mod audio_state;
pub mod auth;
pub mod canisters;
Expand Down