diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html
index f96f48a8..9a3fd2ce 100644
--- a/bookwyrm/templates/snippets/shelf_selector.html
+++ b/bookwyrm/templates/snippets/shelf_selector.html
@@ -63,16 +63,18 @@
{% endfor %}
{% if shelf.identifier == 'all' %}
-{% for shelved_in in book.shelves.all %}
+{% for user_shelf in user_shelves %}
+{% if user_shelf in book.shelves.all %}
+{% endif %}
{% endfor %}
{% else %}
diff --git a/bookwyrm/views/shelf/shelf.py b/bookwyrm/views/shelf/shelf.py
index 34914d97..0662f302 100644
--- a/bookwyrm/views/shelf/shelf.py
+++ b/bookwyrm/views/shelf/shelf.py
@@ -72,9 +72,13 @@ class Shelf(View):
"start_date"
)
+ if shelf_identifier:
+ books = books.annotate(shelved_date=F("shelfbook__shelved_date"))
+ else:
+ # sorting by shelved date will cause duplicates in the "all books" view
+ books = books.annotate(shelved_date=F("updated_date"))
books = books.annotate(
rating=Subquery(reviews.values("rating")[:1]),
- shelved_date=F("shelfbook__shelved_date"),
start_date=Subquery(reading.values("start_date")[:1]),
finish_date=Subquery(reading.values("finish_date")[:1]),
author=Subquery(