feat(home): limit open bags to 3 most recently updated
- Add UpdatedAt variant to BagSortKey - Sort home page bags by updated_at desc instead of roast_date - Limit to 3 bags instead of showing all open bags
This commit is contained in:
parent
d15d58b32c
commit
f3a4cc7075
3 changed files with 10 additions and 1 deletions
|
|
@ -60,7 +60,12 @@ async fn load_home_content(state: &AppState) -> Result<HomeContent, AppError> {
|
|||
BrewSortKey::CreatedAt,
|
||||
SortDirection::Desc,
|
||||
);
|
||||
let open_bags_req = ListRequest::show_all(BagSortKey::RoastDate, SortDirection::Desc);
|
||||
let open_bags_req = ListRequest::new(
|
||||
1,
|
||||
PageSize::limited(3),
|
||||
BagSortKey::UpdatedAt,
|
||||
SortDirection::Desc,
|
||||
);
|
||||
let recent_events_req = ListRequest::new(
|
||||
1,
|
||||
PageSize::limited(5),
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ impl BagFilter {
|
|||
pub enum BagSortKey {
|
||||
RoastDate,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
Roaster,
|
||||
Roast,
|
||||
FinishedAt,
|
||||
|
|
@ -97,6 +98,7 @@ impl SortKey for BagSortKey {
|
|||
match value {
|
||||
"roast-date" => Some(BagSortKey::RoastDate),
|
||||
"created-at" => Some(BagSortKey::CreatedAt),
|
||||
"updated-at" => Some(BagSortKey::UpdatedAt),
|
||||
"roaster" => Some(BagSortKey::Roaster),
|
||||
"roast" => Some(BagSortKey::Roast),
|
||||
"finished-at" => Some(BagSortKey::FinishedAt),
|
||||
|
|
@ -108,6 +110,7 @@ impl SortKey for BagSortKey {
|
|||
match self {
|
||||
BagSortKey::RoastDate => "roast-date",
|
||||
BagSortKey::CreatedAt => "created-at",
|
||||
BagSortKey::UpdatedAt => "updated-at",
|
||||
BagSortKey::Roaster => "roaster",
|
||||
BagSortKey::Roast => "roast",
|
||||
BagSortKey::FinishedAt => "finished-at",
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ impl SqlBagRepository {
|
|||
match request.sort_key() {
|
||||
BagSortKey::RoastDate => format!("b.roast_date {dir_sql}, b.created_at DESC"),
|
||||
BagSortKey::CreatedAt => format!("b.created_at {dir_sql}, b.id DESC"),
|
||||
BagSortKey::UpdatedAt => format!("b.updated_at {dir_sql}, b.id DESC"),
|
||||
BagSortKey::Roaster => format!("LOWER(rr.name) {dir_sql}, b.created_at DESC"),
|
||||
BagSortKey::Roast => format!("LOWER(r.name) {dir_sql}, b.created_at DESC"),
|
||||
BagSortKey::FinishedAt => format!("b.finished_at {dir_sql}, b.created_at DESC"),
|
||||
|
|
|
|||
Loading…
Reference in a new issue