Add /games page and add checkboxes for subscribing to games

This commit is contained in:
2024-07-04 05:36:30 +02:00
parent fb1f7c4983
commit 474e2b5bff
8 changed files with 72 additions and 1 deletions

View File

@ -3,6 +3,7 @@
"allauth", "allauth",
"appendonly", "appendonly",
"asgiref", "asgiref",
"forloop",
"logdir", "logdir",
"memlock", "memlock",
"networkidle", "networkidle",

29
core/templates/games.html Normal file
View File

@ -0,0 +1,29 @@
{% extends "base.html" %}
{% block content %}
<div class="container mt-4">
<div class="row">
{% for game in games %}
<div class="col-xl-3 col-lg-4 col-md-6 col-sm-12 mb-4">
<div class="card h-100 shadow-sm">
<img src="{{ game.image_url }}"
class="card-img-top"
alt="{{ game.display_name }}">
<div class="card-body d-flex flex-column">
<h5 class="card-title">{{ game.display_name }}</h5>
<div class="mt-auto">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="new">
<label class="form-check-label" for="new">Notify when new</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="live">
<label class="form-check-label" for="live">Notify when farmable</label>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock content %}

View File

@ -18,7 +18,6 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Games Column -->
<div class="col-lg-9"> <div class="col-lg-9">
{% for game in games %} {% for game in games %}
<div class="card mb-4 shadow-sm" id="game-{{ game.game_id }}"> <div class="card mb-4 shadow-sm" id="game-{{ game.game_id }}">
@ -36,6 +35,18 @@
<h2 class="card-title h5"> <h2 class="card-title h5">
<a href="{{ game.twitch_url }}" class="text-decoration-none">{{ game.display_name }}</a> <a href="{{ game.twitch_url }}" class="text-decoration-none">{{ game.display_name }}</a>
</h2> </h2>
<div class="mt-auto">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="new">
<label class="form-check-label" for="new">
Notify when new drop is found on <a href="https://www.twitch.tv/drops/campaigns">Twitch</a>
</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="live">
<label class="form-check-label" for="live">Notify when a drop starts</label>
</div>
</div>
{% for campaign in game.campaigns %} {% for campaign in game.campaigns %}
{% if not forloop.first %}<br>{% endif %} {% if not forloop.first %}<br>{% endif %}
<div class="mt-3"> <div class="mt-3">

View File

@ -5,6 +5,9 @@
</h1> </h1>
<nav> <nav>
<ul class="nav"> <ul class="nav">
<li class="nav-item">
<a class="nav-link" href='{% url "core:games" %}'>Games</a>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href='{% url "api-1.0.0:openapi-view" %}'>API</a> <a class="nav-link" href='{% url "api-1.0.0:openapi-view" %}'>API</a>
</li> </li>

View File

@ -25,4 +25,9 @@ urlpatterns: list[URLPattern | URLResolver] = [
view=views.subscription_create, view=views.subscription_create,
name="subscription_create", name="subscription_create",
), ),
path(
route="games/",
view=views.GameView.as_view(),
name="games",
),
] ]

View File

@ -12,6 +12,7 @@ from django.http import (
) )
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.views.generic import ListView
from core.discord import send from core.discord import send
from core.models import DiscordSetting from core.models import DiscordSetting
@ -279,3 +280,10 @@ def subscription_create(request: HttpRequest) -> HttpResponse:
messages.error(request, "Failed to create subscription") messages.error(request, "Failed to create subscription")
return redirect("core:index") return redirect("core:index")
class GameView(ListView):
model = Game
template_name: str = "games.html"
context_object_name: str = "games"
paginate_by = 100

View File

@ -37,6 +37,7 @@ lint.ignore = [
[tool.djlint] [tool.djlint]
profile = "django" profile = "django"
format_attribute_template_tags = true format_attribute_template_tags = true
ignore="H006" # Img tag should have height and width attributes.
[tool.pytest.ini_options] [tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "config.settings" DJANGO_SETTINGS_MODULE = "config.settings"

View File

@ -60,3 +60,16 @@ a:hover {
.toc { .toc {
top: 1rem; top: 1rem;
} }
/* Checkboxes for subscribing to notifications */
/* Checked */
.form-check-input:checked {
background-color: #af1548;
border-color: #111111;
}
/* Unchecked */
.form-check-input {
background-color: #0c0c0c;
border-color: #111111;
}