Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment attempts counter after a submission #82

Merged
merged 3 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions assets/js/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Alpine.data("Challenge", () => ({
solves: [],
response: null,
share_url: null,
max_attempts: 0,
attempts: 0,

async init() {
highlight();
Expand Down Expand Up @@ -174,6 +176,11 @@ Alpine.data("Challenge", () => ({
this.submission = "";
}

// Increment attempts counter
if (this.max_attempts > 0 && this.response.data.status != "already_solved") {
this.attempts += 1;
}

// Dispatch load-challenges event to call loadChallenges in the ChallengeBoard
this.$dispatch("load-challenges");
},
Expand Down
1 change: 0 additions & 1 deletion static/assets/challenges.0e43adc4.js

This file was deleted.

1 change: 1 addition & 0 deletions static/assets/challenges.a2215eea.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion static/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
]
},
"assets/js/challenges.js": {
"file": "assets/challenges.0e43adc4.js",
"file": "assets/challenges.a2215eea.js",
"src": "assets/js/challenges.js",
"isEntry": true,
"imports": [
Expand Down
26 changes: 11 additions & 15 deletions templates/challenge.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div :class="getStyles()" role="document" x-data="Challenge" x-init="id = {{ challenge.id }}">
<div :class="getStyles()" role="document" x-data="Challenge" x-init="id = {{ challenge.id }}; max_attempts = {{ max_attempts }}; attempts = {{ attempts }}">
<div class="modal-content">
<div class="modal-body py-4 px-4 px-sm-5">

Expand Down Expand Up @@ -111,15 +111,11 @@ <h3 class="challenge-value text-center">
</div>
{% endif %}

{% if max_attempts > 0 %}
<div class="row text-center">
<div class="col-12">
<p>
{{ attempts }}/{{ max_attempts }} attempt{{ max_attempts|pluralize }}
</p>
</div>
</div>
{% endif %}
<template x-if="max_attempts > 0">
<p class="text-center">
<span x-text="attempts"></span>/<span x-text="max_attempts"></span> {% trans c=max_attempts %}attempt{% pluralize %}attempts{% endtrans %}
</p>
</template>

<div class="row submit-row">
<div class="col-12 col-sm-8">
Expand Down Expand Up @@ -153,12 +149,12 @@ <h3 class="challenge-value text-center">
<div class="row notification-row">
<div class="col-12">
<template x-if="response">
{# This alert is re-used for all alerts, so it's important not to make it dismissble #}
<div
{# This alert is re-used for all alerts, so it's important not to make it dismissible #}
<div class="alert text-center w-100 mt-3"
:class="{
'alert text-center w-100 mt-3 alert-success': response.data.status == 'correct',
'alert text-center w-100 mt-3 alert-info': response.data.status == 'already_solved',
'alert text-center w-100 mt-3 alert-danger': response.data.status == 'incorrect',
'alert-success': response.data.status == 'correct',
'alert-info': response.data.status == 'already_solved',
'alert-danger': response.data.status == 'incorrect',
}" role="alert"
>
<strong x-text="response.data.message"></strong>
Expand Down
Loading