From 3fdee5a3a37da027fa4262f376d46ce30fb696ea Mon Sep 17 00:00:00 2001 From: Per Stark Date: Tue, 22 Apr 2025 16:25:30 +0200 Subject: [PATCH] fix: sidebar always shows chat history --- html-router/src/routes/account/handlers.rs | 13 +++++++++++-- html-router/src/routes/admin/handlers.rs | 4 ++++ html-router/src/routes/content/handlers.rs | 11 ++++++++++- html-router/src/routes/index/handlers.rs | 13 +++++++++---- html-router/src/routes/knowledge/handlers.rs | 4 ++++ html-router/templates/index/signed_in/base.html | 2 -- html-router/templates/sidebar.html | 17 ++++++++--------- 7 files changed, 46 insertions(+), 18 deletions(-) diff --git a/html-router/src/routes/account/handlers.rs b/html-router/src/routes/account/handlers.rs index 6aec7dd..abfb39b 100644 --- a/html-router/src/routes/account/handlers.rs +++ b/html-router/src/routes/account/handlers.rs @@ -9,7 +9,7 @@ use crate::{ }, AuthSessionType, }; -use common::storage::types::user::User; +use common::storage::types::{conversation::Conversation, user::User}; use crate::html_state::HtmlState; @@ -17,16 +17,23 @@ use crate::html_state::HtmlState; pub struct AccountPageData { user: User, timezones: Vec, + conversation_archive: Vec, } pub async fn show_account_page( RequireUser(user): RequireUser, + State(state): State, ) -> Result { let timezones = TZ_VARIANTS.iter().map(|tz| tz.to_string()).collect(); + let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?; Ok(TemplateResponse::new_template( "auth/account_settings.html", - AccountPageData { user, timezones }, + AccountPageData { + user, + timezones, + conversation_archive, + }, )) } @@ -54,6 +61,7 @@ pub async fn set_api_key( AccountPageData { user: updated_user, timezones: vec![], + conversation_archive: vec![], }, )) } @@ -103,6 +111,7 @@ pub async fn update_timezone( AccountPageData { user: updated_user, timezones, + conversation_archive: vec![], }, )) } diff --git a/html-router/src/routes/admin/handlers.rs b/html-router/src/routes/admin/handlers.rs index be21237..73cfc62 100644 --- a/html-router/src/routes/admin/handlers.rs +++ b/html-router/src/routes/admin/handlers.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; use common::storage::types::{ analytics::Analytics, + conversation::Conversation, system_prompts::{DEFAULT_INGRESS_ANALYSIS_SYSTEM_PROMPT, DEFAULT_QUERY_SYSTEM_PROMPT}, system_settings::SystemSettings, user::User, @@ -23,6 +24,7 @@ pub struct AdminPanelData { analytics: Analytics, users: i64, default_query_prompt: String, + conversation_archive: Vec, } pub async fn show_admin_panel( @@ -32,6 +34,7 @@ pub async fn show_admin_panel( let settings = SystemSettings::get_current(&state.db).await?; let analytics = Analytics::get_current(&state.db).await?; let users_count = Analytics::get_users_amount(&state.db).await?; + let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?; Ok(TemplateResponse::new_template( "auth/admin_panel.html", @@ -41,6 +44,7 @@ pub async fn show_admin_panel( analytics, users: users_count, default_query_prompt: DEFAULT_QUERY_SYSTEM_PROMPT.to_string(), + conversation_archive, }, )) } diff --git a/html-router/src/routes/content/handlers.rs b/html-router/src/routes/content/handlers.rs index 58713d8..6c11a6e 100644 --- a/html-router/src/routes/content/handlers.rs +++ b/html-router/src/routes/content/handlers.rs @@ -6,7 +6,9 @@ use axum::{ use axum_htmx::{HxBoosted, HxRequest}; use serde::{Deserialize, Serialize}; -use common::storage::types::{file_info::FileInfo, text_content::TextContent, user::User}; +use common::storage::types::{ + conversation::Conversation, file_info::FileInfo, text_content::TextContent, user::User, +}; use crate::{ html_state::HtmlState, @@ -22,6 +24,7 @@ pub struct ContentPageData { text_contents: Vec, categories: Vec, selected_category: Option, + conversation_archive: Vec, } #[derive(Deserialize)] @@ -48,11 +51,13 @@ pub async fn show_content_page( User::get_text_contents(&user.id, &state.db).await? }; + let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?; let data = ContentPageData { user, text_contents, categories, selected_category: params.category.clone(), + conversation_archive, }; if is_htmx && !is_boosted && has_category_param { @@ -112,6 +117,7 @@ pub async fn patch_text_content( let text_contents = User::get_text_contents(&user.id, &state.db).await?; let categories = User::get_user_categories(&user.id, &state.db).await?; + let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?; Ok(TemplateResponse::new_partial( "content/base.html", @@ -121,6 +127,7 @@ pub async fn patch_text_content( text_contents, categories, selected_category: None, + conversation_archive, }, )) } @@ -144,6 +151,7 @@ pub async fn delete_text_content( // Get updated content, categories and return the refreshed list let text_contents = User::get_text_contents(&user.id, &state.db).await?; let categories = User::get_user_categories(&user.id, &state.db).await?; + let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?; Ok(TemplateResponse::new_template( "content/content_list.html", @@ -152,6 +160,7 @@ pub async fn delete_text_content( text_contents, categories, selected_category: None, + conversation_archive, }, )) } diff --git a/html-router/src/routes/index/handlers.rs b/html-router/src/routes/index/handlers.rs index 6a96a88..33f5ce5 100644 --- a/html-router/src/routes/index/handlers.rs +++ b/html-router/src/routes/index/handlers.rs @@ -15,9 +15,9 @@ use crate::{ use common::{ error::AppError, storage::types::{ - file_info::FileInfo, ingestion_task::IngestionTask, knowledge_entity::KnowledgeEntity, - knowledge_relationship::KnowledgeRelationship, text_chunk::TextChunk, - text_content::TextContent, user::User, + conversation::Conversation, file_info::FileInfo, ingestion_task::IngestionTask, + knowledge_entity::KnowledgeEntity, knowledge_relationship::KnowledgeRelationship, + text_chunk::TextChunk, text_content::TextContent, user::User, }, }; @@ -28,6 +28,7 @@ pub struct IndexPageData { user: Option, latest_text_contents: Vec, active_jobs: Vec, + conversation_archive: Vec, } pub async fn index_handler( @@ -41,13 +42,16 @@ pub async fn index_handler( user: None, latest_text_contents: vec![], active_jobs: vec![], + conversation_archive: vec![], }, )); }; let active_jobs = User::get_unfinished_ingestion_tasks(&user.id, &state.db).await?; - let latest_text_contents = User::get_latest_text_contents(user.id.as_str(), &state.db).await?; + let latest_text_contents = User::get_latest_text_contents(&user.id, &state.db).await?; + + let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?; Ok(TemplateResponse::new_template( "index/index.html", @@ -55,6 +59,7 @@ pub async fn index_handler( user: Some(user), latest_text_contents, active_jobs, + conversation_archive, }, )) } diff --git a/html-router/src/routes/knowledge/handlers.rs b/html-router/src/routes/knowledge/handlers.rs index 2aea9af..6d0725d 100644 --- a/html-router/src/routes/knowledge/handlers.rs +++ b/html-router/src/routes/knowledge/handlers.rs @@ -14,6 +14,7 @@ use plotly::{ use serde::{Deserialize, Serialize}; use common::storage::types::{ + conversation::Conversation, knowledge_entity::{KnowledgeEntity, KnowledgeEntityType}, knowledge_relationship::KnowledgeRelationship, user::User, @@ -43,6 +44,7 @@ pub struct KnowledgeBaseData { content_categories: Vec, selected_entity_type: Option, selected_content_category: Option, + conversation_archive: Vec, } pub async fn show_knowledge_page( @@ -76,6 +78,7 @@ pub async fn show_knowledge_page( let relationships = User::get_knowledge_relationships(&user.id, &state.db).await?; let plot_html = get_plot_html(&entities, &relationships)?; + let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?; let kb_data = KnowledgeBaseData { entities, @@ -86,6 +89,7 @@ pub async fn show_knowledge_page( content_categories, selected_entity_type: params.entity_type.clone(), selected_content_category: params.content_category.clone(), + conversation_archive, }; // Determine response type: diff --git a/html-router/templates/index/signed_in/base.html b/html-router/templates/index/signed_in/base.html index 82f183f..8bc8506 100644 --- a/html-router/templates/index/signed_in/base.html +++ b/html-router/templates/index/signed_in/base.html @@ -2,8 +2,6 @@
{% include 'index/signed_in/searchbar.html' %} - {% include "index/signed_in/quick_actions.html" %} -
{% include "index/signed_in/active_jobs.html" %} diff --git a/html-router/templates/sidebar.html b/html-router/templates/sidebar.html index 2c40076..208b900 100644 --- a/html-router/templates/sidebar.html +++ b/html-router/templates/sidebar.html @@ -82,19 +82,18 @@
  • - + {% include "icons/user_icon.html" %} Account
  • -
    -
  • - -
  • -
    +
  • + + {% include "icons/logout_icon.html" %} + Logout + +
  • \ No newline at end of file