Switch hub endpoints to use the hub `name` slug and update frontend routes/clients accordingly. Backend: HubViewSet now uses lookup_field='name'; PostViewSet list supports `sort=top` with vote_score annotation and time windows/custom ranges, and a new TopPostsCursorPagination was added. Frontend: routes changed from `/hub/:id` to `/h/:name`, the generated hubs API was updated from id->name, and the hub feed client accepts `sort`, `time`, `start`, and `end` params (query key updated). Also adds new homepage UI components (HeroSection, DroneSection) and navbar improvements (scroll state, auto-close mobile menu on route changes, and small icon/class tweaks).
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
"""Shared pagination classes.
|
|
|
|
`CreatedCursorPagination` is the canonical choice for infinite-scroll feeds
|
|
(posts feed, chat message history). Cursor pagination keeps a stable view of
|
|
results even when new items are created at the head, which page/offset
|
|
pagination does not.
|
|
"""
|
|
|
|
from rest_framework.pagination import CursorPagination
|
|
|
|
|
|
class CreatedCursorPagination(CursorPagination):
|
|
"""Cursor pagination ordered by `-created_at` (newest first)."""
|
|
page_size = 20
|
|
ordering = '-created_at'
|
|
cursor_query_param = 'cursor'
|
|
page_size_query_param = 'page_size'
|
|
max_page_size = 100
|
|
|
|
|
|
class TopPostsCursorPagination(CursorPagination):
|
|
"""Cursor pagination ordered by vote score descending, then by id descending as tiebreaker."""
|
|
page_size = 20
|
|
ordering = ('-vote_score', '-id')
|
|
cursor_query_param = 'cursor'
|
|
page_size_query_param = 'page_size'
|
|
max_page_size = 100
|
|
|
|
|
|
class CreatedAscCursorPagination(CursorPagination):
|
|
"""Cursor pagination ordered by `created_at` (oldest first).
|
|
|
|
Used for chat history scroll-back where messages are displayed oldest -> newest
|
|
and pagination walks backwards in time from the most recent.
|
|
"""
|
|
page_size = 30
|
|
ordering = '-created_at' # backend orders newest-first; client reverses for display
|
|
cursor_query_param = 'cursor'
|
|
page_size_query_param = 'page_size'
|
|
max_page_size = 100
|