Update dashboard

This commit is contained in:
Joakim Hellsén 2026-01-08 19:41:05 +01:00
commit 0060f4d8f6
No known key found for this signature in database
2 changed files with 113 additions and 126 deletions

View file

@ -7,7 +7,7 @@
<main>
<h1 id="page-title">Twitch Drops</h1>
<pre>
Drops are sorted alphabetically by organization and game. Click on a campaign or game title to see more details.
Latest drops are shown first within each game. Click on a campaign or game title to see more details.
Hover over the end time to see the exact date and time.
</pre>
<!-- RSS Feeds -->
@ -18,20 +18,12 @@ Hover over the end time to see the exact date and time.
</div>
{% if campaigns_by_org_game %}
{% for org_id, org_data in campaigns_by_org_game.items %}
<section id="org-section-{{ org_id }}">
<h2>
{% if org_data.name %}
{{ org_data.name }}
{% else %}
Organization {{ org_id }}
{% endif %}
</h2>
{% for game_id, game_data in org_data.games.items %}
<article id="game-article-{{ game_id }}">
<article id="game-article-{{ game_id }}" style="margin-bottom: 2rem;">
<header style="margin-bottom: 1rem;">
<h3 style="margin: 0 0 0.5rem 0;">
<h2 style="margin: 0 0 0.5rem 0;">
<a href="{% url 'twitch:game_detail' game_id %}">{{ game_data.name }}</a>
</h3>
</h2>
</header>
<div style="display: flex; gap: 1rem;">
<div style="flex-shrink: 0;">
@ -111,6 +103,19 @@ Hover over the end time to see the exact date and time.
... and {{ campaign.allow_channels.all|length|add:"-5" }} more
</li>
{% endif %}
{% else %}
{% if campaign.game.twitch_directory_url %}
<li>
<a href="{{ campaign.game.twitch_directory_url }}"
target="_blank"
rel="noopener noreferrer"
title="Open Twitch category page for {{ campaign.game.display_name }} with Drops filter">
Browse {{ campaign.game.display_name }} category
</a>
</li>
{% else %}
<li>Failed to get Twitch category URL :(</li>
{% endif %}
{% endif %}
{% else %}
{% if campaign.game.twitch_directory_url %}
@ -136,7 +141,6 @@ Hover over the end time to see the exact date and time.
</div>
</article>
{% endfor %}
</section>
{% endfor %}
{% else %}
<p>No active campaigns at the moment.</p>

View file

@ -641,9 +641,11 @@ def dashboard(request: HttpRequest) -> HttpResponse:
.prefetch_related(
"allow_channels",
)
.order_by("-start_at")
)
campaigns_by_org_game: dict[str, Any] = {}
# Use OrderedDict to preserve insertion order (newest campaigns first)
campaigns_by_org_game: OrderedDict[str, Any] = OrderedDict()
for campaign in active_campaigns:
owner: Organization | None = campaign.game.owner
@ -654,7 +656,7 @@ def dashboard(request: HttpRequest) -> HttpResponse:
game_name: str = campaign.game.display_name
if org_id not in campaigns_by_org_game:
campaigns_by_org_game[org_id] = {"name": org_name, "games": {}}
campaigns_by_org_game[org_id] = {"name": org_name, "games": OrderedDict()}
if game_id not in campaigns_by_org_game[org_id]["games"]:
campaigns_by_org_game[org_id]["games"][game_id] = {
@ -663,33 +665,14 @@ def dashboard(request: HttpRequest) -> HttpResponse:
"campaigns": [],
}
campaigns_by_org_game[org_id]["games"][game_id]["campaigns"].append(
campaign,
)
sorted_campaigns_by_org_game: dict[str, Any] = {
org_id: campaigns_by_org_game[org_id]
for org_id in sorted(
campaigns_by_org_game.keys(),
key=lambda k: campaigns_by_org_game[k]["name"],
)
}
for org_data in sorted_campaigns_by_org_game.values():
org_data["games"] = {
game_id: org_data["games"][game_id]
for game_id in sorted(
org_data["games"].keys(),
key=lambda k: org_data["games"][k]["name"],
)
}
campaigns_by_org_game[org_id]["games"][game_id]["campaigns"].append(campaign)
return render(
request,
"twitch/dashboard.html",
{
"active_campaigns": active_campaigns,
"campaigns_by_org_game": sorted_campaigns_by_org_game,
"campaigns_by_org_game": campaigns_by_org_game,
"now": now,
},
)