Create new thread
This commit is contained in:
parent
4d24b817ff
commit
8758baa0fa
2
main.go
2
main.go
@ -18,6 +18,7 @@ import (
|
||||
"github.com/animenotifier/notify.moe/pages/forum"
|
||||
"github.com/animenotifier/notify.moe/pages/forums"
|
||||
"github.com/animenotifier/notify.moe/pages/login"
|
||||
"github.com/animenotifier/notify.moe/pages/newthread"
|
||||
"github.com/animenotifier/notify.moe/pages/popularanime"
|
||||
"github.com/animenotifier/notify.moe/pages/posts"
|
||||
"github.com/animenotifier/notify.moe/pages/profile"
|
||||
@ -64,6 +65,7 @@ func configure(app *aero.Application) *aero.Application {
|
||||
app.Ajax("/user/:nick/posts", profile.GetPostsByUser)
|
||||
app.Ajax("/user/:nick/animelist", animelist.Get)
|
||||
app.Ajax("/user/:nick/animelist/:id", animelistitem.Get)
|
||||
app.Ajax("/new/thread", newthread.Get)
|
||||
app.Ajax("/settings", settings.Get)
|
||||
app.Ajax("/admin", admin.Get)
|
||||
app.Ajax("/search/:term", search.Get)
|
||||
|
@ -4,8 +4,12 @@ component Forum(tag string, threads []*arn.Thread, threadsPerPage int)
|
||||
.forum
|
||||
ThreadList(threads)
|
||||
|
||||
if len(threads) == threadsPerPage
|
||||
.buttons
|
||||
|
||||
.buttons
|
||||
button#new-thread.action(data-action="load", data-trigger="click", data-url="/new/thread")
|
||||
Icon("plus")
|
||||
span New thread
|
||||
if len(threads) == threadsPerPage
|
||||
button
|
||||
Icon("refresh")
|
||||
span Load more
|
||||
|
@ -29,5 +29,8 @@
|
||||
.forum-tag-text
|
||||
display none
|
||||
|
||||
#load-more-threads
|
||||
margin-top 1rem
|
||||
> 1250px
|
||||
#new-thread
|
||||
position fixed
|
||||
right content-padding
|
||||
bottom content-padding
|
||||
|
20
pages/newthread/newthread.go
Normal file
20
pages/newthread/newthread.go
Normal file
@ -0,0 +1,20 @@
|
||||
package newthread
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
// Get forums page.
|
||||
func Get(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
if user == nil {
|
||||
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.NewThread(user))
|
||||
}
|
20
pages/newthread/newthread.pixy
Normal file
20
pages/newthread/newthread.pixy
Normal file
@ -0,0 +1,20 @@
|
||||
component NewThread(user *arn.User)
|
||||
.widgets
|
||||
.widget
|
||||
input#title.widget-element(type="text", placeholder="Title")
|
||||
|
||||
textarea#text.widget-element(placeholder="Content")
|
||||
|
||||
select#tag.widget-element
|
||||
option(value="general") General
|
||||
option(value="news") News
|
||||
option(value="anime") Anime
|
||||
option(value="bug") Bug
|
||||
option(value="suggestion") Suggestion
|
||||
|
||||
if user.Role == "admin"
|
||||
option(value="update") Update
|
||||
|
||||
button.action(data-action="createThread", data-trigger="click")
|
||||
Icon("check")
|
||||
span Create thread
|
@ -153,7 +153,7 @@ export class AnimeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
load(url: string) {
|
||||
diff(url: string) {
|
||||
let request = fetch("/_" + url, {
|
||||
credentials: "same-origin"
|
||||
})
|
||||
@ -175,6 +175,20 @@ export class AnimeNotifier {
|
||||
})
|
||||
}
|
||||
|
||||
post(url, obj) {
|
||||
return fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(obj),
|
||||
credentials: "same-origin"
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(body => {
|
||||
if(body !== "ok") {
|
||||
throw body
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onPopState(e: PopStateEvent) {
|
||||
if(e.state) {
|
||||
this.app.load(e.state, {
|
||||
|
@ -57,10 +57,16 @@ export function save(arn: AnimeNotifier, input: HTMLInputElement | HTMLTextAreaE
|
||||
})
|
||||
}
|
||||
|
||||
// Load
|
||||
export function load(arn: AnimeNotifier, element: HTMLElement) {
|
||||
let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
|
||||
arn.app.load(url)
|
||||
}
|
||||
|
||||
// Diff
|
||||
export function diff(arn: AnimeNotifier, element: HTMLElement) {
|
||||
let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
|
||||
arn.load(url)
|
||||
arn.diff(url)
|
||||
}
|
||||
|
||||
// Forum reply
|
||||
@ -74,20 +80,26 @@ export function forumReply(arn: AnimeNotifier) {
|
||||
tags: []
|
||||
}
|
||||
|
||||
fetch("/api/post/new", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(post),
|
||||
credentials: "same-origin"
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(body => {
|
||||
if(body !== "ok") {
|
||||
throw body
|
||||
}
|
||||
|
||||
textarea.value = ""
|
||||
})
|
||||
arn.post("/api/post/new", post)
|
||||
.then(() => arn.reloadContent())
|
||||
.then(() => textarea.value = "")
|
||||
.catch(console.error)
|
||||
}
|
||||
|
||||
// Create thread
|
||||
export function createThread(arn: AnimeNotifier) {
|
||||
let title = arn.app.find("title") as HTMLInputElement
|
||||
let text = arn.app.find("text") as HTMLTextAreaElement
|
||||
let category = arn.app.find("tag") as HTMLInputElement
|
||||
|
||||
let thread = {
|
||||
title: title.value,
|
||||
text: text.value,
|
||||
tags: [category.value]
|
||||
}
|
||||
|
||||
arn.post("/api/thread/new", thread)
|
||||
.then(() => arn.app.load("/forum/" + thread.tags[0]))
|
||||
.catch(console.error)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user