-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Hide notification pane before page has fully loaded (#202) * Abstract notifications dropdown into own template * Add Alpine and HTMX Morph plugins * Add Notification middleware to automatically mark notifications as read
- Loading branch information
Showing
10 changed files
with
97 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
htmx.defineExtension('alpine-morph', { | ||
isInlineSwap: function (swapStyle) { | ||
return swapStyle === 'morph'; | ||
}, | ||
handleSwap: function (swapStyle, target, fragment) { | ||
if (swapStyle === 'morph') { | ||
if (fragment.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | ||
Alpine.morph(target, fragment.firstElementChild); | ||
return [target]; | ||
} else { | ||
Alpine.morph(target, fragment.outerHTML); | ||
return [target]; | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{# <div hx-target="this" hx-ext="alpine-morph" hx-swap="morph" hx-get="{% url 'users:htmx_notifications_dropdown' %}" hx-trigger="every 15s" x-data="{ open: false }"> #} | ||
<div x-data="{ open: false }"> | ||
<a class="nav-link" href="#"> | ||
<span class="icon-badge-container text-white" x-on:click="open = !open"> | ||
{% if notifications.unread %} | ||
<i class="bi bi-bell-fill icon-badge-icon"></i> | ||
<span class="icon-badge">{{ notifications.unread }}</span> | ||
{% else %} | ||
<i class="bi bi-bell"></i> | ||
{% endif %} | ||
</span> | ||
</a> | ||
<div class="notification-dropdown shadow-lg border border-2 bg-light" x-show="open" @click.outside="open = false" x-cloak x-transition> | ||
<div class="item title my-0"> | ||
Notifications | ||
</div> | ||
|
||
{% if notifications.list %} | ||
{% for notification in notifications.list %} | ||
<div data-href="{% url 'users:notification' pk=notification.pk %}" class="item text-primary"> | ||
<span{% if not notification.read %} class="fw-bold"{% endif %}>{{ notification.get_message }}</span> | ||
<br /> | ||
<small class="text-muted"> | ||
{{ notification.updated|timesince }} ago | ||
</small> | ||
</div> | ||
{% endfor %} | ||
|
||
<div data-href="{% url 'users:notifications' %}" class="item text-primary"> | ||
<a href="{% url 'users:notifications' %}" | ||
class="btn btn-primary"> | ||
See all notifications | ||
</a> | ||
</div> | ||
{% else %} | ||
<div class="item title fw-normal text-primary"> | ||
<span>You do not have any notifications. Oh well!</span> | ||
</div> | ||
{% endif %} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters