142 lines
4.9 KiB
Rust
142 lines
4.9 KiB
Rust
use crate::components::error_template::{AppError, ErrorTemplate};
|
|
use crate::components::playbar::CustomTitle;
|
|
use crate::components::playbar::PlayBar;
|
|
use crate::components::queue::Queue;
|
|
use crate::pages::album::*;
|
|
use crate::pages::artist::*;
|
|
use crate::pages::dashboard::*;
|
|
use crate::pages::liked_songs::*;
|
|
use crate::pages::login::*;
|
|
use crate::pages::playlist::*;
|
|
use crate::pages::profile::*;
|
|
use crate::pages::search::*;
|
|
use crate::pages::signup::*;
|
|
use crate::pages::song::*;
|
|
use crate::util::state::GlobalState;
|
|
use leptos::prelude::*;
|
|
use leptos_meta::*;
|
|
use leptos_router::components::*;
|
|
use leptos_router::*;
|
|
|
|
pub fn shell(options: LeptosOptions) -> impl IntoView {
|
|
view! {
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<AutoReload options=options.clone() />
|
|
<HydrationScripts options/>
|
|
<MetaTags/>
|
|
</head>
|
|
<body>
|
|
<App/>
|
|
</body>
|
|
</html>
|
|
}
|
|
}
|
|
|
|
#[component]
|
|
pub fn App() -> impl IntoView {
|
|
// Provides context that manages stylesheets, titles, meta tags, etc.
|
|
provide_meta_context();
|
|
|
|
provide_context(GlobalState::new());
|
|
|
|
let upload_open = RwSignal::new(false);
|
|
let add_artist_open = RwSignal::new(false);
|
|
let add_album_open = RwSignal::new(false);
|
|
|
|
view! {
|
|
// injects a stylesheet into the document <head>
|
|
// id=leptos means cargo-leptos will hot-reload this stylesheet
|
|
<Stylesheet id="leptos" href="/pkg/libretunes.css"/>
|
|
|
|
// sets the document title
|
|
<CustomTitle />
|
|
|
|
// content for this welcome page
|
|
<Router>
|
|
<main>
|
|
<Routes fallback=|| {
|
|
let mut outside_errors = Errors::default();
|
|
outside_errors.insert_with_default_key(AppError::NotFound);
|
|
view! {
|
|
<ErrorTemplate outside_errors/>
|
|
}
|
|
.into_view()
|
|
}>
|
|
<ParentRoute path=path!("") view=move || view! { <HomePage upload_open=upload_open add_artist_open=add_artist_open add_album_open=add_album_open/> }>
|
|
<Route path=path!("") view=Dashboard />
|
|
<Route path=path!("dashboard") view=Dashboard />
|
|
<Route path=path!("search") view=Search />
|
|
<Route path=path!("user/:id") view=Profile />
|
|
<Route path=path!("user") view=Profile />
|
|
<Route path=path!("album/:id") view=AlbumPage />
|
|
<Route path=path!("artist/:id") view=ArtistPage />
|
|
<Route path=path!("song/:id") view=SongPage />
|
|
<Route path=path!("playlist/:id") view=PlaylistPage />
|
|
<Route path=path!("liked") view=LikedSongsPage />
|
|
</ParentRoute>
|
|
<Route path=path!("/login") view=Login />
|
|
<Route path=path!("/signup") view=Signup />
|
|
</Routes>
|
|
</main>
|
|
</Router>
|
|
}
|
|
}
|
|
|
|
use crate::components::add_album::AddAlbum;
|
|
use crate::components::add_artist::AddArtist;
|
|
use crate::components::personal::Personal;
|
|
use crate::components::sidebar::*;
|
|
use crate::components::upload::*;
|
|
|
|
/// Renders the home page of your application.
|
|
#[component]
|
|
fn HomePage(
|
|
upload_open: RwSignal<bool>,
|
|
add_artist_open: RwSignal<bool>,
|
|
add_album_open: RwSignal<bool>,
|
|
) -> impl IntoView {
|
|
view! {
|
|
<section class="bg-black h-screen flex">
|
|
<Upload open=upload_open/>
|
|
<AddArtist open=add_artist_open/>
|
|
<AddAlbum open=add_album_open/>
|
|
<Sidebar upload_open=upload_open add_artist_open=add_artist_open add_album_open=add_album_open/>
|
|
// This <Outlet /> will render the child route components
|
|
<div class="flex flex-col flex-grow min-w-0">
|
|
<div class="home-card">
|
|
<Outlet />
|
|
</div>
|
|
</div>
|
|
<Personal />
|
|
<Queue />
|
|
<PlayBar />
|
|
</section>
|
|
}
|
|
}
|
|
|
|
/// 404 - Not Found
|
|
#[component]
|
|
fn NotFound() -> impl IntoView {
|
|
// set an HTTP status code 404
|
|
// this is feature gated because it can only be done during
|
|
// initial server-side rendering
|
|
// if you navigate to the 404 page subsequently, the status
|
|
// code will not be set because there is not a new HTTP request
|
|
// to the server
|
|
#[cfg(feature = "ssr")]
|
|
{
|
|
// this can be done inline because it's synchronous
|
|
// if it were async, we'd use a server function
|
|
let resp = expect_context::<leptos_axum::ResponseOptions>();
|
|
resp.set_status(axum::http::StatusCode::NOT_FOUND);
|
|
}
|
|
|
|
view! {
|
|
<h1>"Not Found"</h1>
|
|
}
|
|
}
|