feat: add information and update chunk loading

This commit is contained in:
PandaDEV 2024-12-16 23:38:35 +10:00
parent c48a0d8239
commit 149e72802c
No known key found for this signature in database
GPG key ID: 13EFF9BAF70EE75C
7 changed files with 435 additions and 151 deletions

View file

@ -28,7 +28,7 @@ pub async fn initialize_history(pool: &SqlitePool) -> Result<(), Box<dyn std::er
#[tauri::command]
pub async fn get_history(pool: tauri::State<'_, SqlitePool>) -> Result<Vec<HistoryItem>, String> {
let rows = sqlx::query(
"SELECT id, source, source_icon, content_type, content, favicon, timestamp FROM history ORDER BY timestamp DESC",
"SELECT id, source, source_icon, content_type, content, favicon, timestamp, language FROM history ORDER BY timestamp DESC",
)
.fetch_all(&*pool)
.await
@ -44,6 +44,7 @@ pub async fn get_history(pool: tauri::State<'_, SqlitePool>) -> Result<Vec<Histo
content: row.get("content"),
favicon: row.get("favicon"),
timestamp: row.get("timestamp"),
language: row.get("language"),
})
.collect();
@ -55,7 +56,8 @@ pub async fn add_history_item(
pool: tauri::State<'_, SqlitePool>,
item: HistoryItem,
) -> Result<(), String> {
let (id, source, source_icon, content_type, content, favicon, timestamp) = item.to_row();
let (id, source, source_icon, content_type, content, favicon, timestamp, language) =
item.to_row();
let last_content: Option<String> = sqlx::query_scalar(
"SELECT content FROM history WHERE content_type = ? ORDER BY timestamp DESC LIMIT 1",
@ -70,7 +72,7 @@ pub async fn add_history_item(
}
sqlx::query(
"INSERT INTO history (id, source, source_icon, content_type, content, favicon, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?)"
"INSERT INTO history (id, source, source_icon, content_type, content, favicon, timestamp, language) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
)
.bind(id)
.bind(source)
@ -79,6 +81,7 @@ pub async fn add_history_item(
.bind(content)
.bind(favicon)
.bind(timestamp)
.bind(language)
.execute(&*pool)
.await
.map_err(|e| e.to_string())?;
@ -93,7 +96,7 @@ pub async fn search_history(
) -> Result<Vec<HistoryItem>, String> {
let query = format!("%{}%", query);
let rows = sqlx::query(
"SELECT id, source, source_icon, content_type, content, favicon, timestamp FROM history WHERE content LIKE ? ORDER BY timestamp DESC"
"SELECT id, source, source_icon, content_type, content, favicon, timestamp, language FROM history WHERE content LIKE ? ORDER BY timestamp DESC"
)
.bind(query)
.fetch_all(&*pool)
@ -110,6 +113,7 @@ pub async fn search_history(
content: row.get("content"),
favicon: row.get("favicon"),
timestamp: row.get("timestamp"),
language: row.get("language"),
})
.collect();
@ -123,7 +127,7 @@ pub async fn load_history_chunk(
limit: i64,
) -> Result<Vec<HistoryItem>, String> {
let rows = sqlx::query(
"SELECT id, source, source_icon, content_type, content, favicon, timestamp FROM history ORDER BY timestamp DESC LIMIT ? OFFSET ?"
"SELECT id, source, source_icon, content_type, content, favicon, timestamp, language FROM history ORDER BY timestamp DESC LIMIT ? OFFSET ?"
)
.bind(limit)
.bind(offset)
@ -141,6 +145,7 @@ pub async fn load_history_chunk(
content: row.get("content"),
favicon: row.get("favicon"),
timestamp: row.get("timestamp"),
language: row.get("language"),
})
.collect();