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,
|
BrewSortKey::CreatedAt,
|
||||||
SortDirection::Desc,
|
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(
|
let recent_events_req = ListRequest::new(
|
||||||
1,
|
1,
|
||||||
PageSize::limited(5),
|
PageSize::limited(5),
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ impl BagFilter {
|
||||||
pub enum BagSortKey {
|
pub enum BagSortKey {
|
||||||
RoastDate,
|
RoastDate,
|
||||||
CreatedAt,
|
CreatedAt,
|
||||||
|
UpdatedAt,
|
||||||
Roaster,
|
Roaster,
|
||||||
Roast,
|
Roast,
|
||||||
FinishedAt,
|
FinishedAt,
|
||||||
|
|
@ -97,6 +98,7 @@ impl SortKey for BagSortKey {
|
||||||
match value {
|
match value {
|
||||||
"roast-date" => Some(BagSortKey::RoastDate),
|
"roast-date" => Some(BagSortKey::RoastDate),
|
||||||
"created-at" => Some(BagSortKey::CreatedAt),
|
"created-at" => Some(BagSortKey::CreatedAt),
|
||||||
|
"updated-at" => Some(BagSortKey::UpdatedAt),
|
||||||
"roaster" => Some(BagSortKey::Roaster),
|
"roaster" => Some(BagSortKey::Roaster),
|
||||||
"roast" => Some(BagSortKey::Roast),
|
"roast" => Some(BagSortKey::Roast),
|
||||||
"finished-at" => Some(BagSortKey::FinishedAt),
|
"finished-at" => Some(BagSortKey::FinishedAt),
|
||||||
|
|
@ -108,6 +110,7 @@ impl SortKey for BagSortKey {
|
||||||
match self {
|
match self {
|
||||||
BagSortKey::RoastDate => "roast-date",
|
BagSortKey::RoastDate => "roast-date",
|
||||||
BagSortKey::CreatedAt => "created-at",
|
BagSortKey::CreatedAt => "created-at",
|
||||||
|
BagSortKey::UpdatedAt => "updated-at",
|
||||||
BagSortKey::Roaster => "roaster",
|
BagSortKey::Roaster => "roaster",
|
||||||
BagSortKey::Roast => "roast",
|
BagSortKey::Roast => "roast",
|
||||||
BagSortKey::FinishedAt => "finished-at",
|
BagSortKey::FinishedAt => "finished-at",
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ impl SqlBagRepository {
|
||||||
match request.sort_key() {
|
match request.sort_key() {
|
||||||
BagSortKey::RoastDate => format!("b.roast_date {dir_sql}, b.created_at DESC"),
|
BagSortKey::RoastDate => format!("b.roast_date {dir_sql}, b.created_at DESC"),
|
||||||
BagSortKey::CreatedAt => format!("b.created_at {dir_sql}, b.id 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::Roaster => format!("LOWER(rr.name) {dir_sql}, b.created_at DESC"),
|
||||||
BagSortKey::Roast => format!("LOWER(r.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"),
|
BagSortKey::FinishedAt => format!("b.finished_at {dir_sql}, b.created_at DESC"),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue