diff --git a/app/routers/web.py b/app/routers/web.py index 929779a..df5520b 100644 --- a/app/routers/web.py +++ b/app/routers/web.py @@ -203,7 +203,6 @@ def profile_rename(profile_id: int, nickname: str = Form(...), user: User = Depe def postcard_list( request: Request, profile_id: int, - status: str = "", country: str = "", user: User = Depends(get_current_user_web), db: Session = Depends(get_db), @@ -212,14 +211,24 @@ def postcard_list( if not profile: return _redirect("/profiles") q = db.query(Postcard).filter(Postcard.profile_id == profile_id) - if status: - q = q.filter(Postcard.status == status) if country: - q = q.filter(Postcard.country.ilike(f"%{country}%")) - postcards = q.order_by(Postcard.created_at.desc()).all() + q = q.filter(Postcard.country == country) + postcards = q.all() + + # collect existing countries for dropdown + all_countries = sorted({pc.country for pc in db.query(Postcard.country).filter(Postcard.profile_id == profile_id, Postcard.country.isnot(None)).all()}) + + # status sort order: sent=0, delivered=1, received=2 + _status_order = {"sent": 0, "delivered": 1, "received": 2} + postcards.sort(key=lambda pc: (_status_order.get(pc.status, 9), -(pc.send_time or pc.arrival_time or pc.receive_time or pc.created_at).timestamp())) + + # split into sent and received + sent = [pc for pc in postcards if pc.status in ("sent", "delivered")] + received = [pc for pc in postcards if pc.status == "received"] + return templates.TemplateResponse( "postcards.html", - {"request": request, "user": user, "profile": profile, "postcards": postcards, "status": status, "country": country}, + {"request": request, "user": user, "profile": profile, "sent": sent, "received": received, "countries": all_countries, "country": country}, ) diff --git a/app/static/style.css b/app/static/style.css index 2eb2ad7..93fdff6 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -136,6 +136,23 @@ code { background: var(--bg); padding: .15rem .4rem; border-radius: 4px; font-si .detail-meta dt { font-weight: 600; font-size: .85rem; color: var(--text-muted); } .detail-meta dd { font-size: .95rem; } +/* Tabs */ +.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1rem; } +.tab { padding: .5rem 1.25rem; border: none; background: none; cursor: pointer; font-size: .9rem; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; } +.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; } +.tab:hover { color: var(--primary); } + +/* Postcard row */ +.postcard-row { display: flex; align-items: center; gap: 1rem; padding: .75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); margin-bottom: .5rem; text-decoration: none; color: var(--text); transition: box-shadow .15s; } +.postcard-row:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); text-decoration: none; } +.postcard-row-img { flex-shrink: 0; width: 56px; height: 56px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); } +.postcard-row-img img { width: 100%; height: 100%; object-fit: cover; } +.postcard-row-img .placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: var(--bg); font-size: 1.2rem; } +.postcard-row-info { flex: 1; display: flex; align-items: center; gap: .75rem; min-width: 0; font-size: .9rem; } +.postcard-row-info strong { white-space: nowrap; } +.postcard-row-info span { white-space: nowrap; color: var(--text-muted); } +.postcard-row-action { flex-shrink: 0; } + /* Filter */ .filter-bar { margin-bottom: 1.25rem; } @@ -146,4 +163,5 @@ code { background: var(--bg); padding: .15rem .4rem; border-radius: 4px; font-si @media (max-width: 640px) { .detail-grid { grid-template-columns: 1fr; } .card-grid { grid-template-columns: 1fr; } + .postcard-row-info { flex-wrap: wrap; gap: .35rem; } } diff --git a/app/templates/postcards.html b/app/templates/postcards.html index cefa665..e4183fd 100644 --- a/app/templates/postcards.html +++ b/app/templates/postcards.html @@ -7,43 +7,80 @@
-{% if postcards %} -没有找到明信片。
+没有寄出的明信片。
{% endif %} +