diff --git a/web/static/index.js b/web/static/index.js index d7ed31f..c2c0fa2 100644 --- a/web/static/index.js +++ b/web/static/index.js @@ -13,8 +13,13 @@ function isOffScreen(el) { ); } -function scrollToBottom() { - window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' }); +function smoothScrollTo(loc) { + if (loc === "top") { + window.scrollTo({ top: 0, behavior: 'smooth' }); + } + else if (loc === "bottom") { + window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' }); + } } function isHttpWarningStatus(code) { diff --git a/web/views/thread.templ b/web/views/thread.templ index dce3c0a..5e52ef6 100644 --- a/web/views/thread.templ +++ b/web/views/thread.templ @@ -185,11 +185,16 @@ type ThreadContext struct { IsAdmin bool } -templ ThreadActionBar(thread database.Thread) { +templ ThreadActionBar(thread database.Thread, pos string) {
- [Catalog] - [Refresh] + if pos == "top" { + [Scroll to bottom] + } else { + [Scroll to top] + } + [Catalog] + [Refresh]

} @@ -201,15 +206,15 @@ templ Thread(board database.Board, thread database.Thread, posts []database.Post
@shared.NewPostForm(board, fmt.Sprintf("/%s/threads/%d", board.Slug, thread.Id), false)
- @ThreadActionBar(thread) + @ThreadActionBar(thread, "top")
@Posts(posts, thread, threadContext)
- @ThreadActionBar(thread) + @ThreadActionBar(thread, "bottom") } }