Skip to content

Commit

Permalink
render sidebar once
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszKielar committed Apr 25, 2024
1 parent bd07673 commit c6de653
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 40 deletions.
21 changes: 15 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use leptos::*;
use leptos_meta::*;
use leptos_router::*;

use crate::frontend::views::{Chat, Home, NotFound};
use crate::frontend::{
components::Sidebar,
views::{Chat, Home},
};

#[component]
pub fn App() -> impl IntoView {
Expand All @@ -15,11 +18,17 @@ pub fn App() -> impl IntoView {
<Meta charset="UTF-8"/>
<Router>
<main>
<Routes>
<Route path="/" view=Home/>
<Route path="/c/:id" view=Chat/>
<Route path="/*any" view=NotFound/>
</Routes>
<div class="overflow-hidden w-full h-screen relative flex">
<div class="dark hidden flex-shrink-0 bg-gray-900 md:flex md:w-[260px] md:flex-col">
<div class="flex h-full min-h-0 flex-col ">
<Sidebar/>
</div>
</div>
<Routes>
<Route path="/" view=Home/>
<Route path="/c/:id" view=Chat/>
</Routes>
</div>
</main>
</Router>
}
Expand Down
13 changes: 2 additions & 11 deletions src/frontend/views/chat.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
use leptos::*;

use crate::frontend::components::{Conversation, Sidebar};
use crate::frontend::components::Conversation;

#[component]
pub(crate) fn Chat() -> impl IntoView {
view! {
<div class="overflow-hidden w-full h-screen relative flex">
<div class="dark hidden flex-shrink-0 bg-gray-900 md:flex md:w-[260px] md:flex-col">
<div class="flex h-full min-h-0 flex-col ">
<Sidebar/>
</div>
</div>
<Conversation/>
</div>
}
view! { <Conversation/> }
}
15 changes: 4 additions & 11 deletions src/frontend/views/home.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
use leptos::*;

use crate::frontend::components::{Conversation, Sidebar};

// TODO: create sidebar once and pass it as a context in the app
#[component]
pub(crate) fn Home() -> impl IntoView {
view! {
<div class="overflow-hidden w-full h-screen relative flex">
<div class="dark hidden flex-shrink-0 bg-gray-900 md:flex md:w-[260px] md:flex-col">
<div class="flex h-full min-h-0 flex-col ">
<Sidebar/>
</div>
</div>
// TODO: create NewConversation view
// <Conversation/>
<div class="flex max-w-full dark:bg-gray-800">
<div class="h-10">A</div>
<div class="h-10">B</div>
<div class="h-10">C</div>
</div>
}
}
2 changes: 0 additions & 2 deletions src/frontend/views/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod chat;
mod home;
mod not_found;

pub(crate) use chat::Chat;
pub(crate) use home::Home;
pub(crate) use not_found::NotFound;
10 changes: 0 additions & 10 deletions src/frontend/views/not_found.rs

This file was deleted.

3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ async fn main() {
use std::env;
use std::str::FromStr;

use axum::response::Redirect;
use axum::routing::get;
use axum::Router;
use leptos::*;
Expand Down Expand Up @@ -75,6 +76,8 @@ async fn main() {
)
.route("/pkg/*path", get(file_and_error_handler))
.route("/favicon.ico", get(file_and_error_handler))
// TODO: I should add static html for all not found
.route("/*any", get(|| async { Redirect::permanent("/") }))
.leptos_routes_with_handler(routes, get(leptos_routes_handler))
.fallback(file_and_error_handler)
.with_state(app_state);
Expand Down

0 comments on commit c6de653

Please sign in to comment.