Implemented forum likes
This commit is contained in:
parent
7579c52188
commit
1f4dc0a05d
@ -30,14 +30,13 @@ component Postable(post arn.Postable, user *arn.User, highlightAuthorID string)
|
|||||||
.post-likes(id="likes-" + post.ID(), title="Likes")= len(post.Likes())
|
.post-likes(id="likes-" + post.ID(), title="Likes")= len(post.Likes())
|
||||||
|
|
||||||
if user != nil
|
if user != nil
|
||||||
//- if user.ID !== post.authorId
|
if user.ID != post.Author().ID
|
||||||
//- - var liked = post.likes && post.likes.indexOf(user.ID) !== -1
|
if post.LikedBy(user.ID)
|
||||||
|
a.post-tool.post-unlike.action(id="unlike-" + post.ID(), title="Unlike", data-action="unlike", data-trigger="click")
|
||||||
//- a.post-tool.post-like(id="like-" + post.ID, onclick=`$.like("${type.toLowerCase()}", "${post.ID}")`, title="Like", class=liked ? "hidden" : ")
|
RawIcon("thumbs-down")
|
||||||
//- i.fa.fa-thumbs-up.fa-fw
|
else
|
||||||
|
a.post-tool.post-like.action(id="like-" + post.ID(), title="Like", data-action="like", data-trigger="click")
|
||||||
//- a.post-tool.post-unlike(id="unlike-" + post.ID, onclick=`$.unlike("${type.toLowerCase()}", "${post.ID}")`, title="Unlike", class=!liked ? "hidden" : ")
|
RawIcon("thumbs-up")
|
||||||
//- i.fa.fa-thumbs-down.fa-fw
|
|
||||||
|
|
||||||
if user.ID == post.Author().ID
|
if user.ID == post.Author().ID
|
||||||
a.post-tool.post-edit.action(data-action="editPost", data-trigger="click", data-id=post.ID(), title="Edit")
|
a.post-tool.post-edit.action(data-action="editPost", data-trigger="click", data-id=post.ID(), title="Edit")
|
||||||
|
@ -115,6 +115,24 @@ export function savePost(arn: AnimeNotifier, element: HTMLElement) {
|
|||||||
.catch(console.error)
|
.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
|
// Forum reply
|
||||||
export function forumReply(arn: AnimeNotifier) {
|
export function forumReply(arn: AnimeNotifier) {
|
||||||
let textarea = arn.app.find("new-reply") as HTMLTextAreaElement
|
let textarea = arn.app.find("new-reply") as HTMLTextAreaElement
|
||||||
|
@ -182,23 +182,36 @@ export class AnimeNotifier {
|
|||||||
|
|
||||||
assignActions() {
|
assignActions() {
|
||||||
for(let element of findAll("action")) {
|
for(let element of findAll("action")) {
|
||||||
if(element["action assigned"]) {
|
let actionTrigger = element.dataset.trigger
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
let actionName = element.dataset.action
|
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)
|
actions[actionName](this, element, e)
|
||||||
|
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
})
|
}
|
||||||
|
|
||||||
|
element.addEventListener(actionTrigger, actionHandler)
|
||||||
|
|
||||||
// Use "action assigned" flag instead of removing the class.
|
// Use "action assigned" flag instead of removing the class.
|
||||||
// This will make sure that DOM diffs which restore the class name
|
// This will make sure that DOM diffs which restore the class name
|
||||||
// will not assign the action multiple times to the same element.
|
// 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 elemA = a as HTMLElement
|
||||||
let elemB = b as HTMLElement
|
let elemB = b as HTMLElement
|
||||||
|
|
||||||
// Skip iframes
|
// Skip iframes and lazy loaded images
|
||||||
if(elemA.tagName === "IFRAME") {
|
if(elemA.tagName === "IFRAME" || elemA.classList.contains("lazy")) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
tests.go
4
tests.go
@ -186,6 +186,7 @@ var routeTests = map[string][]string{
|
|||||||
"/anime/:id/edit": nil,
|
"/anime/:id/edit": nil,
|
||||||
"/new/thread": nil,
|
"/new/thread": nil,
|
||||||
"/new/soundtrack": nil,
|
"/new/soundtrack": nil,
|
||||||
|
"/editor": nil,
|
||||||
"/user": nil,
|
"/user": nil,
|
||||||
"/settings": nil,
|
"/settings": nil,
|
||||||
"/extension/embed": nil,
|
"/extension/embed": nil,
|
||||||
@ -194,6 +195,7 @@ var routeTests = map[string][]string{
|
|||||||
// API interfaces
|
// API interfaces
|
||||||
var creatable = reflect.TypeOf((*api.Creatable)(nil)).Elem()
|
var creatable = reflect.TypeOf((*api.Creatable)(nil)).Elem()
|
||||||
var updatable = reflect.TypeOf((*api.Updatable)(nil)).Elem()
|
var updatable = reflect.TypeOf((*api.Updatable)(nil)).Elem()
|
||||||
|
var actionable = reflect.TypeOf((*api.Actionable)(nil)).Elem()
|
||||||
var collection = reflect.TypeOf((*api.Collection)(nil)).Elem()
|
var collection = reflect.TypeOf((*api.Collection)(nil)).Elem()
|
||||||
|
|
||||||
// Required interface implementations
|
// Required interface implementations
|
||||||
@ -204,10 +206,12 @@ var interfaceImplementations = map[string][]reflect.Type{
|
|||||||
"Thread": []reflect.Type{
|
"Thread": []reflect.Type{
|
||||||
creatable,
|
creatable,
|
||||||
updatable,
|
updatable,
|
||||||
|
actionable,
|
||||||
},
|
},
|
||||||
"Post": []reflect.Type{
|
"Post": []reflect.Type{
|
||||||
creatable,
|
creatable,
|
||||||
updatable,
|
updatable,
|
||||||
|
actionable,
|
||||||
},
|
},
|
||||||
"SoundTrack": []reflect.Type{
|
"SoundTrack": []reflect.Type{
|
||||||
creatable,
|
creatable,
|
||||||
|
Loading…
Reference in New Issue
Block a user