mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-11 23:19:40 +00:00
Partially refresh notifications list (#35010)
This PR prevents full reloads for the notifications list when changing a notifications status (read, unread, pinned). --------- Co-authored-by: Anton Bracke <anton.bracke@fastleansmart.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
b6d6402a1b
commit
ea809a5220
@ -4,10 +4,8 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
activities_model "code.gitea.io/gitea/models/activities"
|
activities_model "code.gitea.io/gitea/models/activities"
|
||||||
@ -34,58 +32,42 @@ const (
|
|||||||
tplNotificationSubscriptions templates.TplName = "user/notification/notification_subscriptions"
|
tplNotificationSubscriptions templates.TplName = "user/notification/notification_subscriptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Notifications is the notifications page
|
// Notifications is the notification list page
|
||||||
func Notifications(ctx *context.Context) {
|
func Notifications(ctx *context.Context) {
|
||||||
getNotifications(ctx)
|
prepareUserNotificationsData(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ctx.FormBool("div-only") {
|
if ctx.FormBool("div-only") {
|
||||||
ctx.Data["SequenceNumber"] = ctx.FormString("sequence-number")
|
|
||||||
ctx.HTML(http.StatusOK, tplNotificationDiv)
|
ctx.HTML(http.StatusOK, tplNotificationDiv)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.HTML(http.StatusOK, tplNotification)
|
ctx.HTML(http.StatusOK, tplNotification)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNotifications(ctx *context.Context) {
|
func prepareUserNotificationsData(ctx *context.Context) {
|
||||||
var (
|
pageType := ctx.FormString("type", ctx.FormString("q")) // "q" is the legacy query parameter for "page type"
|
||||||
keyword = ctx.FormTrim("q")
|
page := max(1, ctx.FormInt("page"))
|
||||||
status activities_model.NotificationStatus
|
perPage := util.IfZero(ctx.FormInt("perPage"), 20) // this value is never used or exposed ....
|
||||||
page = ctx.FormInt("page")
|
queryStatus := util.Iif(pageType == "read", activities_model.NotificationStatusRead, activities_model.NotificationStatusUnread)
|
||||||
perPage = ctx.FormInt("perPage")
|
|
||||||
)
|
|
||||||
if page < 1 {
|
|
||||||
page = 1
|
|
||||||
}
|
|
||||||
if perPage < 1 {
|
|
||||||
perPage = 20
|
|
||||||
}
|
|
||||||
|
|
||||||
switch keyword {
|
|
||||||
case "read":
|
|
||||||
status = activities_model.NotificationStatusRead
|
|
||||||
default:
|
|
||||||
status = activities_model.NotificationStatusUnread
|
|
||||||
}
|
|
||||||
|
|
||||||
total, err := db.Count[activities_model.Notification](ctx, activities_model.FindNotificationOptions{
|
total, err := db.Count[activities_model.Notification](ctx, activities_model.FindNotificationOptions{
|
||||||
UserID: ctx.Doer.ID,
|
UserID: ctx.Doer.ID,
|
||||||
Status: []activities_model.NotificationStatus{status},
|
Status: []activities_model.NotificationStatus{queryStatus},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("ErrGetNotificationCount", err)
|
ctx.ServerError("ErrGetNotificationCount", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// redirect to last page if request page is more than total pages
|
|
||||||
pager := context.NewPagination(int(total), perPage, page, 5)
|
pager := context.NewPagination(int(total), perPage, page, 5)
|
||||||
if pager.Paginater.Current() < page {
|
if pager.Paginater.Current() < page {
|
||||||
ctx.Redirect(fmt.Sprintf("%s/notifications?q=%s&page=%d", setting.AppSubURL, url.QueryEscape(ctx.FormString("q")), pager.Paginater.Current()))
|
// use the last page if the requested page is more than total pages
|
||||||
return
|
page = pager.Paginater.Current()
|
||||||
|
pager = context.NewPagination(int(total), perPage, page, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
statuses := []activities_model.NotificationStatus{status, activities_model.NotificationStatusPinned}
|
statuses := []activities_model.NotificationStatus{queryStatus, activities_model.NotificationStatusPinned}
|
||||||
nls, err := db.Find[activities_model.Notification](ctx, activities_model.FindNotificationOptions{
|
nls, err := db.Find[activities_model.Notification](ctx, activities_model.FindNotificationOptions{
|
||||||
ListOptions: db.ListOptions{
|
ListOptions: db.ListOptions{
|
||||||
PageSize: perPage,
|
PageSize: perPage,
|
||||||
@ -142,51 +124,37 @@ func getNotifications(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Title"] = ctx.Tr("notifications")
|
ctx.Data["Title"] = ctx.Tr("notifications")
|
||||||
ctx.Data["Keyword"] = keyword
|
ctx.Data["PageType"] = pageType
|
||||||
ctx.Data["Status"] = status
|
|
||||||
ctx.Data["Notifications"] = notifications
|
ctx.Data["Notifications"] = notifications
|
||||||
|
ctx.Data["Link"] = setting.AppSubURL + "/notifications"
|
||||||
|
ctx.Data["SequenceNumber"] = ctx.FormString("sequence-number")
|
||||||
pager.AddParamFromRequest(ctx.Req)
|
pager.AddParamFromRequest(ctx.Req)
|
||||||
ctx.Data["Page"] = pager
|
ctx.Data["Page"] = pager
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotificationStatusPost is a route for changing the status of a notification
|
// NotificationStatusPost is a route for changing the status of a notification
|
||||||
func NotificationStatusPost(ctx *context.Context) {
|
func NotificationStatusPost(ctx *context.Context) {
|
||||||
var (
|
notificationID := ctx.FormInt64("notification_id")
|
||||||
notificationID = ctx.FormInt64("notification_id")
|
var newStatus activities_model.NotificationStatus
|
||||||
statusStr = ctx.FormString("status")
|
switch ctx.FormString("notification_action") {
|
||||||
status activities_model.NotificationStatus
|
case "mark_as_read":
|
||||||
)
|
newStatus = activities_model.NotificationStatusRead
|
||||||
|
case "mark_as_unread":
|
||||||
switch statusStr {
|
newStatus = activities_model.NotificationStatusUnread
|
||||||
case "read":
|
case "pin":
|
||||||
status = activities_model.NotificationStatusRead
|
newStatus = activities_model.NotificationStatusPinned
|
||||||
case "unread":
|
|
||||||
status = activities_model.NotificationStatusUnread
|
|
||||||
case "pinned":
|
|
||||||
status = activities_model.NotificationStatusPinned
|
|
||||||
default:
|
default:
|
||||||
ctx.ServerError("InvalidNotificationStatus", errors.New("Invalid notification status"))
|
return // ignore user's invalid input
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
if _, err := activities_model.SetNotificationStatus(ctx, notificationID, ctx.Doer, newStatus); err != nil {
|
||||||
if _, err := activities_model.SetNotificationStatus(ctx, notificationID, ctx.Doer, status); err != nil {
|
|
||||||
ctx.ServerError("SetNotificationStatus", err)
|
ctx.ServerError("SetNotificationStatus", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.FormBool("noredirect") {
|
prepareUserNotificationsData(ctx)
|
||||||
url := fmt.Sprintf("%s/notifications?page=%s", setting.AppSubURL, url.QueryEscape(ctx.FormString("page")))
|
|
||||||
ctx.Redirect(url, http.StatusSeeOther)
|
|
||||||
}
|
|
||||||
|
|
||||||
getNotifications(ctx)
|
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["Link"] = setting.AppSubURL + "/notifications"
|
|
||||||
ctx.Data["SequenceNumber"] = ctx.Req.PostFormValue("sequence-number")
|
|
||||||
|
|
||||||
ctx.HTML(http.StatusOK, tplNotificationDiv)
|
ctx.HTML(http.StatusOK, tplNotificationDiv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,124 +1,96 @@
|
|||||||
<div role="main" aria-label="{{.Title}}" class="page-content user notification" id="notification_div" data-sequence-number="{{.SequenceNumber}}">
|
<div role="main" aria-label="{{.Title}}" class="page-content user notification" id="notification_div" data-sequence-number="{{.SequenceNumber}}">
|
||||||
<div class="ui container">
|
<div class="ui container">
|
||||||
|
{{$statusUnread := 1}}{{$statusRead := 2}}{{$statusPinned := 3}}
|
||||||
{{$notificationUnreadCount := call .PageGlobalData.GetNotificationUnreadCount}}
|
{{$notificationUnreadCount := call .PageGlobalData.GetNotificationUnreadCount}}
|
||||||
<div class="tw-flex tw-items-center tw-justify-between tw-mb-[--page-spacing]">
|
{{$pageTypeIsRead := eq $.PageType "read"}}
|
||||||
|
<div class="flex-text-block tw-justify-between tw-mb-[--page-spacing]">
|
||||||
<div class="small-menu-items ui compact tiny menu">
|
<div class="small-menu-items ui compact tiny menu">
|
||||||
<a class="{{if eq .Status 1}}active {{end}}item" href="{{AppSubUrl}}/notifications?q=unread">
|
<a class="{{if not $pageTypeIsRead}}active{{end}} item" href="{{AppSubUrl}}/notifications?type=unread">
|
||||||
{{ctx.Locale.Tr "notification.unread"}}
|
{{ctx.Locale.Tr "notification.unread"}}
|
||||||
<div class="notifications-unread-count ui label {{if not $notificationUnreadCount}}tw-hidden{{end}}">{{$notificationUnreadCount}}</div>
|
<div class="notifications-unread-count ui label {{if not $notificationUnreadCount}}tw-hidden{{end}}">{{$notificationUnreadCount}}</div>
|
||||||
</a>
|
</a>
|
||||||
<a class="{{if eq .Status 2}}active {{end}}item" href="{{AppSubUrl}}/notifications?q=read">
|
<a class="{{if $pageTypeIsRead}}active{{end}} item" href="{{AppSubUrl}}/notifications?type=read">
|
||||||
{{ctx.Locale.Tr "notification.read"}}
|
{{ctx.Locale.Tr "notification.read"}}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{{if and (eq .Status 1)}}
|
{{if and (not $pageTypeIsRead) $notificationUnreadCount}}
|
||||||
<form action="{{AppSubUrl}}/notifications/purge" method="post">
|
<form action="{{AppSubUrl}}/notifications/purge" method="post">
|
||||||
{{$.CsrfTokenHtml}}
|
{{$.CsrfTokenHtml}}
|
||||||
<div class="{{if not $notificationUnreadCount}}tw-hidden{{end}}">
|
|
||||||
<button class="ui mini button primary tw-mr-0" title="{{ctx.Locale.Tr "notification.mark_all_as_read"}}">
|
<button class="ui mini button primary tw-mr-0" title="{{ctx.Locale.Tr "notification.mark_all_as_read"}}">
|
||||||
{{svg "octicon-checklist"}}
|
{{svg "octicon-checklist"}}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<div class="tw-p-0">
|
|
||||||
<div id="notification_table">
|
<div id="notification_table">
|
||||||
{{if not .Notifications}}
|
{{range $one := .Notifications}}
|
||||||
<div class="tw-flex tw-items-center tw-flex-col tw-p-4">
|
<div class="notifications-item" id="notification_{{$one.ID}}" data-status="{{$one.Status}}">
|
||||||
{{svg "octicon-inbox" 56 "tw-mb-4"}}
|
<div class="tw-self-start tw-mt-[2px]">
|
||||||
{{if eq .Status 1}}
|
{{if $one.Issue}}
|
||||||
{{ctx.Locale.Tr "notification.no_unread"}}
|
{{template "shared/issueicon" $one.Issue}}
|
||||||
{{else}}
|
|
||||||
{{ctx.Locale.Tr "notification.no_read"}}
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
{{else}}
|
|
||||||
{{range $notification := .Notifications}}
|
|
||||||
<div class="notifications-item tw-flex tw-items-center tw-flex-wrap tw-gap-2 tw-p-2" id="notification_{{.ID}}" data-status="{{.Status}}">
|
|
||||||
<div class="notifications-icon tw-ml-2 tw-mr-1 tw-self-start tw-mt-1">
|
|
||||||
{{if .Issue}}
|
|
||||||
{{template "shared/issueicon" .Issue}}
|
|
||||||
{{else}}
|
{{else}}
|
||||||
{{svg "octicon-repo" 16 "text grey"}}
|
{{svg "octicon-repo" 16 "text grey"}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<a class="notifications-link tw-flex tw-flex-1 tw-flex-col silenced" href="{{.Link ctx}}">
|
<a class="notifications-link silenced tw-flex-1" href="{{$one.Link ctx}}">
|
||||||
<div class="notifications-top-row tw-text-13 tw-break-anywhere">
|
<div class="flex-text-block tw-text-[0.95em]">
|
||||||
{{.Repository.FullName}} {{if .Issue}}<span class="text light-3">#{{.Issue.Index}}</span>{{end}}
|
{{$one.Repository.FullName}} {{if $one.Issue}}<span class="text light-3">#{{$one.Issue.Index}}</span>{{end}}
|
||||||
{{if eq .Status 3}}
|
{{if eq $one.Status $statusPinned}}
|
||||||
{{svg "octicon-pin" 13 "text blue tw-mt-0.5 tw-ml-1"}}
|
{{svg "octicon-pin" 13 "text blue"}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<div class="notifications-bottom-row tw-text-16 tw-py-0.5">
|
<div class="tw-text-16 tw-py-0.5">
|
||||||
<span class="issue-title tw-break-anywhere">
|
{{if $one.Issue}}
|
||||||
{{if .Issue}}
|
{{$one.Issue.Title | ctx.RenderUtils.RenderIssueSimpleTitle}}
|
||||||
{{.Issue.Title | ctx.RenderUtils.RenderIssueSimpleTitle}}
|
|
||||||
{{else}}
|
{{else}}
|
||||||
{{.Repository.FullName}}
|
{{$one.Repository.FullName}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<div class="notifications-updated tw-items-center tw-mr-2">
|
<div class="notifications-updated flex-text-inline">
|
||||||
{{if .Issue}}
|
{{if $one.Issue}}
|
||||||
{{DateUtils.TimeSince .Issue.UpdatedUnix}}
|
{{DateUtils.TimeSince $one.Issue.UpdatedUnix}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{DateUtils.TimeSince .UpdatedUnix}}
|
{{DateUtils.TimeSince $one.UpdatedUnix}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<div class="notifications-buttons tw-items-center tw-justify-end tw-gap-1 tw-px-1">
|
<form class="notifications-buttons" action="{{AppSubUrl}}/notifications/status?type={{$.PageType}}&page={{$.Page.Paginater.Current}}&perPage={{$.Page.Paginater.PagingNum}}" method="post"
|
||||||
{{if ne .Status 3}}
|
hx-boost="true" hx-target="#notification_div" hx-swap="outerHTML"
|
||||||
<form action="{{AppSubUrl}}/notifications/status" method="post">
|
>
|
||||||
{{$.CsrfTokenHtml}}
|
{{$.CsrfTokenHtml}}
|
||||||
<input type="hidden" name="notification_id" value="{{.ID}}">
|
<input type="hidden" name="notification_id" value="{{$one.ID}}">
|
||||||
<input type="hidden" name="status" value="pinned">
|
{{if ne $one.Status $statusPinned}}
|
||||||
<button class="btn interact-bg tw-p-2" title="{{ctx.Locale.Tr "notification.pin"}}"
|
<button class="btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "notification.pin"}}"
|
||||||
data-url="{{AppSubUrl}}/notifications/status"
|
name="notification_action" value="pin"
|
||||||
data-status="pinned"
|
>
|
||||||
data-page="{{$.Page.Paginater.Current}}"
|
|
||||||
data-notification-id="{{.ID}}"
|
|
||||||
data-q="{{$.Keyword}}">
|
|
||||||
{{svg "octicon-pin"}}
|
{{svg "octicon-pin"}}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if or (eq .Status 1) (eq .Status 3)}}
|
{{if or (eq $one.Status $statusUnread) (eq $one.Status $statusPinned)}}
|
||||||
<form action="{{AppSubUrl}}/notifications/status" method="post">
|
<button class="btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "notification.mark_as_read"}}"
|
||||||
{{$.CsrfTokenHtml}}
|
name="notification_action" value="mark_as_read"
|
||||||
<input type="hidden" name="notification_id" value="{{.ID}}">
|
>
|
||||||
<input type="hidden" name="status" value="read">
|
|
||||||
<input type="hidden" name="page" value="{{$.Page.Paginater.Current}}">
|
|
||||||
<button class="btn interact-bg tw-p-2" title="{{ctx.Locale.Tr "notification.mark_as_read"}}"
|
|
||||||
data-url="{{AppSubUrl}}/notifications/status"
|
|
||||||
data-status="read"
|
|
||||||
data-page="{{$.Page.Paginater.Current}}"
|
|
||||||
data-notification-id="{{.ID}}"
|
|
||||||
data-q="{{$.Keyword}}">
|
|
||||||
{{svg "octicon-check"}}
|
{{svg "octicon-check"}}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
{{else if eq $one.Status $statusRead}}
|
||||||
{{else if eq .Status 2}}
|
<button class="btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "notification.mark_as_unread"}}"
|
||||||
<form action="{{AppSubUrl}}/notifications/status" method="post">
|
name="notification_action" value="mark_as_unread"
|
||||||
{{$.CsrfTokenHtml}}
|
>
|
||||||
<input type="hidden" name="notification_id" value="{{.ID}}">
|
|
||||||
<input type="hidden" name="status" value="unread">
|
|
||||||
<input type="hidden" name="page" value="{{$.Page.Paginater.Current}}">
|
|
||||||
<button class="btn interact-bg tw-p-2" title="{{ctx.Locale.Tr "notification.mark_as_unread"}}"
|
|
||||||
data-url="{{AppSubUrl}}/notifications/status"
|
|
||||||
data-status="unread"
|
|
||||||
data-page="{{$.Page.Paginater.Current}}"
|
|
||||||
data-notification-id="{{.ID}}"
|
|
||||||
data-q="{{$.Keyword}}">
|
|
||||||
{{svg "octicon-bell"}}
|
{{svg "octicon-bell"}}
|
||||||
</button>
|
</button>
|
||||||
|
{{end}}
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div class="empty-placeholder">
|
||||||
|
{{svg "octicon-inbox" 56 "tw-mb-4"}}
|
||||||
|
{{if $pageTypeIsRead}}
|
||||||
|
{{ctx.Locale.Tr "notification.no_read"}}
|
||||||
|
{{else}}
|
||||||
|
{{ctx.Locale.Tr "notification.no_unread"}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{{template "base/paginate" .}}
|
{{template "base/paginate" .}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -114,6 +114,14 @@
|
|||||||
border-radius: var(--border-radius);
|
border-radius: var(--border-radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notifications-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5em;
|
||||||
|
padding: 0.5em 1em;
|
||||||
|
}
|
||||||
|
|
||||||
.notifications-item:hover {
|
.notifications-item:hover {
|
||||||
background: var(--color-hover);
|
background: var(--color-hover);
|
||||||
}
|
}
|
||||||
@ -129,6 +137,9 @@
|
|||||||
|
|
||||||
.notifications-item:hover .notifications-buttons {
|
.notifications-item:hover .notifications-buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: end;
|
||||||
|
gap: 0.25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.notifications-item:hover .notifications-updated {
|
.notifications-item:hover .notifications-updated {
|
||||||
|
@ -1,40 +1,13 @@
|
|||||||
import {GET} from '../modules/fetch.ts';
|
import {GET} from '../modules/fetch.ts';
|
||||||
import {toggleElem, type DOMEvent, createElementFromHTML} from '../utils/dom.ts';
|
import {toggleElem, createElementFromHTML} from '../utils/dom.ts';
|
||||||
import {logoutFromWorker} from '../modules/worker.ts';
|
import {logoutFromWorker} from '../modules/worker.ts';
|
||||||
|
|
||||||
const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config;
|
const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config;
|
||||||
let notificationSequenceNumber = 0;
|
let notificationSequenceNumber = 0;
|
||||||
|
|
||||||
export function initNotificationsTable() {
|
async function receiveUpdateCount(event: MessageEvent<{type: string, data: string}>) {
|
||||||
const table = document.querySelector('#notification_table');
|
|
||||||
if (!table) return;
|
|
||||||
|
|
||||||
// when page restores from bfcache, delete previously clicked items
|
|
||||||
window.addEventListener('pageshow', (e) => {
|
|
||||||
if (e.persisted) { // page was restored from bfcache
|
|
||||||
const table = document.querySelector('#notification_table');
|
|
||||||
const unreadCountEl = document.querySelector<HTMLElement>('.notifications-unread-count');
|
|
||||||
let unreadCount = parseInt(unreadCountEl.textContent);
|
|
||||||
for (const item of table.querySelectorAll('.notifications-item[data-remove="true"]')) {
|
|
||||||
item.remove();
|
|
||||||
unreadCount -= 1;
|
|
||||||
}
|
|
||||||
unreadCountEl.textContent = String(unreadCount);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// mark clicked unread links for deletion on bfcache restore
|
|
||||||
for (const link of table.querySelectorAll<HTMLAnchorElement>('.notifications-item[data-status="1"] .notifications-link')) {
|
|
||||||
link.addEventListener('click', (e: DOMEvent<MouseEvent>) => {
|
|
||||||
e.target.closest('.notifications-item').setAttribute('data-remove', 'true');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function receiveUpdateCount(event: MessageEvent) {
|
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data.data);
|
||||||
|
|
||||||
for (const count of document.querySelectorAll('.notification_count')) {
|
for (const count of document.querySelectorAll('.notification_count')) {
|
||||||
count.classList.toggle('tw-hidden', data.Count === 0);
|
count.classList.toggle('tw-hidden', data.Count === 0);
|
||||||
count.textContent = `${data.Count}`;
|
count.textContent = `${data.Count}`;
|
||||||
@ -71,7 +44,7 @@ export function initNotificationCount() {
|
|||||||
type: 'start',
|
type: 'start',
|
||||||
url: `${window.location.origin}${appSubUrl}/user/events`,
|
url: `${window.location.origin}${appSubUrl}/user/events`,
|
||||||
});
|
});
|
||||||
worker.port.addEventListener('message', (event: MessageEvent) => {
|
worker.port.addEventListener('message', (event: MessageEvent<{type: string, data: string}>) => {
|
||||||
if (!event.data || !event.data.type) {
|
if (!event.data || !event.data.type) {
|
||||||
console.error('unknown worker message event', event);
|
console.error('unknown worker message event', event);
|
||||||
return;
|
return;
|
||||||
@ -144,11 +117,11 @@ async function updateNotificationCountWithCallback(callback: (timeout: number, n
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function updateNotificationTable() {
|
async function updateNotificationTable() {
|
||||||
const notificationDiv = document.querySelector('#notification_div');
|
let notificationDiv = document.querySelector('#notification_div');
|
||||||
if (notificationDiv) {
|
if (notificationDiv) {
|
||||||
try {
|
try {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
params.set('div-only', String(true));
|
params.set('div-only', 'true');
|
||||||
params.set('sequence-number', String(++notificationSequenceNumber));
|
params.set('sequence-number', String(++notificationSequenceNumber));
|
||||||
const response = await GET(`${appSubUrl}/notifications?${params.toString()}`);
|
const response = await GET(`${appSubUrl}/notifications?${params.toString()}`);
|
||||||
|
|
||||||
@ -160,7 +133,8 @@ async function updateNotificationTable() {
|
|||||||
const el = createElementFromHTML(data);
|
const el = createElementFromHTML(data);
|
||||||
if (parseInt(el.getAttribute('data-sequence-number')) === notificationSequenceNumber) {
|
if (parseInt(el.getAttribute('data-sequence-number')) === notificationSequenceNumber) {
|
||||||
notificationDiv.outerHTML = data;
|
notificationDiv.outerHTML = data;
|
||||||
initNotificationsTable();
|
notificationDiv = document.querySelector('#notification_div');
|
||||||
|
window.htmx.process(notificationDiv); // when using htmx, we must always remember to process the new content changed by us
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -15,7 +15,7 @@ import {initTableSort} from './features/tablesort.ts';
|
|||||||
import {initAdminUserListSearchForm} from './features/admin/users.ts';
|
import {initAdminUserListSearchForm} from './features/admin/users.ts';
|
||||||
import {initAdminConfigs} from './features/admin/config.ts';
|
import {initAdminConfigs} from './features/admin/config.ts';
|
||||||
import {initMarkupAnchors} from './markup/anchors.ts';
|
import {initMarkupAnchors} from './markup/anchors.ts';
|
||||||
import {initNotificationCount, initNotificationsTable} from './features/notification.ts';
|
import {initNotificationCount} from './features/notification.ts';
|
||||||
import {initRepoIssueContentHistory} from './features/repo-issue-content.ts';
|
import {initRepoIssueContentHistory} from './features/repo-issue-content.ts';
|
||||||
import {initStopwatch} from './features/stopwatch.ts';
|
import {initStopwatch} from './features/stopwatch.ts';
|
||||||
import {initFindFileInRepo} from './features/repo-findfile.ts';
|
import {initFindFileInRepo} from './features/repo-findfile.ts';
|
||||||
@ -117,7 +117,6 @@ const initPerformanceTracer = callInitFunctions([
|
|||||||
initDashboardRepoList,
|
initDashboardRepoList,
|
||||||
|
|
||||||
initNotificationCount,
|
initNotificationCount,
|
||||||
initNotificationsTable,
|
|
||||||
|
|
||||||
initOrgTeam,
|
initOrgTeam,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user