Increase session count on game overview when starting a new session
This commit is contained in:
parent
e2b7ff2e15
commit
4b75a1dea9
|
@ -2,6 +2,7 @@
|
|||
|
||||
## Improved
|
||||
* mark refunded purchases red on game overview
|
||||
* increase session count on game overview when starting a new session
|
||||
|
||||
## Fixed
|
||||
* Fix title not being displayed on the Recent sessions page
|
||||
|
|
|
@ -57,13 +57,14 @@
|
|||
</ul>
|
||||
<h1 class="text-3xl mt-4 mb-1 flex gap-2 items-center">
|
||||
Sessions
|
||||
<span class="dark:text-slate-500">({{ session_count }})</span>
|
||||
<span class="dark:text-slate-500" id="session-count">({{ session_count }})</span>
|
||||
{% url 'view_game_start_session_from_session' latest_session_id as add_session_link %}
|
||||
<a
|
||||
class="truncate max-w-xs py-1 px-2 text-xs bg-green-600 hover:bg-green-700 focus:ring-green-500 focus:ring-offset-blue-200 text-white transition ease-in duration-200 text-center font-semibold shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 rounded-sm"
|
||||
title="Start new session"
|
||||
href="{{ add_session_link }}"
|
||||
hx-get="{{ add_session_link }}"
|
||||
hx-vals="js:{session_count:getSessionCount()}"
|
||||
hx-target="#session-list"
|
||||
hx-swap="afterbegin"
|
||||
>New</a>
|
||||
|
@ -85,6 +86,7 @@
|
|||
hx-get="{{ end_session_url }}"
|
||||
hx-target="closest li"
|
||||
hx-swap="outerHTML"
|
||||
hx-vals="js:{session_count:getSessionCount()}"
|
||||
hx-indicator="#indicator"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="#ffffff" class="h-3" x="0px" y="0px" viewBox="0 0 24 24">
|
||||
|
@ -95,8 +97,16 @@
|
|||
{% endif %}
|
||||
</li>
|
||||
<li class="sm:pl-4 italic">{{ session.note|linebreaks }}</li>
|
||||
<div class="hidden" hx-swap-oob="innerHTML:#session-count">
|
||||
({{ session_count }})
|
||||
</div>
|
||||
{% endpartialdef %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
function getSessionCount() {
|
||||
return document.getElementById('session-count').textContent.match("[0-9]+");
|
||||
}
|
||||
</script>
|
||||
{% endblock content %}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from datetime import datetime
|
||||
from typing import Any, Callable
|
||||
import re
|
||||
|
||||
from django.db.models import (
|
||||
Avg,
|
||||
|
@ -247,7 +248,10 @@ def clone_session_by_id(session_id: int) -> Session:
|
|||
def new_session_from_existing_session(request, session_id: int, template: str = ""):
|
||||
session = clone_session_by_id(session_id)
|
||||
if request.htmx:
|
||||
context = {"session": session}
|
||||
context = {
|
||||
"session": session,
|
||||
"session_count": int(request.GET.get("session_count", 0)) + 1,
|
||||
}
|
||||
return render(request, template, context)
|
||||
return redirect("list_sessions")
|
||||
|
||||
|
@ -258,7 +262,10 @@ def end_session(request, session_id: int, template: str = ""):
|
|||
session.timestamp_end = timezone.now()
|
||||
session.save()
|
||||
if request.htmx:
|
||||
context = {"session": session}
|
||||
context = {
|
||||
"session": session,
|
||||
"session_count": request.GET.get("session_count", 0),
|
||||
}
|
||||
return render(request, template, context)
|
||||
return redirect("list_sessions")
|
||||
|
||||
|
|
Loading…
Reference in New Issue