fix: sidebar always shows chat history

This commit is contained in:
Per Stark
2025-04-22 16:25:30 +02:00
parent 0c09b13a38
commit 3fdee5a3a3
7 changed files with 46 additions and 18 deletions

View File

@@ -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<String>,
conversation_archive: Vec<Conversation>,
}
pub async fn show_account_page(
RequireUser(user): RequireUser,
State(state): State<HtmlState>,
) -> Result<impl IntoResponse, HtmlError> {
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![],
},
))
}

View File

@@ -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<Conversation>,
}
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,
},
))
}

View File

@@ -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<TextContent>,
categories: Vec<String>,
selected_category: Option<String>,
conversation_archive: Vec<Conversation>,
}
#[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,
},
))
}

View File

@@ -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<User>,
latest_text_contents: Vec<TextContent>,
active_jobs: Vec<IngestionTask>,
conversation_archive: Vec<Conversation>,
}
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,
},
))
}

View File

@@ -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<String>,
selected_entity_type: Option<String>,
selected_content_category: Option<String>,
conversation_archive: Vec<Conversation>,
}
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:

View File

@@ -2,8 +2,6 @@
<div class="container">
{% include 'index/signed_in/searchbar.html' %}
{% include "index/signed_in/quick_actions.html" %}
<div class="grid grid-cols-1 md:grid-cols-2 shadow my-10">
{% include "index/signed_in/active_jobs.html" %}

View File

@@ -82,19 +82,18 @@
<div class="px-2 pb-4">
<div class="divider "></div>
<li>
<a hx-boost="true" href="/account" class="flex items-center gap-3">
<a hx-boost="true" href="/account" class="flex btn btn-ghost justify-start items-center gap-3">
{% include "icons/user_icon.html" %}
<span>Account</span>
</a>
</li>
<form action="/signout" method="get" class="w-full block">
<li>
<button type="submit" class="btn btn-error btn-outline w-full flex items-center gap-3 justify-start !mt-1">
{% include "icons/logout_icon.html" %}
<span>Logout</span>
</button>
</li>
</form>
<li>
<a hx-boost="true" href="/signout"
class="btn btn-error btn-outline w-full flex items-center gap-3 justify-start !mt-1">
{% include "icons/logout_icon.html" %}
<span>Logout</span>
</a>
</li>
</div>
</ul>
</div>