Skip to content

Commit

Permalink
[#N/A] Fixed issue with for you page JS. Added links to usernames and…
Browse files Browse the repository at this point in the history
… made navigation buttons gray when disabled.
  • Loading branch information
paulmckissock committed Jul 29, 2024
1 parent 575c075 commit ea5845a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 12 deletions.
37 changes: 25 additions & 12 deletions audioapp/templates/audioapp/for_you.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ <h1 class="text-2xl font-bold text-center my-8">For You</h1>
<div class="flex items-center justify-between space-x-4">
<div class="flex items-center space-x-4">
<h2 id="audio-title" class="text-xl font-bold">{{ audio_file.title }}</h2>
<p id="audio-username" class="text-sm text-gray-600">By {{ audio_file.user.username }}</p>
<p id="audio-username" class="text-sm text-gray-600">
By <a href="{% url 'user_detail' audio_file.user.username %}" class="text-sm text-gray-600 hover:underline">{{ audio_file.user.username }}</a>
</p>
</div>
<div class="flex items-center space-x-4 ml-auto">
<p id="audio-like-count">{{ audio_file.like_count }} Likes</p>
Expand All @@ -26,17 +28,26 @@ <h2 id="audio-title" class="text-xl font-bold">{{ audio_file.title }}</h2>

<p id="audio-description">{{ audio_file.description }}</p>
{% if audio_file %}
<div class="flex items-center space-x-4">
<button id="previous-button" class="control-button" {% if fyp_index <= 0 %}disabled{% endif %}>
<div class="flex items-center space-x-1">
<button
id="previous-button"
class="text-black p-2 rounded disabled:text-gray-400 disabled:cursor-not-allowed"
{% if fyp_index <= 0 %}disabled{% endif %}
>
<i class="fas fa-step-backward"></i>
</button>
<audio controls id="audio-player" autoplay class="flex-1">
<source id="audio-source" src="{{ audio_file.file.url }}" type="audio/mp4">
Your browser does not support the audio element.
</audio>
<button id="next-button" class="control-button" {% if reached_end %}disabled{% endif %}>
<button
id="next-button"
class="text-black p-2 rounded disabled:text-gray-400 disabled:cursor-not-allowed"
{% if reached_end %}disabled{% endif %}
>
<i class="fas fa-step-forward"></i>
</button>

</div>
<h2 class="text-xl font-bold">Comments</h2>
<form id="comment-form" method="post" action="{% url 'for_you' %}">
Expand All @@ -50,7 +61,7 @@ <h2 class="text-xl font-bold">Comments</h2>
</form>
<ul id="comments-list">
{% for comment in comments %}
<li>{{ comment.user.username }}: {{ comment.text }}</li>
<li><a href="{% url 'user_detail' comment.user.username %}" class="text-m text-black-600 hover:underline">{{ comment.user.username }}</a>: {{ comment.text }}</li>
{% endfor %}
</ul>
{% else %}
Expand All @@ -73,19 +84,21 @@ <h2 class="text-xl font-bold">Comments</h2>
audioPlayer.load();
if (document.getElementById('autoplay-checkbox').checked) {
audioPlayer.play();
}
document.getElementById('previous-button').disabled = data.fyp_index <= 0;
document.getElementById('next-button').disabled = data.reached_end;
if (data.reached_end) {
document.getElementById('autoplay-checkbox').checked = false;
}
}

}
var data = JSON.parse(xhr.responseText);
document.getElementById('audio-title').textContent = data.title;
document.getElementById('audio-description').textContent = data.description;
document.getElementById('audio-like-count').textContent = data.like_count + ' Likes';
document.getElementById('audio-username').textContent = 'By ' + data.username;


document.getElementById('previous-button').disabled = data.fyp_index <= 0;
document.getElementById('next-button').disabled = data.reached_end;
if (data.reached_end) {
document.getElementById('autoplay-checkbox').checked = false;
}

var likeButton = document.getElementById('like-button');
if (data.has_liked) {
likeButton.classList.remove('text-black-500');
Expand Down
49 changes: 49 additions & 0 deletions theme/static/css/dist/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,18 @@ select {
margin-left: calc(1rem * calc(1 - var(--tw-space-x-reverse)));
}

.space-x-10 > :not([hidden]) ~ :not([hidden]) {
--tw-space-x-reverse: 0;
margin-right: calc(2.5rem * var(--tw-space-x-reverse));
margin-left: calc(2.5rem * calc(1 - var(--tw-space-x-reverse)));
}

.space-x-1 > :not([hidden]) ~ :not([hidden]) {
--tw-space-x-reverse: 0;
margin-right: calc(0.25rem * var(--tw-space-x-reverse));
margin-left: calc(0.25rem * calc(1 - var(--tw-space-x-reverse)));
}

.rounded {
border-radius: 0.25rem;
}
Expand Down Expand Up @@ -952,6 +964,10 @@ select {
padding: 1rem;
}

.p-2 {
padding: 0.5rem;
}

.px-4 {
padding-left: 1rem;
padding-right: 1rem;
Expand Down Expand Up @@ -1027,6 +1043,11 @@ select {
color: rgb(255 255 255 / var(--tw-text-opacity));
}

.text-black {
--tw-text-opacity: 1;
color: rgb(0 0 0 / var(--tw-text-opacity));
}

.shadow {
--tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);
Expand Down Expand Up @@ -1055,3 +1076,31 @@ select {
--tw-text-opacity: 1;
color: rgb(185 28 28 / var(--tw-text-opacity));
}

.hover\:underline:hover {
text-decoration-line: underline;
}

.disabled\:cursor-not-allowed:disabled {
cursor: not-allowed;
}

.disabled\:bg-gray-400:disabled {
--tw-bg-opacity: 1;
background-color: rgb(156 163 175 / var(--tw-bg-opacity));
}

.disabled\:text-gray-600:disabled {
--tw-text-opacity: 1;
color: rgb(75 85 99 / var(--tw-text-opacity));
}

.disabled\:text-gray-300:disabled {
--tw-text-opacity: 1;
color: rgb(209 213 219 / var(--tw-text-opacity));
}

.disabled\:text-gray-400:disabled {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
}

0 comments on commit ea5845a

Please sign in to comment.