slack status without the slack status.zzstoatzz.io/
quickslice

feed(api): return object {statuses, has_more, next_offset}; implement offset/limit pagination; frontend handles object form

+24 -4
+17 -3
src/api/status_read.rs
··· 355 355 pub async fn api_feed( 356 356 db_pool: web::Data<Arc<Pool>>, 357 357 handle_resolver: web::Data<HandleResolver>, 358 + query: web::Query<std::collections::HashMap<String, String>>, 358 359 ) -> Result<impl Responder> { 359 - // Simple paginated feed (offset/limit defaulted) 360 - let statuses = StatusFromDb::load_latest_statuses(&db_pool) 360 + // Paginated feed 361 + let offset = query 362 + .get("offset") 363 + .and_then(|s| s.parse::<i32>().ok()) 364 + .unwrap_or(0); 365 + let limit = query 366 + .get("limit") 367 + .and_then(|s| s.parse::<i32>().ok()) 368 + .unwrap_or(20) 369 + .clamp(5, 50); 370 + 371 + let statuses = StatusFromDb::load_statuses_paginated(&db_pool, offset, limit) 361 372 .await 362 373 .unwrap_or_default(); 363 374 let mut enriched = Vec::with_capacity(statuses.len()); ··· 371 382 } 372 383 enriched.push(s); 373 384 } 374 - Ok(web::Json(json!({ "statuses": enriched }))) 385 + let has_more = (enriched.len() as i32) == limit; 386 + Ok(web::Json( 387 + json!({ "statuses": enriched, "has_more": has_more, "next_offset": offset + (enriched.len() as i32) }), 388 + )) 375 389 } 376 390 377 391 #[get("/api/frequent-emojis")]
+1
src/db/models.rs
··· 150 150 } 151 151 152 152 /// Loads the last 10 statuses we have saved 153 + #[allow(dead_code)] 153 154 pub async fn load_latest_statuses( 154 155 pool: &Data<Arc<Pool>>, 155 156 ) -> Result<Vec<Self>, async_sqlite::Error> {
+6 -1
templates/feed.html
··· 965 965 966 966 try { 967 967 const response = await fetch(`/api/feed?offset=${offset}&limit=20`); 968 - const newStatuses = await response.json(); 968 + const data = await response.json(); 969 + const newStatuses = Array.isArray(data) ? data : (data.statuses || []); 969 970 970 971 if (newStatuses.length === 0) { 971 972 hasMore = false; ··· 1036 1037 } 1037 1038 1038 1039 offset += newStatuses.length; 1040 + if (!Array.isArray(data) && typeof data === 'object') { 1041 + if (typeof data.next_offset === 'number') offset = data.next_offset; 1042 + if (typeof data.has_more === 'boolean') hasMore = data.has_more; 1043 + } 1039 1044 loadingIndicator.style.display = 'none'; 1040 1045 } catch (error) { 1041 1046 console.error('Error loading more statuses:', error);