Implemented features for creating and deleting boards and threads, removed thread types, enhanced CSS for boards and comments

master
Joca 2025-04-15 22:15:54 -03:00
parent f7206db295
commit 55908bb215
Signed by: jocadbz
GPG Key ID: B1836DCE2F50BDF7
11 changed files with 382 additions and 75 deletions

View File

@ -54,9 +54,8 @@ func BoardHandler(app *App) http.HandlerFunc {
action := r.URL.Query().Get("action") action := r.URL.Query().Get("action")
if action == "create_thread" { if action == "create_thread" {
title := r.FormValue("title") title := r.FormValue("title")
threadType := r.FormValue("type") if title == "" {
if title == "" || (threadType != "classic" && threadType != "chat" && threadType != "question") { http.Error(w, "Thread title is required", http.StatusBadRequest)
http.Error(w, "Invalid input", http.StatusBadRequest)
return return
} }
if board.Private { if board.Private {
@ -74,7 +73,6 @@ func BoardHandler(app *App) http.HandlerFunc {
thread := models.Thread{ thread := models.Thread{
BoardID: boardID, BoardID: boardID,
Title: title, Title: title,
Type: threadType,
CreatedByUserID: userID, CreatedByUserID: userID,
} }
err = models.CreateThread(app.DB, thread) err = models.CreateThread(app.DB, thread)

View File

@ -3,16 +3,52 @@ package handlers
import ( import (
"log" "log"
"net/http" "net/http"
"github.com/gorilla/sessions" "strconv"
"threadr/models" "threadr/models"
"github.com/gorilla/sessions"
) )
func BoardsHandler(app *App) http.HandlerFunc { func BoardsHandler(app *App) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value("session").(*sessions.Session) session := r.Context().Value("session").(*sessions.Session)
loggedIn := session.Values["user_id"] != nil loggedIn := session.Values["user_id"] != nil
userID, _ := session.Values["user_id"].(int)
cookie, _ := r.Cookie("threadr_cookie_banner") cookie, _ := r.Cookie("threadr_cookie_banner")
userID, _ := session.Values["user_id"].(int)
isAdmin := false
if loggedIn {
user, err := models.GetUserByID(app.DB, userID)
if err != nil {
log.Printf("Error fetching user: %v", err)
} else if user != nil {
isAdmin = models.HasGlobalPermission(user, models.PermCreateBoard)
}
}
if r.Method == http.MethodPost && loggedIn && isAdmin {
name := r.FormValue("name")
description := r.FormValue("description")
if name == "" {
http.Error(w, "Board name is required", http.StatusBadRequest)
return
}
board := models.Board{
Name: name,
Description: description,
Private: false,
PublicVisible: true,
}
query := "INSERT INTO boards (name, description, private, public_visible) VALUES (?, ?, ?, ?)"
result, err := app.DB.Exec(query, board.Name, board.Description, board.Private, board.PublicVisible)
if err != nil {
log.Printf("Error creating board: %v", err)
http.Error(w, "Failed to create board", http.StatusInternalServerError)
return
}
boardID, _ := result.LastInsertId()
http.Redirect(w, r, app.Config.ThreadrDir+"/board/?id="+strconv.FormatInt(boardID, 10), http.StatusFound)
return
}
publicBoards, err := models.GetAllBoards(app.DB, false) publicBoards, err := models.GetAllBoards(app.DB, false)
if err != nil { if err != nil {
@ -46,6 +82,7 @@ func BoardsHandler(app *App) http.HandlerFunc {
PageData PageData
PublicBoards []models.Board PublicBoards []models.Board
PrivateBoards []models.Board PrivateBoards []models.Board
IsAdmin bool
}{ }{
PageData: PageData{ PageData: PageData{
Title: "ThreadR - Boards", Title: "ThreadR - Boards",
@ -58,6 +95,7 @@ func BoardsHandler(app *App) http.HandlerFunc {
}, },
PublicBoards: publicBoards, PublicBoards: publicBoards,
PrivateBoards: privateBoards, PrivateBoards: privateBoards,
IsAdmin: isAdmin,
} }
if err := app.Tmpl.ExecuteTemplate(w, "boards", data); err != nil { if err := app.Tmpl.ExecuteTemplate(w, "boards", data); err != nil {
log.Printf("Error executing template in BoardsHandler: %v", err) log.Printf("Error executing template in BoardsHandler: %v", err)

View File

@ -61,7 +61,7 @@ func ThreadHandler(app *App) http.HandlerFunc {
if action == "submit" { if action == "submit" {
content := r.FormValue("content") content := r.FormValue("content")
replyToStr := r.URL.Query().Get("to") replyToStr := r.URL.Query().Get("to")
replyTo := 0 replyTo := -1
if replyToStr != "" { if replyToStr != "" {
replyTo, err = strconv.Atoi(replyToStr) replyTo, err = strconv.Atoi(replyToStr)
if err != nil { if err != nil {
@ -109,12 +109,6 @@ func ThreadHandler(app *App) http.HandlerFunc {
return return
} }
if thread.Type == "chat" {
for i, j := 0, len(posts)-1; i < j; i, j = i+1, j-1 {
posts[i], posts[j] = posts[j], posts[i]
}
}
data := struct { data := struct {
PageData PageData
Thread models.Thread Thread models.Thread

View File

@ -64,13 +64,12 @@ func createTablesIfNotExist(db *sql.DB) error {
return fmt.Errorf("error creating users table: %v", err) return fmt.Errorf("error creating users table: %v", err)
} }
// Create threads table // Create threads table (without type field)
_, err = db.Exec(` _, err = db.Exec(`
CREATE TABLE IF NOT EXISTS threads ( CREATE TABLE IF NOT EXISTS threads (
id INT AUTO_INCREMENT PRIMARY KEY, id INT AUTO_INCREMENT PRIMARY KEY,
board_id INT NOT NULL, board_id INT NOT NULL,
title VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL,
type VARCHAR(50) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
created_by_user_id INT NOT NULL, created_by_user_id INT NOT NULL,

View File

@ -20,20 +20,38 @@ func GetBoardByID(db *sql.DB, id int) (*Board, error) {
query := "SELECT id, name, description, private, public_visible, pinned_threads, custom_landing_page, color_scheme FROM boards WHERE id = ?" query := "SELECT id, name, description, private, public_visible, pinned_threads, custom_landing_page, color_scheme FROM boards WHERE id = ?"
row := db.QueryRow(query, id) row := db.QueryRow(query, id)
board := &Board{} board := &Board{}
var pinnedThreadsJSON string var pinnedThreadsJSON sql.NullString
err := row.Scan(&board.ID, &board.Name, &board.Description, &board.Private, &board.PublicVisible, &pinnedThreadsJSON, &board.CustomLandingPage, &board.ColorScheme) var customLandingPage sql.NullString
var colorScheme sql.NullString
var description sql.NullString
err := row.Scan(&board.ID, &board.Name, &description, &board.Private, &board.PublicVisible, &pinnedThreadsJSON, &customLandingPage, &colorScheme)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return nil, nil return nil, nil
} }
if err != nil { if err != nil {
return nil, err return nil, err
} }
if pinnedThreadsJSON != "" { if description.Valid {
err = json.Unmarshal([]byte(pinnedThreadsJSON), &board.PinnedThreads) board.Description = description.String
} else {
board.Description = ""
}
if pinnedThreadsJSON.Valid && pinnedThreadsJSON.String != "" {
err = json.Unmarshal([]byte(pinnedThreadsJSON.String), &board.PinnedThreads)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
if customLandingPage.Valid {
board.CustomLandingPage = customLandingPage.String
} else {
board.CustomLandingPage = ""
}
if colorScheme.Valid {
board.ColorScheme = colorScheme.String
} else {
board.ColorScheme = ""
}
return board, nil return board, nil
} }
@ -48,17 +66,35 @@ func GetAllBoards(db *sql.DB, private bool) ([]Board, error) {
var boards []Board var boards []Board
for rows.Next() { for rows.Next() {
board := Board{} board := Board{}
var pinnedThreadsJSON string var pinnedThreadsJSON sql.NullString
err := rows.Scan(&board.ID, &board.Name, &board.Description, &board.Private, &board.PublicVisible, &pinnedThreadsJSON, &board.CustomLandingPage, &board.ColorScheme) var customLandingPage sql.NullString
var colorScheme sql.NullString
var description sql.NullString
err := rows.Scan(&board.ID, &board.Name, &description, &board.Private, &board.PublicVisible, &pinnedThreadsJSON, &customLandingPage, &colorScheme)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if pinnedThreadsJSON != "" { if description.Valid {
err = json.Unmarshal([]byte(pinnedThreadsJSON), &board.PinnedThreads) board.Description = description.String
} else {
board.Description = ""
}
if pinnedThreadsJSON.Valid && pinnedThreadsJSON.String != "" {
err = json.Unmarshal([]byte(pinnedThreadsJSON.String), &board.PinnedThreads)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
if customLandingPage.Valid {
board.CustomLandingPage = customLandingPage.String
} else {
board.CustomLandingPage = ""
}
if colorScheme.Valid {
board.ColorScheme = colorScheme.String
} else {
board.ColorScheme = ""
}
boards = append(boards, board) boards = append(boards, board)
} }
return boards, nil return boards, nil

View File

@ -29,10 +29,26 @@ func GetPostsByThreadID(db *sql.DB, threadID int) ([]Post, error) {
var posts []Post var posts []Post
for rows.Next() { for rows.Next() {
post := Post{} post := Post{}
err := rows.Scan(&post.ID, &post.ThreadID, &post.UserID, &post.PostTime, &post.EditTime, &post.Content, &post.AttachmentHash, &post.AttachmentName, &post.Title, &post.ReplyTo) var postTimeStr string
var editTimeStr sql.NullString
err := rows.Scan(&post.ID, &post.ThreadID, &post.UserID, &postTimeStr, &editTimeStr, &post.Content, &post.AttachmentHash, &post.AttachmentName, &post.Title, &post.ReplyTo)
if err != nil { if err != nil {
return nil, err return nil, err
} }
post.PostTime, err = time.Parse("2006-01-02 15:04:05", postTimeStr)
if err != nil {
post.PostTime = time.Time{}
}
if editTimeStr.Valid {
editTime, err := time.Parse("2006-01-02 15:04:05", editTimeStr.String)
if err != nil {
post.EditTime = nil
} else {
post.EditTime = &editTime
}
} else {
post.EditTime = nil
}
posts = append(posts, post) posts = append(posts, post)
} }
return posts, nil return posts, nil

View File

@ -9,7 +9,6 @@ type Thread struct {
ID int ID int
BoardID int BoardID int
Title string Title string
Type string // "classic", "chat", "question"
CreatedAt time.Time CreatedAt time.Time
UpdatedAt time.Time UpdatedAt time.Time
CreatedByUserID int CreatedByUserID int
@ -17,21 +16,31 @@ type Thread struct {
} }
func GetThreadByID(db *sql.DB, id int) (*Thread, error) { func GetThreadByID(db *sql.DB, id int) (*Thread, error) {
query := "SELECT id, board_id, title, type, created_at, updated_at, created_by_user_id, accepted_answer_post_id FROM threads WHERE id = ?" query := "SELECT id, board_id, title, created_at, updated_at, created_by_user_id, accepted_answer_post_id FROM threads WHERE id = ?"
row := db.QueryRow(query, id) row := db.QueryRow(query, id)
thread := &Thread{} thread := &Thread{}
err := row.Scan(&thread.ID, &thread.BoardID, &thread.Title, &thread.Type, &thread.CreatedAt, &thread.UpdatedAt, &thread.CreatedByUserID, &thread.AcceptedAnswerPostID) var createdAtStr string
var updatedAtStr string
err := row.Scan(&thread.ID, &thread.BoardID, &thread.Title, &createdAtStr, &updatedAtStr, &thread.CreatedByUserID, &thread.AcceptedAnswerPostID)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return nil, nil return nil, nil
} }
if err != nil { if err != nil {
return nil, err return nil, err
} }
thread.CreatedAt, err = time.Parse("2006-01-02 15:04:05", createdAtStr)
if err != nil {
thread.CreatedAt = time.Time{}
}
thread.UpdatedAt, err = time.Parse("2006-01-02 15:04:05", updatedAtStr)
if err != nil {
thread.UpdatedAt = time.Time{}
}
return thread, nil return thread, nil
} }
func GetThreadsByBoardID(db *sql.DB, boardID int) ([]Thread, error) { func GetThreadsByBoardID(db *sql.DB, boardID int) ([]Thread, error) {
query := "SELECT id, board_id, title, type, created_at, updated_at, created_by_user_id, accepted_answer_post_id FROM threads WHERE board_id = ? ORDER BY updated_at DESC" query := "SELECT id, board_id, title, created_at, updated_at, created_by_user_id, accepted_answer_post_id FROM threads WHERE board_id = ? ORDER BY updated_at DESC"
rows, err := db.Query(query, boardID) rows, err := db.Query(query, boardID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -41,17 +50,27 @@ func GetThreadsByBoardID(db *sql.DB, boardID int) ([]Thread, error) {
var threads []Thread var threads []Thread
for rows.Next() { for rows.Next() {
thread := Thread{} thread := Thread{}
err := rows.Scan(&thread.ID, &thread.BoardID, &thread.Title, &thread.Type, &thread.CreatedAt, &thread.UpdatedAt, &thread.CreatedByUserID, &thread.AcceptedAnswerPostID) var createdAtStr string
var updatedAtStr string
err := rows.Scan(&thread.ID, &thread.BoardID, &thread.Title, &createdAtStr, &updatedAtStr, &thread.CreatedByUserID, &thread.AcceptedAnswerPostID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
thread.CreatedAt, err = time.Parse("2006-01-02 15:04:05", createdAtStr)
if err != nil {
thread.CreatedAt = time.Time{}
}
thread.UpdatedAt, err = time.Parse("2006-01-02 15:04:05", updatedAtStr)
if err != nil {
thread.UpdatedAt = time.Time{}
}
threads = append(threads, thread) threads = append(threads, thread)
} }
return threads, nil return threads, nil
} }
func CreateThread(db *sql.DB, thread Thread) error { func CreateThread(db *sql.DB, thread Thread) error {
query := "INSERT INTO threads (board_id, title, type, created_by_user_id, created_at, updated_at) VALUES (?, ?, ?, ?, NOW(), NOW())" query := "INSERT INTO threads (board_id, title, created_by_user_id, created_at, updated_at, type) VALUES (?, ?, ?, NOW(), NOW(), 'classic')"
_, err := db.Exec(query, thread.BoardID, thread.Title, thread.Type, thread.CreatedByUserID) _, err := db.Exec(query, thread.BoardID, thread.Title, thread.CreatedByUserID)
return err return err
} }

View File

@ -1,5 +1,5 @@
body { body {
font-family: Arial, sans-serif; font-family: monospace;
margin: 0; margin: 0;
padding: 0; padding: 0;
background-color: #fef6e4; /* beige */ background-color: #fef6e4; /* beige */
@ -10,7 +10,7 @@ main {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
padding: 20px; padding: 25px;
} }
main > header { main > header {
@ -20,20 +20,33 @@ main > header {
main > section { main > section {
margin: 1em; margin: 1em;
padding: 1em; padding: 14px 20px;
border: 1px solid #001858; border: 1px solid #001858;
border-radius: 5px; border-radius: 5px;
background-color: #f3d2c1; /* orange */ background-color: #f3d2c1; /* orange */
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
width: 80%;
max-width: 800px;
}
main > div {
width: 80%;
max-width: 800px;
} }
main > div > article { main > div > article {
border: 1px solid #001858; border: 1px solid #001858;
padding: 1em; padding: 14px 20px;
margin-bottom: 1em; margin-bottom: 1em;
background-color: #fef6e4; background-color: #fef6e4;
border-radius: 5px; border-radius: 5px;
box-shadow: inset 0px 8px 16px 0px rgba(0,0,0,0.2); box-shadow: inset 0px 8px 16px 0px rgba(0,0,0,0.2);
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
main > div > article:hover {
transform: translateY(-2px);
box-shadow: 0px 4px 12px 0px rgba(0,0,0,0.15);
} }
article > header { article > header {
@ -41,7 +54,9 @@ article > header {
background-color: #001858; background-color: #001858;
color: #fef6e4; color: #fef6e4;
padding: 0.5em; padding: 0.5em;
margin: -1em -1em 1em -1em; margin: -14px -20px 1em -20px;
border-radius: 5px 5px 0 0;
box-shadow: 0px 4px 8px 0px rgba(0,0,0,0.2);
} }
ul.topnav { ul.topnav {
@ -52,6 +67,7 @@ ul.topnav {
background-color: #001858; background-color: #001858;
position: fixed; position: fixed;
top: 0; top: 0;
left: 0;
width: 100%; width: 100%;
box-shadow: 0 0.7em 1.2em 0 rgba(0,0,0,0.2); box-shadow: 0 0.7em 1.2em 0 rgba(0,0,0,0.2);
} }
@ -64,11 +80,13 @@ ul.topnav li a {
display: block; display: block;
color: #fef6e4; color: #fef6e4;
text-align: center; text-align: center;
padding: 14px 16px; padding: 1.2em 1.3em;
text-decoration: none; text-decoration: none;
font-family: monospace;
font-size: 1em;
} }
ul.topnav li a:hover { ul.topnav li a:hover:not(.active) {
background-color: #8bd3dd; /* cyan */ background-color: #8bd3dd; /* cyan */
} }
@ -83,6 +101,7 @@ div.topnav {
div.banner { div.banner {
position: fixed; position: fixed;
bottom: 0; bottom: 0;
left: 0;
width: 100%; width: 100%;
background-color: #001858; background-color: #001858;
padding: 10px; padding: 10px;
@ -104,17 +123,21 @@ form {
} }
input, textarea, select { input, textarea, select {
margin: 0.5em 0; margin: 8px 0;
padding: 0.5em; padding: 14px 20px;
border: 1px solid #001858; border: 1px solid #001858;
border-radius: 4px; border-radius: 4px;
background-color: #fef6e4; background-color: #fef6e4;
color: #001858; color: #001858;
font-family: monospace;
box-sizing: border-box;
box-shadow: inset 0px 8px 16px 0px rgba(0,0,0,0.2);
} }
input[type="submit"] { input[type="submit"] {
background-color: #001858; background-color: #001858;
color: #fef6e4; color: #fef6e4;
border: none;
cursor: pointer; cursor: pointer;
} }
@ -123,13 +146,15 @@ input[type="submit"]:hover {
} }
button { button {
margin: 0.5em 0; margin: 8px 0;
padding: 0.5em; padding: 14px 20px;
border: none; border: none;
border-radius: 4px; border-radius: 4px;
background-color: #001858; background-color: #001858;
color: #fef6e4; color: #fef6e4;
cursor: pointer; cursor: pointer;
font-family: monospace;
width: 100%;
} }
button:hover { button:hover {
@ -138,6 +163,125 @@ button:hover {
img { img {
max-width: 100%; max-width: 100%;
object-fit: contain;
}
h1, h2, h3, h4, h5, h6 {
font-family: monospace;
color: #001858;
}
p, a, li {
font-family: monospace;
color: #001858;
}
/* Enhanced styles for boards */
ul.board-list {
list-style-type: none;
padding: 0;
margin: 0;
}
li.board-item {
margin-bottom: 1em;
padding: 1em;
background-color: #fef6e4;
border: 1px solid #001858;
border-radius: 8px;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
li.board-item:hover {
transform: translateY(-3px);
box-shadow: 0px 6px 14px 0px rgba(0,0,0,0.15);
}
li.board-item a {
color: #001858;
font-weight: bold;
text-decoration: none;
font-size: 1.2em;
}
li.board-item a:hover {
color: #f582ae;
text-decoration: underline;
}
p.board-desc {
margin: 0.5em 0 0 0;
color: #001858;
font-size: 0.9em;
}
/* Enhanced styles for thread posts */
.thread-posts {
width: 80%;
max-width: 800px;
}
.post-item {
background-color: #fef6e4;
border: 1px solid #001858;
border-radius: 8px;
margin-bottom: 1.5em;
padding: 1em;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.post-item:hover {
transform: translateY(-3px);
box-shadow: 0px 6px 14px 0px rgba(0,0,0,0.15);
}
.post-item header {
background-color: #001858;
color: #fef6e4;
padding: 0.5em;
margin: -1em -1em 1em -1em;
border-radius: 6px 6px 0 0;
border-bottom: 1px solid #001858;
}
.post-item header h3 {
margin: 0;
font-size: 1.1em;
}
.post-item header p {
margin: 0.3em 0 0 0;
font-size: 0.85em;
opacity: 0.9;
}
.post-content {
margin: 0;
padding: 0.5em;
line-height: 1.5;
font-size: 0.95em;
}
.post-actions {
margin-top: 0.8em;
display: flex;
gap: 0.5em;
align-items: center;
}
.post-actions a {
color: #001858;
text-decoration: none;
font-size: 0.9em;
padding: 0.3em 0.6em;
border: 1px solid #001858;
border-radius: 4px;
transition: background-color 0.2s ease;
}
.post-actions a:hover {
background-color: #8bd3dd;
color: #fef6e4;
} }
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
@ -169,6 +313,40 @@ img {
input[type="submit"]:hover, button:hover { input[type="submit"]:hover, button:hover {
background-color: #8bd3dd; background-color: #8bd3dd;
} }
li.board-item {
background-color: #444;
border-color: #fef6e4;
}
li.board-item a {
color: #fef6e4;
}
li.board-item a:hover {
color: #f582ae;
}
p.board-desc {
color: #fef6e4;
}
.post-item {
background-color: #444;
border-color: #fef6e4;
}
.post-content {
color: #fef6e4;
}
.post-actions a {
color: #fef6e4;
border-color: #fef6e4;
}
.post-actions a:hover {
background-color: #8bd3dd;
color: #001858;
}
h1, h2, h3, h4, h5, h6 {
color: #fef6e4;
}
p, a, li {
color: #fef6e4;
}
} }
@media (max-width: 600px) { @media (max-width: 600px) {
@ -182,5 +360,12 @@ img {
main > section { main > section {
margin: 0.5em; margin: 0.5em;
padding: 0.5em; padding: 0.5em;
width: 95%;
}
main > div {
width: 95%;
}
.thread-posts {
width: 95%;
} }
} }

View File

@ -13,11 +13,16 @@
<p>{{.Board.Description}}</p> <p>{{.Board.Description}}</p>
</header> </header>
<section> <section>
<h3>Threads</h3>
{{if .Threads}}
<ul> <ul>
{{range .Threads}} {{range .Threads}}
<li><a href="{{$.BasePath}}/thread/?id={{.ID}}">{{.Title}}</a> ({{.Type}})</li> <li><a href="{{$.BasePath}}/thread/?id={{.ID}}">{{.Title}}</a> - Updated on {{.UpdatedAt.Format "02/01/2006 - 15:04"}}</li>
{{end}} {{end}}
</ul> </ul>
{{else}}
<p>No threads available in this board yet.</p>
{{end}}
</section> </section>
{{if .LoggedIn}} {{if .LoggedIn}}
<section> <section>
@ -25,12 +30,6 @@
<form method="post" action="{{.BasePath}}/board/?id={{.Board.ID}}&action=create_thread"> <form method="post" action="{{.BasePath}}/board/?id={{.Board.ID}}&action=create_thread">
<label for="title">Thread Title:</label> <label for="title">Thread Title:</label>
<input type="text" id="title" name="title" required><br> <input type="text" id="title" name="title" required><br>
<label for="type">Thread Type:</label>
<select id="type" name="type">
<option value="classic">Classic</option>
<option value="chat">Chat</option>
<option value="question">Question</option>
</select><br>
<input type="submit" value="Create Thread"> <input type="submit" value="Create Thread">
</form> </form>
</section> </section>

View File

@ -13,20 +13,46 @@
</header> </header>
<section> <section>
<h3>Public Boards</h3> <h3>Public Boards</h3>
<ul> {{if .PublicBoards}}
<ul class="board-list">
{{range .PublicBoards}} {{range .PublicBoards}}
<li><a href="{{$.BasePath}}/board/?id={{.ID}}">{{.Name}}</a></li> <li class="board-item">
<a href="{{$.BasePath}}/board/?id={{.ID}}">{{.Name}}</a>
<p class="board-desc">{{.Description}}</p>
</li>
{{end}} {{end}}
</ul> </ul>
{{else}}
<p>No public boards available at the moment.</p>
{{end}}
</section> </section>
{{if .LoggedIn}} {{if .LoggedIn}}
<section> <section>
<h3>Private Boards</h3> <h3>Private Boards</h3>
<ul> {{if .PrivateBoards}}
<ul class="board-list">
{{range .PrivateBoards}} {{range .PrivateBoards}}
<li><a href="{{$.BasePath}}/board/?id={{.ID}}">{{.Name}}</a></li> <li class="board-item">
<a href="{{$.BasePath}}/board/?id={{.ID}}">{{.Name}}</a>
<p class="board-desc">{{.Description}}</p>
</li>
{{end}} {{end}}
</ul> </ul>
{{else}}
<p>No private boards available to you at the moment.</p>
{{end}}
</section>
{{end}}
{{if .IsAdmin}}
<section>
<h3>Create New Public Board</h3>
<form method="post" action="{{.BasePath}}/boards/">
<label for="name">Board Name:</label>
<input type="text" id="name" name="name" required><br>
<label for="description">Description:</label>
<textarea id="description" name="description"></textarea><br>
<input type="submit" value="Create Board">
</form>
</section> </section>
{{end}} {{end}}
</main> </main>

View File

@ -10,35 +10,32 @@
<main> <main>
<header> <header>
<h2>{{.Thread.Title}}</h2> <h2>{{.Thread.Title}}</h2>
{{if eq .Thread.Type "question"}}
{{if .Thread.AcceptedAnswerPostID}}
<p>Accepted Answer: <a href="#{{.Thread.AcceptedAnswerPostID}}">Post {{.Thread.AcceptedAnswerPostID}}</a></p>
{{end}}
{{end}}
</header> </header>
<div> <div class="thread-posts">
{{range .Posts}} {{range .Posts}}
<article id="{{.ID}}"> <article id="{{.ID}}" class="post-item" style="margin-left: {{if gt .ReplyTo 0}}20px{{else}}0px{{end}};">
<header> <header>
<h3>{{.Title}}</h3> <h3>{{if .Title}}{{.Title}}{{else}}Post #{{.ID}}{{end}}</h3>
<p>Posted by User {{.UserID}} on {{.PostTime}}</p> <p>Posted on {{.PostTime.Format "02/01/2006 - 15:04"}}</p>
{{if gt .ReplyTo 0}} {{if gt .ReplyTo 0}}
<p>Reply to post {{.ReplyTo}}</p> <p>Reply to post <a href="#{{.ReplyTo}}">{{.ReplyTo}}</a></p>
{{end}} {{end}}
</header> </header>
<p>{{.Content}}</p> <div class="post-content">{{.Content}}</div>
{{if $.LoggedIn}} {{if $.LoggedIn}}
<form method="post" action="{{$.BasePath}}/like/" style="display:inline;"> <div class="post-actions">
<input type="hidden" name="post_id" value="{{.ID}}"> <form method="post" action="{{$.BasePath}}/like/" style="display:inline;">
<input type="hidden" name="type" value="like"> <input type="hidden" name="post_id" value="{{.ID}}">
<button type="submit">Like</button> <input type="hidden" name="type" value="like">
</form> <button type="submit">Like</button>
<form method="post" action="{{$.BasePath}}/like/" style="display:inline;"> </form>
<input type="hidden" name="post_id" value="{{.ID}}"> <form method="post" action="{{$.BasePath}}/like/" style="display:inline;">
<input type="hidden" name="type" value="dislike"> <input type="hidden" name="post_id" value="{{.ID}}">
<button type="submit">Dislike</button> <input type="hidden" name="type" value="dislike">
</form> <button type="submit">Dislike</button>
<a href="{{$.BasePath}}/thread/?id={{$.Thread.ID}}&action=submit&to={{.ID}}">Reply</a> </form>
<a href="{{$.BasePath}}/thread/?id={{$.Thread.ID}}&action=submit&to={{.ID}}">Reply</a>
</div>
{{end}} {{end}}
</article> </article>
{{end}} {{end}}