Implemented forum likes
This commit is contained in:
@ -115,6 +115,24 @@ export function savePost(arn: AnimeNotifier, element: HTMLElement) {
|
||||
.catch(console.error)
|
||||
}
|
||||
|
||||
// like
|
||||
export function like(arn: AnimeNotifier, element: HTMLElement) {
|
||||
let apiEndpoint = arn.findAPIEndpoint(element)
|
||||
|
||||
arn.post(apiEndpoint + "/like", null)
|
||||
.then(() => arn.reloadContent())
|
||||
.catch(console.error)
|
||||
}
|
||||
|
||||
// unlike
|
||||
export function unlike(arn: AnimeNotifier, element: HTMLElement) {
|
||||
let apiEndpoint = arn.findAPIEndpoint(element)
|
||||
|
||||
arn.post(apiEndpoint + "/unlike", null)
|
||||
.then(() => arn.reloadContent())
|
||||
.catch(console.error)
|
||||
}
|
||||
|
||||
// Forum reply
|
||||
export function forumReply(arn: AnimeNotifier) {
|
||||
let textarea = arn.app.find("new-reply") as HTMLTextAreaElement
|
||||
|
@ -182,23 +182,36 @@ export class AnimeNotifier {
|
||||
|
||||
assignActions() {
|
||||
for(let element of findAll("action")) {
|
||||
if(element["action assigned"]) {
|
||||
continue
|
||||
}
|
||||
|
||||
let actionTrigger = element.dataset.trigger
|
||||
let actionName = element.dataset.action
|
||||
|
||||
element.addEventListener(element.dataset.trigger, e => {
|
||||
let oldAction = element["action assigned"]
|
||||
|
||||
if(oldAction) {
|
||||
if(oldAction.trigger === actionTrigger && oldAction.action === actionName) {
|
||||
continue
|
||||
}
|
||||
|
||||
element.removeEventListener(oldAction.trigger, oldAction.handler)
|
||||
}
|
||||
|
||||
let actionHandler = e => {
|
||||
actions[actionName](this, element, e)
|
||||
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
})
|
||||
}
|
||||
|
||||
element.addEventListener(actionTrigger, actionHandler)
|
||||
|
||||
// Use "action assigned" flag instead of removing the class.
|
||||
// This will make sure that DOM diffs which restore the class name
|
||||
// will not assign the action multiple times to the same element.
|
||||
element["action assigned"] = true
|
||||
element["action assigned"] = {
|
||||
trigger: actionTrigger,
|
||||
action: actionName,
|
||||
handler: actionHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,8 @@ export class Diff {
|
||||
let elemA = a as HTMLElement
|
||||
let elemB = b as HTMLElement
|
||||
|
||||
// Skip iframes
|
||||
if(elemA.tagName === "IFRAME") {
|
||||
// Skip iframes and lazy loaded images
|
||||
if(elemA.tagName === "IFRAME" || elemA.classList.contains("lazy")) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user