Implemented forum overview

This commit is contained in:
Eduard Urbach 2016-11-19 02:58:00 +09:00
parent e23f843450
commit b5be7e9cef
17 changed files with 130 additions and 13 deletions

1
.gitignore vendored
View File

@ -29,6 +29,7 @@ _testmain.go
# external packages folder
vendor/
node_modules/
tmp/
# debugger
debug

15
api.go
View File

@ -3,7 +3,6 @@ package main
import (
"sort"
"strings"
"time"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
@ -11,7 +10,6 @@ import (
func init() {
app.Get("/all/anime", func(ctx *aero.Context) string {
start := time.Now()
var titles []string
results := make(chan *arn.Anime)
@ -22,7 +20,7 @@ func init() {
}
sort.Strings(titles)
return ctx.Text(s(len(titles)) + " anime fetched in " + s(time.Since(start)) + "\n\n" + strings.Join(titles, "\n"))
return ctx.Text(toString(len(titles)) + "\n\n" + strings.Join(titles, "\n"))
})
app.Get("/api/anime/:id", func(ctx *aero.Context) string {
@ -46,4 +44,15 @@ func init() {
return ctx.JSON(user)
})
app.Get("/api/threads/:id", func(ctx *aero.Context) string {
id := ctx.Get("id")
thread, err := arn.GetThread(id)
if err != nil {
return ctx.Text("Thread not found")
}
return ctx.JSON(thread)
})
}

View File

@ -3,7 +3,7 @@ package main
import "fmt"
// Converts anything into a string
func s(v interface{}) string {
func toString(v interface{}) string {
return fmt.Sprint(v)
}

View File

@ -23,10 +23,14 @@ component Content(content string)
component Navigation
nav#navigation
a.navigation-link.navigation-link-left.ajax(href="/")
NavigationButton("Dash", "/", "dashboard")
NavigationButton("Forum", "/forum", "comment")
component NavigationButton(name string, target string, icon string)
a.navigation-link.navigation-link-left.ajax(href=target)
.navigation-button
i.fa.fa-dashboard
span.navigation-text Dash
i(class="fa fa-" + icon)
span.navigation-text= name
component LoadingAnimation
#loading-animation.sk-cube-grid.fade

12
mixins/Avatar.pixy Normal file
View File

@ -0,0 +1,12 @@
component Avatar(user *arn.User)
a.user.ajax(href="/+" + user.Nick, title=user.Nick)
if user.Avatar != ""
if strings.Contains(user.Avatar, "gravatar.com")
img.user-image(src=user.Avatar + "?s=100&r=x&d=mm", alt=user.Nick)
else
img.user-image(src=user.Avatar, alt=user.Nick)
else
svg.user-image(width="50", height="50")
circle.head(cx="25", cy="19", r="10", fill="rgb(32, 32, 32)")
circle.body(cx="25", cy="50", r="20")
//- text(x="25", y="44", text-anchor="middle") TODO

View File

@ -49,7 +49,7 @@ component Anime(anime *arn.Anime)
h3.anime-header Studios
.light-button-group
each studio in anime.Studios
a.light-button(href="https://anilist.co/studio/" + s(studio.ID), target="_blank")
a.light-button(href="https://anilist.co/studio/" + toString(studio.ID), target="_blank")
i.fa.fa-building.fa-fw
span= studio.Name
@ -106,7 +106,7 @@ component Anime(anime *arn.Anime)
a.light-button(href=link.URL, target="_blank")= link.Title
if anime.CreatedBy == ""
a.light-button(href="https://anilist.co/anime/" + s(anime.ID), target="_blank") AniList
a.light-button(href="https://anilist.co/anime/" + toString(anime.ID), target="_blank") AniList
//- if providers.HummingBird
//- a.light-button(href="https://hummingbird.me/anime/" + providers.HummingBird.providerId, target="_blank") HummingBird

35
pages/forum/forum.pixy Normal file
View File

@ -0,0 +1,35 @@
component Forum(threads []*arn.Thread)
h2 Forum
ForumHeader
each thread in threads
ThreadLink(thread)
component ForumHeader
.forum-tags
a.ajax(href="/forum") All
span |
a.ajax(href="/forum/general") General
span |
a.ajax(href="/forum/news") News
span |
a.ajax(href="/forum/anime") Anime
span |
a.ajax(href="/forum/update") Updates
span |
a.ajax(href="/forum/suggestion") Suggestions
span |
a.ajax(href="/forum/bug") Bugs
component ThreadLink(thread *arn.Thread)
.thread(data-stick=toString(thread.Sticky))
.post-author.thread-author
Avatar(thread.Author)
.thread-content-container
.post-content.thread-content
if thread.Sticky
i.fa.fa-thumb-tack.fa-fw.thread-icon
a.thread-title.ajax(href="/threads/" + thread.ID)= thread.Title
//- .thread-icons
//- each icon in thread.Icons
//- i(class='fa fa-' + icon + ' fa-fw thread-icon')
//- .thread-reply-count= 25

37
pages/forum/forum.styl Normal file
View File

@ -0,0 +1,37 @@
.forum-tags
text-align left
margin-bottom 1.5rem
.thread
display flex
flex-flow row
width 100%
.thread-icons
.thread-reply-count
flex 1
text-align right
opacity 0.5
.thread-reply-count
&:after
content " replies"
.thread-content-container
display flex
align-items center
width 100%
.thread-content
display flex
align-items center
justify-content flex-start
text-align left
min-height 80%
a
color rgb(32, 32, 32) !important
&:hover
color linkHoverColor !important
.thread-icon
font-size 0.9em

View File

@ -11,5 +11,5 @@ component AnimeInGenre(genre string, animeList []*arn.Anime)
h2.genre-header= arn.Capitalize(genre)
.genre-anime-list
each anime in animeList
a.genre-anime-link.ajax(href="/anime/" + s(anime.ID))
img.anime-image.genre-anime-image(src=anime.Image, alt=anime.Title.Romaji, title=anime.Title.Romaji + " (" + s(anime.Watching) + ")")
a.genre-anime-link.ajax(href="/anime/" + toString(anime.ID))
img.anime-image.genre-anime-image(src=anime.Image, alt=anime.Title.Romaji, title=anime.Title.Romaji + " (" + toString(anime.Watching) + ")")

View File

@ -38,4 +38,24 @@ func init() {
return ctx.HTML(components.AnimeInGenre(genreInfo.Genre, genreInfo.AnimeList))
})
const threadsPerPage = 12
forumHandler := func(ctx *aero.Context) string {
tag := ctx.Get("tag")
threads, _ := arn.GetThreadsByTag(tag)
if len(threads) > threadsPerPage {
threads = threads[:threadsPerPage]
}
for _, thread := range threads {
thread.Author, _ = arn.GetUser(thread.AuthorID)
}
return ctx.HTML(components.Forum(threads))
}
app.Ajax("/forum", forumHandler)
app.Ajax("/forum/:tag", forumHandler)
}

View File

@ -73,7 +73,6 @@
& > div
float left
width 100%
text-align center
.header-logged-in
background-image none !important