blessing-skin-server/resources/assets/src/scripts/notification.ts
2019-07-03 16:19:13 +08:00

26 lines
746 B
TypeScript

import { get } from './net'
import { showModal } from './notify'
export default async function handler(event: Event) {
const item = event.target as HTMLAnchorElement
const id = item.getAttribute('data-nid')
const {
title, content, time,
} = await get(`/user/notifications/${id}`)
showModal(`${content}<br><small>${time}</small>`, title)
item.remove()
const counter = document.querySelector('.notifications-counter') as HTMLSpanElement
const value = Number.parseInt(counter.textContent!) - 1
if (value > 0) {
counter.textContent = value.toString()
} else {
counter.remove()
}
}
const el = document.querySelector('.notifications-list')
// istanbul ignore next
if (el) {
el.addEventListener('click', handler)
}