From 877b2433e4aa97d438a4d2b5afa8aa6d688905a8 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 20 Jun 2017 14:16:23 +0200 Subject: [PATCH] General improvements --- main.go | 2 ++ mixins/Navigation.pixy | 3 ++- pages/anime/anime.scarlet | 3 +++ pages/profile/profile.go | 5 +++++ pages/user/user.go | 24 ++++++++++++++++++++++++ scripts/AnimeNotifier.ts | 18 ++++++++++++++++++ scripts/Application.ts | 2 +- scripts/main.ts | 8 ++------ styles/include/config.scarlet | 1 + styles/loading.scarlet | 2 +- tests.go | 9 +++++++++ 11 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 pages/user/user.go diff --git a/main.go b/main.go index 856ec6dd..b6dfb3d0 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ import ( "github.com/animenotifier/notify.moe/pages/search" "github.com/animenotifier/notify.moe/pages/settings" "github.com/animenotifier/notify.moe/pages/threads" + "github.com/animenotifier/notify.moe/pages/user" "github.com/animenotifier/notify.moe/pages/users" "github.com/animenotifier/notify.moe/pages/webdev" "github.com/animenotifier/notify.moe/utils" @@ -50,6 +51,7 @@ func main() { app.Ajax("/forum/:tag", forum.Get) app.Ajax("/threads/:id", threads.Get) app.Ajax("/posts/:id", posts.Get) + app.Ajax("/user", user.Get) app.Ajax("/user/:nick", profile.Get) app.Ajax("/user/:nick/threads", profile.GetThreadsByUser) app.Ajax("/user/:nick/animelist", animelist.Get) diff --git a/mixins/Navigation.pixy b/mixins/Navigation.pixy index 70cf58f4..244dc8be 100644 --- a/mixins/Navigation.pixy +++ b/mixins/Navigation.pixy @@ -16,12 +16,13 @@ component LoggedInMenu(user *arn.User) nav#navigation NavigationButton("Dash", "/", "inbox") NavigationButton("Anime", "/anime", "television") + NavigationButton("Profile", "/+", "user") NavigationButton("Forum", "/forum", "comment") - NavigationButton("Airing", "/airing", "rss") NavigationButton("Settings", "/settings", "cog") .extra-navigation ExtraNavigationButton("Users", "/users", "globe") + ExtraNavigationButton("Airing", "/airing", "rss") if user.Role == "admin" ExtraNavigationButton("Admin", "/admin", "wrench") diff --git a/pages/anime/anime.scarlet b/pages/anime/anime.scarlet index ba6fdfc4..30977a69 100644 --- a/pages/anime/anime.scarlet +++ b/pages/anime/anime.scarlet @@ -46,7 +46,10 @@ horizontal justify-content center margin content-padding 0 + + // Setting z-index requires setting a background as well z-index 10 + background-color bg-color > 900px .anime-actions diff --git a/pages/profile/profile.go b/pages/profile/profile.go index 47f6ff19..8cfbeba9 100644 --- a/pages/profile/profile.go +++ b/pages/profile/profile.go @@ -18,6 +18,11 @@ func Get(ctx *aero.Context) string { return ctx.Error(404, "User not found", err) } + return Profile(ctx, viewUser) +} + +// Profile renders the user profile page of the given viewUser. +func Profile(ctx *aero.Context, viewUser *arn.User) string { var user *arn.User var threads []*arn.Thread var animeList *arn.AnimeList diff --git a/pages/user/user.go b/pages/user/user.go new file mode 100644 index 00000000..fabf39f0 --- /dev/null +++ b/pages/user/user.go @@ -0,0 +1,24 @@ +package user + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/pages/profile" + "github.com/animenotifier/notify.moe/utils" +) + +// Get redirects /+ to /+UserName +func Get(ctx *aero.Context) string { + user := utils.GetUser(ctx) + + if user == nil { + return ctx.Error(http.StatusBadRequest, "Not logged in", nil) + } + + if user.Nick == "" { + return ctx.Error(http.StatusInternalServerError, "User did not set a nickname", nil) + } + + return profile.Profile(ctx, user) +} diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 32dddff2..c901e17c 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -43,6 +43,14 @@ export class AnimeNotifier { } } + onPopState(e: PopStateEvent) { + if(e.state) { + this.app.load(e.state, false) + } else if(this.app.currentPath !== this.app.originalPath) { + this.app.load(this.app.originalPath, false) + } + } + updateAvatars() { for(let element of findAll(".user-image")) { let img = element as HTMLImageElement @@ -60,4 +68,14 @@ export class AnimeNotifier { } } } + + // onResize(e: UIEvent) { + // let hasScrollbar = this.app.content.clientHeight === this.app.content.scrollHeight + + // if(hasScrollbar) { + // this.app.content.classList.add("has-scrollbar") + // } else { + // this.app.content.classList.remove("has-scrollbar") + // } + // } } \ No newline at end of file diff --git a/scripts/Application.ts b/scripts/Application.ts index b4a75d85..00dea2ce 100644 --- a/scripts/Application.ts +++ b/scripts/Application.ts @@ -55,7 +55,7 @@ export class Application { this.currentPath = url // Start sending a network request - let request = this.get("/_" + url) + let request = this.get("/_" + url).catch(error => error) let onTransitionEnd = e => { // Ignore transitions of child elements. diff --git a/scripts/main.ts b/scripts/main.ts index bdeeab3a..dd889a8f 100644 --- a/scripts/main.ts +++ b/scripts/main.ts @@ -7,9 +7,5 @@ let arn = new AnimeNotifier(app) document.addEventListener("DOMContentLoaded", arn.onContentLoaded.bind(arn)) document.addEventListener("readystatechange", arn.onReadyStateChange.bind(arn)) -window.onpopstate = e => { - if(e.state) - app.load(e.state, false) - else if(app.currentPath !== app.originalPath) - app.load(app.originalPath, false) -} \ No newline at end of file +window.addEventListener("popstate", arn.onPopState.bind(arn)) +// window.addEventListener("resize", arn.onResize.bind(arn)) \ No newline at end of file diff --git a/styles/include/config.scarlet b/styles/include/config.scarlet index d2d0d6df..f9104274 100644 --- a/styles/include/config.scarlet +++ b/styles/include/config.scarlet @@ -5,6 +5,7 @@ link-color = rgb(225, 38, 15) link-hover-color = rgb(242, 60, 30) link-active-color = rgb(100, 149, 237) post-highlight-color = rgba(248, 165, 130, 0.7) +bg-color = white // UI ui-border = 1px solid rgba(0, 0, 0, 0.1) diff --git a/styles/loading.scarlet b/styles/loading.scarlet index 2aebb5b0..22b532b5 100644 --- a/styles/loading.scarlet +++ b/styles/loading.scarlet @@ -4,7 +4,7 @@ loading-anim-size = 24px #loading position fixed bottom 1.15rem - right calc(1.15rem + 17px) + right 1.15rem pointer-events none .sk-cube-grid diff --git a/tests.go b/tests.go index 9da41aa3..324306ae 100644 --- a/tests.go +++ b/tests.go @@ -10,6 +10,14 @@ func init() { "/+Akyoto/threads", }) + app.Test("/user/:nick/animelist", []string{ + "/+Akyoto/animelist", + }) + + app.Test("/user/:nick/animelist/:id", []string{ + "/+Akyoto/animelist/7929", + }) + // Pages app.Test("/anime/:id", []string{ "/anime/1", @@ -92,4 +100,5 @@ func init() { // Disable app.Test("/auth/google", nil) app.Test("/auth/google/callback", nil) + app.Test("/user", nil) }