Skip to content

Commit

Permalink
Merge branch 'dev' into forums/vote-buttons-css
Browse files Browse the repository at this point in the history
  • Loading branch information
giomhern authored Dec 6, 2023
2 parents df4ef08 + 6fae76f commit 3c2e863
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/chigame/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
decline_friend_invitation,
friend_list_view,
notification_detail,
notification_search_results,
remove_friend,
send_friend_invitation,
user_detail_view,
Expand Down Expand Up @@ -36,6 +37,7 @@
path("decline_friend_invitation/<int:pk>", view=decline_friend_invitation, name="decline-friend-invitation"),
path("user_history/<int:pk>", views.user_history, name="user-history"),
path("search-results", view=user_search_results, name="user-search-results"),
path("notifications/search-results", view=notification_search_results, name="notification-search-results"),
path("inbox/<int:pk>", view=user_inbox_view, name="user-inbox"),
path("profile/<int:pk>/friends", view=friend_list_view, name="friend-list"),
path("inbox/<int:pk>/deleted_notifications", views.deleted_notifications_view, name="deleted-notifications"),
Expand Down
14 changes: 14 additions & 0 deletions src/chigame/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def send_friend_invitation(request, pk):
actor=invitation,
receiver=other_user,
type=Notification.FRIEND_REQUEST,
message=Notification.DEFAULT_MESSAGES[Notification.FRIEND_REQUEST],
)
elif invitation.sender.pk == other_user.pk:
messages.info(request, "You already have a pending friend invitation from this profile.")
Expand Down Expand Up @@ -222,6 +223,19 @@ def user_search_results(request):
return render(request, "pages/search_results.html", context)


def notification_search_results(request):
query_input = request.GET.get("q")
context = {"nothing_found": True, "query_type": "Notifications"}
if query_input:
notifications_list = Notification.objects.filter_by_receiver(request.user).filter(
message__icontains=query_input
)
if notifications_list.count() > 0:
context["nothing_found"] = False
context["object_list"] = notifications_list
return render(request, "pages/search_results.html", context)


@login_required
def user_inbox_view(request, pk):
user = request.user
Expand Down
10 changes: 10 additions & 0 deletions src/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
{% url 'games:index' as games_url %}
{% url 'game-search-results' as game_search_url %}
{% url 'users:user-search-results' as users_search_url %}
{% url 'users:notification-search-results' as notifications_search_url %}
<select id="query-type" name="query_type" class="form-select">
<option value="games"
{% if request.path == games_url or request.path == games_search_url %}selected{% endif %}>
Expand All @@ -136,6 +137,10 @@
{% if request.path == forum_url or request.path == forum_search_url %}selected{% endif %}>
Forums
</option>
<option value="notifications"
{% if request.path == notifications_search_url %}selected{% endif %}>
Notifications
</option>
<!-- Add more options here -->
</select>
</div>
Expand Down Expand Up @@ -278,6 +283,11 @@
$("#query-input").autocomplete({
source: [] // placeholder; replace with list of forums
});
} else if (query_type.value == "notifications") {
search_bar.action = "{% url 'users:notification-search-results' %}";
$("#query-input").autocomplete({
source: [] // placeholder; replace with list of notifications
});
}
advancedSearchButton.classList.toggle('d-none', query_type.value !== "forums"); // hide advanced search button if not searching forums
}
Expand Down
6 changes: 6 additions & 0 deletions src/templates/pages/search_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ <h1>{{ query_type }} Search Results</h1>
<a href="{% url 'game-detail' game.id %}">{{ game.name }}</a>
</li>
{% endfor %}
{% elif query_type == "Notifications" %}
{% for notification in object_list %}
<li>
<a href="{% url 'users:notification-detail' notification.id %}">{{ notification.message }}</a>
</li>
{% endfor %}
{% endif %}
</ul>
{% endblock content %}
2 changes: 1 addition & 1 deletion src/templates/users/user_inbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<input type="checkbox" name="notification[]" value="{{ notification.id }}" />
</label>
{% if notification.message %}
<a>{{ notification.message }}</a>
<a href="{% url 'users:notification-detail' notification.pk %}">{{ notification.message }}</a>
{% else %}
<a href="{% url 'users:notification-detail' notification.pk %}">{{ default_notification_messages | get_dict_val:notification_type }}</a>
{% endif %}
Expand Down

0 comments on commit 3c2e863

Please sign in to comment.