Finished :)
This commit is contained in:
+80
@@ -0,0 +1,80 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"sprintpadawan/lib"
|
||||
)
|
||||
|
||||
func handleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
if isLoggedIn(r) {
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
renderTemplate(w, "login.html", nil)
|
||||
return
|
||||
}
|
||||
|
||||
username := r.FormValue("username")
|
||||
password := r.FormValue("password")
|
||||
|
||||
user, err := lib.GetUserByUsername(username)
|
||||
if err != nil || !lib.CheckPasswordHash(password, user.PasswordHash) {
|
||||
renderTemplate(w, "login.html", map[string]string{"Error": "Invalid credentials"})
|
||||
return
|
||||
}
|
||||
|
||||
sessionID, _ := lib.CreateSession(user.ID)
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: "session_token",
|
||||
Value: sessionID,
|
||||
Expires: time.Now().Add(24 * time.Hour),
|
||||
HttpOnly: true,
|
||||
Path: "/",
|
||||
})
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleRegister(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
if isLoggedIn(r) {
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
renderTemplate(w, "register.html", nil)
|
||||
return
|
||||
}
|
||||
|
||||
username := r.FormValue("username")
|
||||
password := r.FormValue("password")
|
||||
confirm := r.FormValue("confirm_password")
|
||||
|
||||
if password != confirm {
|
||||
renderTemplate(w, "register.html", map[string]string{"Error": "Passwords do not match"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := lib.CreateUser(username, password); err != nil {
|
||||
renderTemplate(w, "register.html", map[string]string{"Error": "Username taken"})
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleLogout(w http.ResponseWriter, r *http.Request) {
|
||||
cookie, err := r.Cookie("session_token")
|
||||
if err == nil {
|
||||
lib.DeleteSession(cookie.Value)
|
||||
}
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: "session_token",
|
||||
Value: "",
|
||||
Expires: time.Now().Add(-1 * time.Hour),
|
||||
Path: "/",
|
||||
})
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"sprintpadawan/lib"
|
||||
)
|
||||
|
||||
type RoomView struct {
|
||||
ID int
|
||||
Name string
|
||||
Code string
|
||||
Scale string
|
||||
IsOwner bool
|
||||
MemberCount int
|
||||
}
|
||||
|
||||
func handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
rooms, _ := lib.GetRoomsForUser(user.ID)
|
||||
data := struct {
|
||||
*lib.User
|
||||
Rooms []RoomView
|
||||
}{
|
||||
User: user,
|
||||
}
|
||||
|
||||
for _, room := range rooms {
|
||||
members, _ := lib.GetRoomMembers(room.ID)
|
||||
data.Rooms = append(data.Rooms, RoomView{
|
||||
ID: room.ID,
|
||||
Name: room.Name,
|
||||
Code: room.Code,
|
||||
Scale: room.Scale,
|
||||
IsOwner: room.OwnerID == user.ID,
|
||||
MemberCount: len(members),
|
||||
})
|
||||
}
|
||||
|
||||
if err := templates.ExecuteTemplate(w, "index.html", data); err != nil {
|
||||
log.Printf("template error: %v", err)
|
||||
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
-723
@@ -1,723 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"sprintpadawan/lib"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
const userKey contextKey = "user"
|
||||
|
||||
type sseClient struct {
|
||||
ch chan string
|
||||
userID int
|
||||
}
|
||||
|
||||
var (
|
||||
roomClients = make(map[int][]*sseClient)
|
||||
clientsMu sync.Mutex
|
||||
)
|
||||
|
||||
var templates *template.Template
|
||||
|
||||
// ==================== HELPERS ====================
|
||||
|
||||
func addSSEClient(roomID, userID int, ch chan string) {
|
||||
clientsMu.Lock()
|
||||
defer clientsMu.Unlock()
|
||||
roomClients[roomID] = append(roomClients[roomID], &sseClient{ch: ch, userID: userID})
|
||||
}
|
||||
|
||||
func removeSSEClient(roomID int, ch chan string) {
|
||||
clientsMu.Lock()
|
||||
defer clientsMu.Unlock()
|
||||
clients := roomClients[roomID]
|
||||
for i, c := range clients {
|
||||
if c.ch == ch {
|
||||
roomClients[roomID] = append(clients[:i], clients[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(roomClients[roomID]) == 0 {
|
||||
delete(roomClients, roomID)
|
||||
}
|
||||
}
|
||||
|
||||
func broadcast(roomID int, event string) {
|
||||
clientsMu.Lock()
|
||||
defer clientsMu.Unlock()
|
||||
alive := roomClients[roomID][:0]
|
||||
for _, c := range roomClients[roomID] {
|
||||
select {
|
||||
case c.ch <- event:
|
||||
alive = append(alive, c)
|
||||
default:
|
||||
// drop dead client
|
||||
}
|
||||
}
|
||||
roomClients[roomID] = alive
|
||||
}
|
||||
|
||||
func GetConnectedUserIDs(roomID int) []int {
|
||||
clientsMu.Lock()
|
||||
defer clientsMu.Unlock()
|
||||
seen := make(map[int]bool)
|
||||
var ids []int
|
||||
for _, c := range roomClients[roomID] {
|
||||
if !seen[c.userID] {
|
||||
seen[c.userID] = true
|
||||
ids = append(ids, c.userID)
|
||||
}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
func scaleToOptions(scale string) []string {
|
||||
switch scale {
|
||||
case "fibonacci":
|
||||
return []string{"1", "2", "3", "5", "8", "13", "21", "?"}
|
||||
case "tshirt":
|
||||
return []string{"XS", "S", "M", "L", "XL", "XXL", "?"}
|
||||
case "linear":
|
||||
return []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "?"}
|
||||
default:
|
||||
return []string{"1", "2", "3", "5", "8", "13", "21", "?"}
|
||||
}
|
||||
}
|
||||
|
||||
func getRoomID(r *http.Request) int {
|
||||
return getPathInt(r, "id")
|
||||
}
|
||||
|
||||
func getPathInt(r *http.Request, key string) int {
|
||||
var id int
|
||||
fmt.Sscanf(r.PathValue(key), "%d", &id)
|
||||
return id
|
||||
}
|
||||
|
||||
type MemberView struct {
|
||||
Username string
|
||||
HasVoted bool
|
||||
ID int
|
||||
}
|
||||
|
||||
type RoomData struct {
|
||||
*lib.Room
|
||||
User *lib.User
|
||||
Members []MemberView
|
||||
Stories []lib.Story
|
||||
IsOwner bool
|
||||
UserVotes map[int]string
|
||||
StoryVotes map[int][]lib.VoteView
|
||||
}
|
||||
|
||||
// Builds data used by both full page and all partials
|
||||
func buildRoomData(room *lib.Room, user *lib.User) RoomData {
|
||||
members, _ := lib.GetRoomMembers(room.ID)
|
||||
stories, _ := lib.GetStoriesForRoom(room.ID)
|
||||
connectedIDs := GetConnectedUserIDs(room.ID)
|
||||
connectedMap := make(map[int]bool)
|
||||
for _, cid := range connectedIDs {
|
||||
connectedMap[cid] = true
|
||||
}
|
||||
connectedMap[user.ID] = true
|
||||
|
||||
var activeVotes []lib.Vote
|
||||
if room.ActiveStoryID != nil {
|
||||
activeVotes, _ = lib.GetVotesForStory(*room.ActiveStoryID)
|
||||
}
|
||||
|
||||
var memberViews []MemberView
|
||||
for _, m := range members {
|
||||
if !connectedMap[m.ID] {
|
||||
continue
|
||||
}
|
||||
hasVoted := false
|
||||
for _, v := range activeVotes {
|
||||
if v.UserID == m.ID {
|
||||
hasVoted = true
|
||||
break
|
||||
}
|
||||
}
|
||||
memberViews = append(memberViews, MemberView{
|
||||
Username: m.Username,
|
||||
HasVoted: hasVoted,
|
||||
ID: m.ID,
|
||||
})
|
||||
}
|
||||
|
||||
userVotes := make(map[int]string)
|
||||
storyVotes := make(map[int][]lib.VoteView)
|
||||
for _, s := range stories {
|
||||
votes, _ := lib.GetVotesForStory(s.ID)
|
||||
for _, v := range votes {
|
||||
if v.UserID == user.ID {
|
||||
userVotes[s.ID] = v.Value
|
||||
}
|
||||
}
|
||||
if s.Voted {
|
||||
vv, _ := lib.GetVotesWithUsernames(s.ID)
|
||||
storyVotes[s.ID] = vv
|
||||
}
|
||||
}
|
||||
|
||||
return RoomData{
|
||||
Room: room,
|
||||
User: user,
|
||||
Members: memberViews,
|
||||
Stories: stories,
|
||||
IsOwner: room.OwnerID == user.ID,
|
||||
UserVotes: userVotes,
|
||||
StoryVotes: storyVotes,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
templates = template.Must(template.New("").Funcs(template.FuncMap{
|
||||
"scaleToOptions": scaleToOptions,
|
||||
"derefInt": func(i *int) int {
|
||||
if i == nil {
|
||||
return 0
|
||||
}
|
||||
return *i
|
||||
},
|
||||
"slice": func(s string, start, end int) string {
|
||||
if len(s) == 0 {
|
||||
return ""
|
||||
}
|
||||
if start < 0 {
|
||||
start = 0
|
||||
}
|
||||
if end > len(s) || end <= 0 {
|
||||
end = len(s)
|
||||
}
|
||||
if start > end {
|
||||
return ""
|
||||
}
|
||||
return s[start:end]
|
||||
},
|
||||
"dict": func(values ...interface{}) (map[string]interface{}, error) {
|
||||
if len(values)%2 != 0 {
|
||||
return nil, fmt.Errorf("odd number of arguments to dict")
|
||||
}
|
||||
d := make(map[string]interface{})
|
||||
for i := 0; i < len(values); i += 2 {
|
||||
key, ok := values[i].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("dict keys must be strings")
|
||||
}
|
||||
d[key] = values[i+1]
|
||||
}
|
||||
return d, nil
|
||||
},
|
||||
}).ParseGlob(filepath.Join("templates", "*.html")))
|
||||
}
|
||||
|
||||
func SetupRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("/login", handleLogin)
|
||||
mux.HandleFunc("/register", handleRegister)
|
||||
mux.HandleFunc("/logout", handleLogout)
|
||||
|
||||
mux.HandleFunc("/", requireAuth(handleIndex))
|
||||
mux.HandleFunc("/rooms/new", requireAuth(handleNewRoom))
|
||||
mux.HandleFunc("/rooms/create", requireAuth(handleCreateRoom))
|
||||
mux.HandleFunc("/rooms/join", requireAuth(handleJoinRoom))
|
||||
mux.HandleFunc("/rooms/{id}", requireAuth(handleRoom))
|
||||
|
||||
// HTMX partials
|
||||
mux.HandleFunc("/rooms/{id}/partial/stories", requireAuth(handlePartialStories))
|
||||
mux.HandleFunc("/rooms/{id}/partial/members", requireAuth(handlePartialMembers))
|
||||
mux.HandleFunc("/rooms/{id}/partial/vote-area", requireAuth(handlePartialVoteArea))
|
||||
|
||||
// Actions
|
||||
mux.HandleFunc("/rooms/{id}/stories/new", requireAuth(handleNewStoryForm))
|
||||
mux.HandleFunc("/rooms/{id}/stories", requireAuth(handleAddStory))
|
||||
mux.HandleFunc("/rooms/{id}/active", requireAuth(handleSetActiveStory))
|
||||
mux.HandleFunc("/rooms/{id}/vote", requireAuth(handleVote))
|
||||
mux.HandleFunc("/rooms/{id}/reveal", requireAuth(handleReveal))
|
||||
mux.HandleFunc("/rooms/{id}/stories/{story_id}/edit", requireAuth(handleEditStoryForm))
|
||||
mux.HandleFunc("/rooms/{id}/stories/{story_id}/rename", requireAuth(handleRenameStory))
|
||||
mux.HandleFunc("/rooms/{id}/stories/{story_id}/delete", requireAuth(handleDeleteStory))
|
||||
mux.HandleFunc("/rooms/{id}/stories/{story_id}/unreveal", requireAuth(handleUnrevealStory))
|
||||
mux.HandleFunc("/sse/{room_id}", requireAuth(handleSSE))
|
||||
}
|
||||
|
||||
func isHTMX(r *http.Request) bool {
|
||||
return r.Header.Get("HX-Request") == "true"
|
||||
}
|
||||
|
||||
func renderTemplate(w http.ResponseWriter, name string, data interface{}) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := templates.ExecuteTemplate(w, name, data); err != nil {
|
||||
log.Printf("template error (%s): %v", name, err)
|
||||
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func renderRoomStories(w http.ResponseWriter, roomID int, user *lib.User) {
|
||||
room, err := lib.GetRoomByID(roomID)
|
||||
if err != nil {
|
||||
http.Error(w, "room not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
renderTemplate(w, "stories-panel", buildRoomData(room, user))
|
||||
}
|
||||
|
||||
func renderRoomMembers(w http.ResponseWriter, roomID int, user *lib.User) {
|
||||
room, err := lib.GetRoomByID(roomID)
|
||||
if err != nil {
|
||||
http.Error(w, "room not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
renderTemplate(w, "members-panel", buildRoomData(room, user))
|
||||
}
|
||||
|
||||
func requireAuth(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
cookie, err := r.Cookie("session_token")
|
||||
if err != nil {
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
user, err := lib.GetUserFromSession(cookie.Value)
|
||||
if err != nil || user == nil {
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
ctx := context.WithValue(r.Context(), userKey, user)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
}
|
||||
}
|
||||
|
||||
func isLoggedIn(r *http.Request) bool {
|
||||
cookie, err := r.Cookie("session_token")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
user, err := lib.GetUserFromSession(cookie.Value)
|
||||
return err == nil && user != nil
|
||||
}
|
||||
|
||||
// ==================== AUTH HANDLERS ====================
|
||||
|
||||
func handleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
if isLoggedIn(r) {
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
templates.ExecuteTemplate(w, "login.html", nil)
|
||||
return
|
||||
}
|
||||
|
||||
username := r.FormValue("username")
|
||||
password := r.FormValue("password")
|
||||
|
||||
user, err := lib.GetUserByUsername(username)
|
||||
if err != nil || !lib.CheckPasswordHash(password, user.PasswordHash) {
|
||||
templates.ExecuteTemplate(w, "login.html", map[string]string{"Error": "Invalid credentials"})
|
||||
return
|
||||
}
|
||||
|
||||
sessionID, _ := lib.CreateSession(user.ID)
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: "session_token",
|
||||
Value: sessionID,
|
||||
Expires: time.Now().Add(24 * time.Hour),
|
||||
HttpOnly: true,
|
||||
Path: "/",
|
||||
})
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleRegister(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
if isLoggedIn(r) {
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
templates.ExecuteTemplate(w, "register.html", nil)
|
||||
return
|
||||
}
|
||||
|
||||
username := r.FormValue("username")
|
||||
password := r.FormValue("password")
|
||||
confirm := r.FormValue("confirm_password")
|
||||
|
||||
if password != confirm {
|
||||
templates.ExecuteTemplate(w, "register.html", map[string]string{"Error": "Passwords do not match"})
|
||||
return
|
||||
}
|
||||
|
||||
err := lib.CreateUser(username, password)
|
||||
if err != nil {
|
||||
templates.ExecuteTemplate(w, "register.html", map[string]string{"Error": "Username taken"})
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleLogout(w http.ResponseWriter, r *http.Request) {
|
||||
cookie, err := r.Cookie("session_token")
|
||||
if err == nil {
|
||||
lib.DeleteSession(cookie.Value)
|
||||
}
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: "session_token",
|
||||
Value: "",
|
||||
Expires: time.Now().Add(-1 * time.Hour),
|
||||
Path: "/",
|
||||
})
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// ==================== DASHBOARD ====================
|
||||
|
||||
func handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
rooms, _ := lib.GetRoomsForUser(user.ID)
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
|
||||
type RoomView struct {
|
||||
ID int
|
||||
Name string
|
||||
Code string
|
||||
Scale string
|
||||
IsOwner bool
|
||||
MemberCount int
|
||||
}
|
||||
|
||||
data := struct {
|
||||
*lib.User
|
||||
Rooms []RoomView
|
||||
}{
|
||||
User: user,
|
||||
}
|
||||
|
||||
for _, room := range rooms {
|
||||
members, _ := lib.GetRoomMembers(room.ID)
|
||||
data.Rooms = append(data.Rooms, RoomView{
|
||||
ID: room.ID,
|
||||
Name: room.Name,
|
||||
Code: room.Code,
|
||||
Scale: room.Scale,
|
||||
IsOwner: room.OwnerID == user.ID,
|
||||
MemberCount: len(members),
|
||||
})
|
||||
}
|
||||
|
||||
if err := templates.ExecuteTemplate(w, "index.html", data); err != nil {
|
||||
log.Printf("template error: %v", err)
|
||||
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== ROOM CREATION / JOIN ====================
|
||||
|
||||
func handleNewRoom(w http.ResponseWriter, r *http.Request) {
|
||||
if err := templates.ExecuteTemplate(w, "room_form.html", nil); err != nil {
|
||||
log.Printf("template error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleCreateRoom(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
name := r.FormValue("name")
|
||||
scale := r.FormValue("scale")
|
||||
room, err := lib.CreateRoom(name, user.ID, scale)
|
||||
if err != nil {
|
||||
log.Printf("create room error: %v", err)
|
||||
http.Error(w, "failed to create room", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", room.ID), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleJoinRoom(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
code := r.FormValue("code")
|
||||
room, err := lib.GetRoomByCode(code)
|
||||
if err != nil {
|
||||
http.Error(w, "room not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
lib.AddUserToRoom(room.ID, user.ID)
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", room.ID), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// ==================== MAIN ROOM & PARTIALS ====================
|
||||
|
||||
func handleRoom(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
room, err := lib.GetRoomByID(roomID)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
lib.AddUserToRoom(room.ID, user.ID)
|
||||
|
||||
data := buildRoomData(room, user)
|
||||
renderTemplate(w, "room.html", data)
|
||||
}
|
||||
|
||||
func handlePartialStories(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
renderRoomStories(w, roomID, user)
|
||||
}
|
||||
|
||||
func handlePartialMembers(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
renderRoomMembers(w, roomID, user)
|
||||
}
|
||||
|
||||
func handlePartialVoteArea(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
room, err := lib.GetRoomByID(roomID)
|
||||
if err != nil {
|
||||
http.Error(w, "room not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if room.ActiveStoryID == nil {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
story, err := lib.GetStoryByID(*room.ActiveStoryID)
|
||||
if err != nil {
|
||||
http.Error(w, "story not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
data := struct {
|
||||
RoomData RoomData
|
||||
Story lib.Story
|
||||
}{
|
||||
RoomData: buildRoomData(room, user),
|
||||
Story: *story,
|
||||
}
|
||||
renderTemplate(w, "vote-area", data)
|
||||
}
|
||||
|
||||
// ==================== STORY & VOTING ACTIONS ====================
|
||||
|
||||
func handleNewStoryForm(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
room, _ := lib.GetRoomByID(roomID)
|
||||
renderTemplate(w, "story_form.html", room)
|
||||
}
|
||||
|
||||
func handleAddStory(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
title := r.FormValue("title")
|
||||
_, err := lib.CreateStory(id, title)
|
||||
if err != nil {
|
||||
log.Printf("create story error: %v", err)
|
||||
http.Error(w, "failed to create story", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
broadcast(id, "stories")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleSetActiveStory(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
var sid int
|
||||
fmt.Sscanf(r.FormValue("story_id"), "%d", &sid)
|
||||
|
||||
room, _ := lib.GetRoomByID(id)
|
||||
if room.ActiveStoryID != nil {
|
||||
lib.UnrevealStory(*room.ActiveStoryID)
|
||||
lib.ClearVotesForStory(*room.ActiveStoryID)
|
||||
}
|
||||
lib.UnrevealStory(sid)
|
||||
lib.ClearVotesForStory(sid)
|
||||
lib.SetActiveStory(id, sid)
|
||||
|
||||
broadcast(id, "stories")
|
||||
broadcast(id, "members")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleVote(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
value := r.FormValue("value")
|
||||
var sid int
|
||||
fmt.Sscanf(r.FormValue("story_id"), "%d", &sid)
|
||||
|
||||
lib.VoteOnStory(sid, user.ID, value)
|
||||
broadcast(id, "members")
|
||||
if story, err := lib.GetStoryByID(sid); err == nil && story.Voted {
|
||||
broadcast(id, "stories")
|
||||
}
|
||||
|
||||
if r.Header.Get("HX-Request") == "true" {
|
||||
room, _ := lib.GetRoomByID(id)
|
||||
story, _ := lib.GetStoryByID(sid)
|
||||
tmplData := struct {
|
||||
RoomID int
|
||||
Story lib.Story
|
||||
Scale string
|
||||
UserVote string
|
||||
}{
|
||||
RoomID: id,
|
||||
Story: *story,
|
||||
Scale: room.Scale,
|
||||
UserVote: value,
|
||||
}
|
||||
renderTemplate(w, "vote_form.html", tmplData)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleReveal(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
var sid int
|
||||
fmt.Sscanf(r.FormValue("story_id"), "%d", &sid)
|
||||
lib.RevealVotes(sid)
|
||||
broadcast(id, "stories")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleUnrevealStory(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
var sid int
|
||||
fmt.Sscanf(r.PathValue("story_id"), "%d", &sid)
|
||||
lib.UnrevealStory(sid)
|
||||
broadcast(id, "stories")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleEditStoryForm(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
var storyID int
|
||||
fmt.Sscanf(r.PathValue("story_id"), "%d", &storyID)
|
||||
story, _ := lib.GetStoryByID(storyID)
|
||||
data := struct {
|
||||
RoomID int
|
||||
Story lib.Story
|
||||
}{
|
||||
RoomID: roomID,
|
||||
Story: *story,
|
||||
}
|
||||
renderTemplate(w, "story_edit.html", data)
|
||||
}
|
||||
|
||||
func handleRenameStory(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
var sid int
|
||||
fmt.Sscanf(r.PathValue("story_id"), "%d", &sid)
|
||||
title := r.FormValue("title")
|
||||
lib.RenameStory(sid, title)
|
||||
broadcast(id, "stories")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleDeleteStory(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
var sid int
|
||||
fmt.Sscanf(r.PathValue("story_id"), "%d", &sid)
|
||||
lib.DeleteStory(sid)
|
||||
broadcast(id, "stories")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// ==================== SSE ====================
|
||||
|
||||
func handleSSE(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getPathInt(r, "room_id")
|
||||
user, ok := r.Context().Value(userKey).(*lib.User)
|
||||
if !ok {
|
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
ch := make(chan string, 10)
|
||||
addSSEClient(roomID, user.ID, ch)
|
||||
broadcast(roomID, "members") // notify others of new connection
|
||||
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
w.Header().Set("Connection", "keep-alive")
|
||||
w.Header().Set("X-Accel-Buffering", "no")
|
||||
|
||||
flusher, ok := w.(http.Flusher)
|
||||
if !ok {
|
||||
http.Error(w, "streaming unsupported", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
notify := r.Context().Done()
|
||||
heartbeat := time.NewTicker(25 * time.Second)
|
||||
defer heartbeat.Stop()
|
||||
|
||||
fmt.Fprint(w, ": connected\n\n")
|
||||
flusher.Flush()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-notify:
|
||||
removeSSEClient(roomID, ch)
|
||||
broadcast(roomID, "members")
|
||||
return
|
||||
case <-heartbeat.C:
|
||||
fmt.Fprint(w, ": keep-alive\n\n")
|
||||
flusher.Flush()
|
||||
case event := <-ch:
|
||||
fmt.Fprintf(w, "event: %s\ndata: true\n\n", event)
|
||||
flusher.Flush()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"sprintpadawan/lib"
|
||||
)
|
||||
|
||||
func handleNewRoom(w http.ResponseWriter, r *http.Request) {
|
||||
if err := templates.ExecuteTemplate(w, "room_form.html", nil); err != nil {
|
||||
log.Printf("template error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleCreateRoom(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
name := r.FormValue("name")
|
||||
scale := r.FormValue("scale")
|
||||
room, err := lib.CreateRoom(name, user.ID, scale)
|
||||
if err != nil {
|
||||
log.Printf("create room error: %v", err)
|
||||
http.Error(w, "failed to create room", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", room.ID), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleJoinRoom(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
code := r.FormValue("code")
|
||||
room, err := lib.GetRoomByCode(code)
|
||||
if err != nil {
|
||||
http.Error(w, "room not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
lib.AddUserToRoom(room.ID, user.ID)
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", room.ID), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleRoom(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
room, err := lib.GetRoomByID(roomID)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
lib.AddUserToRoom(room.ID, user.ID)
|
||||
|
||||
renderTemplate(w, "room.html", buildRoomData(room, user))
|
||||
}
|
||||
|
||||
func handlePartialStories(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
renderRoomStories(w, roomID, user)
|
||||
}
|
||||
|
||||
func handlePartialMembers(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
renderRoomMembers(w, roomID, user)
|
||||
}
|
||||
|
||||
func handlePartialVoteArea(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
room, err := lib.GetRoomByID(roomID)
|
||||
if err != nil {
|
||||
http.Error(w, "room not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if room.ActiveStoryID == nil {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
story, err := lib.GetStoryByID(*room.ActiveStoryID)
|
||||
if err != nil {
|
||||
http.Error(w, "story not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
data := struct {
|
||||
RoomData RoomData
|
||||
Story lib.Story
|
||||
}{
|
||||
RoomData: buildRoomData(room, user),
|
||||
Story: *story,
|
||||
}
|
||||
renderTemplate(w, "vote-area", data)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package api
|
||||
|
||||
import "net/http"
|
||||
|
||||
func SetupRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("/login", handleLogin)
|
||||
mux.HandleFunc("/register", handleRegister)
|
||||
mux.HandleFunc("/logout", handleLogout)
|
||||
|
||||
mux.HandleFunc("/", requireAuth(handleIndex))
|
||||
mux.HandleFunc("/rooms/new", requireAuth(handleNewRoom))
|
||||
mux.HandleFunc("/rooms/create", requireAuth(handleCreateRoom))
|
||||
mux.HandleFunc("/rooms/join", requireAuth(handleJoinRoom))
|
||||
mux.HandleFunc("/rooms/{id}", requireAuth(handleRoom))
|
||||
|
||||
mux.HandleFunc("/rooms/{id}/partial/stories", requireAuth(handlePartialStories))
|
||||
mux.HandleFunc("/rooms/{id}/partial/members", requireAuth(handlePartialMembers))
|
||||
mux.HandleFunc("/rooms/{id}/partial/vote-area", requireAuth(handlePartialVoteArea))
|
||||
|
||||
mux.HandleFunc("/rooms/{id}/stories/new", requireAuth(handleNewStoryForm))
|
||||
mux.HandleFunc("/rooms/{id}/stories", requireAuth(handleAddStory))
|
||||
mux.HandleFunc("/rooms/{id}/active", requireAuth(handleSetActiveStory))
|
||||
mux.HandleFunc("/rooms/{id}/vote", requireAuth(handleVote))
|
||||
mux.HandleFunc("/rooms/{id}/reveal", requireAuth(handleReveal))
|
||||
mux.HandleFunc("/rooms/{id}/stories/{story_id}/edit", requireAuth(handleEditStoryForm))
|
||||
mux.HandleFunc("/rooms/{id}/stories/{story_id}/rename", requireAuth(handleRenameStory))
|
||||
mux.HandleFunc("/rooms/{id}/stories/{story_id}/delete", requireAuth(handleDeleteStory))
|
||||
mux.HandleFunc("/rooms/{id}/stories/{story_id}/reset", requireAuth(handleResetStory))
|
||||
mux.HandleFunc("/rooms/{id}/stories/{story_id}/unreveal", requireAuth(handleUnrevealStory))
|
||||
mux.HandleFunc("/sse/{room_id}", requireAuth(handleSSE))
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"sprintpadawan/lib"
|
||||
)
|
||||
|
||||
func handleSSE(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getPathInt(r, "room_id")
|
||||
user, ok := r.Context().Value(userKey).(*lib.User)
|
||||
if !ok {
|
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
ch := make(chan string, 10)
|
||||
addSSEClient(roomID, user.ID, ch)
|
||||
broadcast(roomID, "members")
|
||||
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
w.Header().Set("Connection", "keep-alive")
|
||||
w.Header().Set("X-Accel-Buffering", "no")
|
||||
|
||||
flusher, ok := w.(http.Flusher)
|
||||
if !ok {
|
||||
http.Error(w, "streaming unsupported", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
notify := r.Context().Done()
|
||||
heartbeat := time.NewTicker(25 * time.Second)
|
||||
defer heartbeat.Stop()
|
||||
|
||||
fmt.Fprint(w, ": connected\n\n")
|
||||
flusher.Flush()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-notify:
|
||||
removeSSEClient(roomID, ch)
|
||||
broadcast(roomID, "members")
|
||||
return
|
||||
case <-heartbeat.C:
|
||||
fmt.Fprint(w, ": keep-alive\n\n")
|
||||
flusher.Flush()
|
||||
case event := <-ch:
|
||||
fmt.Fprintf(w, "event: %s\ndata: true\n\n", event)
|
||||
flusher.Flush()
|
||||
}
|
||||
}
|
||||
}
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"sprintpadawan/lib"
|
||||
)
|
||||
|
||||
func handleNewStoryForm(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
room, _ := lib.GetRoomByID(roomID)
|
||||
renderTemplate(w, "story_form.html", room)
|
||||
}
|
||||
|
||||
func handleAddStory(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
title := r.FormValue("title")
|
||||
if _, err := lib.CreateStory(id, title); err != nil {
|
||||
log.Printf("create story error: %v", err)
|
||||
http.Error(w, "failed to create story", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
broadcast(id, "stories")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleSetActiveStory(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
var sid int
|
||||
fmt.Sscanf(r.FormValue("story_id"), "%d", &sid)
|
||||
|
||||
lib.SetActiveStory(id, sid)
|
||||
|
||||
broadcast(id, "stories")
|
||||
broadcast(id, "members")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleResetStory(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
var sid int
|
||||
fmt.Sscanf(r.PathValue("story_id"), "%d", &sid)
|
||||
|
||||
lib.UnrevealStory(sid)
|
||||
lib.ClearVotesForStory(sid)
|
||||
|
||||
broadcast(id, "stories")
|
||||
broadcast(id, "members")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleVote(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
value := r.FormValue("value")
|
||||
var sid int
|
||||
fmt.Sscanf(r.FormValue("story_id"), "%d", &sid)
|
||||
|
||||
lib.VoteOnStory(sid, user.ID, value)
|
||||
broadcast(id, "members")
|
||||
story, storyErr := lib.GetStoryByID(sid)
|
||||
if storyErr == nil && story.Voted {
|
||||
broadcast(id, "stories")
|
||||
}
|
||||
|
||||
if isHTMX(r) {
|
||||
room, _ := lib.GetRoomByID(id)
|
||||
if storyErr != nil {
|
||||
http.Error(w, "story not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
tmplData := struct {
|
||||
RoomID int
|
||||
Story lib.Story
|
||||
Scale string
|
||||
UserVote string
|
||||
}{
|
||||
RoomID: id,
|
||||
Story: *story,
|
||||
Scale: room.Scale,
|
||||
UserVote: value,
|
||||
}
|
||||
renderTemplate(w, "vote_form.html", tmplData)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleReveal(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
var sid int
|
||||
fmt.Sscanf(r.FormValue("story_id"), "%d", &sid)
|
||||
lib.RevealVotes(sid)
|
||||
broadcast(id, "stories")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleUnrevealStory(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
var sid int
|
||||
fmt.Sscanf(r.PathValue("story_id"), "%d", &sid)
|
||||
lib.UnrevealStory(sid)
|
||||
broadcast(id, "stories")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleEditStoryForm(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
var storyID int
|
||||
fmt.Sscanf(r.PathValue("story_id"), "%d", &storyID)
|
||||
story, _ := lib.GetStoryByID(storyID)
|
||||
data := struct {
|
||||
RoomID int
|
||||
Story lib.Story
|
||||
}{
|
||||
RoomID: roomID,
|
||||
Story: *story,
|
||||
}
|
||||
renderTemplate(w, "story_edit.html", data)
|
||||
}
|
||||
|
||||
func handleRenameStory(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
var sid int
|
||||
fmt.Sscanf(r.PathValue("story_id"), "%d", &sid)
|
||||
title := r.FormValue("title")
|
||||
lib.RenameStory(sid, title)
|
||||
broadcast(id, "stories")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func handleDeleteStory(w http.ResponseWriter, r *http.Request) {
|
||||
id := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
var sid int
|
||||
fmt.Sscanf(r.PathValue("story_id"), "%d", &sid)
|
||||
lib.DeleteStory(sid)
|
||||
broadcast(id, "stories")
|
||||
if isHTMX(r) {
|
||||
renderRoomStories(w, id, user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/rooms/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"sprintpadawan/lib"
|
||||
)
|
||||
|
||||
var templates *template.Template
|
||||
|
||||
func init() {
|
||||
templates = template.Must(template.New("").Funcs(template.FuncMap{
|
||||
"scaleToOptions": scaleToOptions,
|
||||
"derefInt": func(i *int) int {
|
||||
if i == nil {
|
||||
return 0
|
||||
}
|
||||
return *i
|
||||
},
|
||||
"slice": func(s string, start, end int) string {
|
||||
if len(s) == 0 {
|
||||
return ""
|
||||
}
|
||||
if start < 0 {
|
||||
start = 0
|
||||
}
|
||||
if end > len(s) || end <= 0 {
|
||||
end = len(s)
|
||||
}
|
||||
if start > end {
|
||||
return ""
|
||||
}
|
||||
return s[start:end]
|
||||
},
|
||||
"dict": func(values ...interface{}) (map[string]interface{}, error) {
|
||||
if len(values)%2 != 0 {
|
||||
return nil, fmt.Errorf("odd number of arguments to dict")
|
||||
}
|
||||
d := make(map[string]interface{})
|
||||
for i := 0; i < len(values); i += 2 {
|
||||
key, ok := values[i].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("dict keys must be strings")
|
||||
}
|
||||
d[key] = values[i+1]
|
||||
}
|
||||
return d, nil
|
||||
},
|
||||
}).ParseGlob(filepath.Join("templates", "*.html")))
|
||||
}
|
||||
|
||||
func isHTMX(r *http.Request) bool {
|
||||
return r.Header.Get("HX-Request") == "true"
|
||||
}
|
||||
|
||||
func renderTemplate(w http.ResponseWriter, name string, data interface{}) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := templates.ExecuteTemplate(w, name, data); err != nil {
|
||||
log.Printf("template error (%s): %v", name, err)
|
||||
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func renderRoomStories(w http.ResponseWriter, roomID int, user *lib.User) {
|
||||
room, err := lib.GetRoomByID(roomID)
|
||||
if err != nil {
|
||||
http.Error(w, "room not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
renderTemplate(w, "stories-panel", buildRoomData(room, user))
|
||||
}
|
||||
|
||||
func renderRoomMembers(w http.ResponseWriter, roomID int, user *lib.User) {
|
||||
room, err := lib.GetRoomByID(roomID)
|
||||
if err != nil {
|
||||
http.Error(w, "room not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
renderTemplate(w, "members-panel", buildRoomData(room, user))
|
||||
}
|
||||
|
||||
func requireAuth(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
cookie, err := r.Cookie("session_token")
|
||||
if err != nil {
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
user, err := lib.GetUserFromSession(cookie.Value)
|
||||
if err != nil || user == nil {
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
ctx := context.WithValue(r.Context(), userKey, user)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
}
|
||||
}
|
||||
|
||||
func isLoggedIn(r *http.Request) bool {
|
||||
cookie, err := r.Cookie("session_token")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
user, err := lib.GetUserFromSession(cookie.Value)
|
||||
return err == nil && user != nil
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"sprintpadawan/lib"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
const userKey contextKey = "user"
|
||||
|
||||
type sseClient struct {
|
||||
ch chan string
|
||||
userID int
|
||||
}
|
||||
|
||||
type MemberView struct {
|
||||
Username string
|
||||
HasVoted bool
|
||||
ID int
|
||||
}
|
||||
|
||||
type RoomData struct {
|
||||
*lib.Room
|
||||
User *lib.User
|
||||
Members []MemberView
|
||||
Stories []lib.Story
|
||||
IsOwner bool
|
||||
UserVotes map[int]string
|
||||
StoryVotes map[int][]lib.VoteView
|
||||
}
|
||||
|
||||
var (
|
||||
roomClients = make(map[int][]*sseClient)
|
||||
clientsMu sync.Mutex
|
||||
)
|
||||
|
||||
func addSSEClient(roomID, userID int, ch chan string) {
|
||||
clientsMu.Lock()
|
||||
defer clientsMu.Unlock()
|
||||
roomClients[roomID] = append(roomClients[roomID], &sseClient{ch: ch, userID: userID})
|
||||
}
|
||||
|
||||
func removeSSEClient(roomID int, ch chan string) {
|
||||
clientsMu.Lock()
|
||||
defer clientsMu.Unlock()
|
||||
clients := roomClients[roomID]
|
||||
for i, c := range clients {
|
||||
if c.ch == ch {
|
||||
roomClients[roomID] = append(clients[:i], clients[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(roomClients[roomID]) == 0 {
|
||||
delete(roomClients, roomID)
|
||||
}
|
||||
}
|
||||
|
||||
func broadcast(roomID int, event string) {
|
||||
clientsMu.Lock()
|
||||
defer clientsMu.Unlock()
|
||||
alive := roomClients[roomID][:0]
|
||||
for _, c := range roomClients[roomID] {
|
||||
select {
|
||||
case c.ch <- event:
|
||||
alive = append(alive, c)
|
||||
default:
|
||||
// drop dead client
|
||||
}
|
||||
}
|
||||
roomClients[roomID] = alive
|
||||
}
|
||||
|
||||
func GetConnectedUserIDs(roomID int) []int {
|
||||
clientsMu.Lock()
|
||||
defer clientsMu.Unlock()
|
||||
seen := make(map[int]bool)
|
||||
var ids []int
|
||||
for _, c := range roomClients[roomID] {
|
||||
if !seen[c.userID] {
|
||||
seen[c.userID] = true
|
||||
ids = append(ids, c.userID)
|
||||
}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
func scaleToOptions(scale string) []string {
|
||||
switch scale {
|
||||
case "fibonacci":
|
||||
return []string{"1", "2", "3", "5", "8", "13", "21", "?"}
|
||||
case "tshirt":
|
||||
return []string{"XS", "S", "M", "L", "XL", "XXL", "?"}
|
||||
case "linear":
|
||||
return []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "?"}
|
||||
default:
|
||||
return []string{"1", "2", "3", "5", "8", "13", "21", "?"}
|
||||
}
|
||||
}
|
||||
|
||||
func getRoomID(r *http.Request) int {
|
||||
return getPathInt(r, "id")
|
||||
}
|
||||
|
||||
func getPathInt(r *http.Request, key string) int {
|
||||
var id int
|
||||
fmt.Sscanf(r.PathValue(key), "%d", &id)
|
||||
return id
|
||||
}
|
||||
|
||||
func buildRoomData(room *lib.Room, user *lib.User) RoomData {
|
||||
members, _ := lib.GetRoomMembers(room.ID)
|
||||
stories, _ := lib.GetStoriesForRoom(room.ID)
|
||||
connectedIDs := GetConnectedUserIDs(room.ID)
|
||||
connectedMap := make(map[int]bool)
|
||||
for _, cid := range connectedIDs {
|
||||
connectedMap[cid] = true
|
||||
}
|
||||
connectedMap[user.ID] = true
|
||||
|
||||
var activeVotes []lib.Vote
|
||||
if room.ActiveStoryID != nil {
|
||||
activeVotes, _ = lib.GetVotesForStory(*room.ActiveStoryID)
|
||||
}
|
||||
|
||||
var memberViews []MemberView
|
||||
for _, m := range members {
|
||||
if !connectedMap[m.ID] {
|
||||
continue
|
||||
}
|
||||
hasVoted := false
|
||||
for _, v := range activeVotes {
|
||||
if v.UserID == m.ID {
|
||||
hasVoted = true
|
||||
break
|
||||
}
|
||||
}
|
||||
memberViews = append(memberViews, MemberView{
|
||||
Username: m.Username,
|
||||
HasVoted: hasVoted,
|
||||
ID: m.ID,
|
||||
})
|
||||
}
|
||||
|
||||
userVotes := make(map[int]string)
|
||||
storyVotes := make(map[int][]lib.VoteView)
|
||||
for _, s := range stories {
|
||||
votes, _ := lib.GetVotesForStory(s.ID)
|
||||
for _, v := range votes {
|
||||
if v.UserID == user.ID {
|
||||
userVotes[s.ID] = v.Value
|
||||
}
|
||||
}
|
||||
if s.Voted {
|
||||
vv, _ := lib.GetVotesWithUsernames(s.ID)
|
||||
storyVotes[s.ID] = vv
|
||||
}
|
||||
}
|
||||
|
||||
return RoomData{
|
||||
Room: room,
|
||||
User: user,
|
||||
Members: memberViews,
|
||||
Stories: stories,
|
||||
IsOwner: room.OwnerID == user.ID,
|
||||
UserVotes: userVotes,
|
||||
StoryVotes: storyVotes,
|
||||
}
|
||||
}
|
||||
+152
-125
@@ -526,34 +526,21 @@ footer a:hover {
|
||||
/* Dashboard */
|
||||
|
||||
.app-shell {
|
||||
display: grid;
|
||||
grid-template-columns: 260px 1fr;
|
||||
display: block;
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
background: #09090b;
|
||||
}
|
||||
|
||||
/* sidebar */
|
||||
.sidebar {
|
||||
background: #09090b;
|
||||
border-right: 1px solid #18181b;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 1.5rem 1rem;
|
||||
overflow-y: auto;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.sidebar-logo {
|
||||
.brand-mark {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
margin-bottom: 2.5rem;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.sidebar-logo .logo-icon {
|
||||
.brand-mark .logo-icon {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: linear-gradient(135deg, var(--accent), #4f46e5);
|
||||
@@ -568,7 +555,7 @@ footer a:hover {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.sidebar-logo .logo-text {
|
||||
.brand-mark .logo-text {
|
||||
font-family: var(--font-heading);
|
||||
font-size: 1.15rem;
|
||||
font-weight: 600;
|
||||
@@ -576,56 +563,10 @@ footer a:hover {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.sidebar-logo .logo-text span {
|
||||
.brand-mark .logo-text span {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
/* Nav */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.65rem;
|
||||
padding: 0.6rem 0.75rem;
|
||||
border-radius: var(--radius-md);
|
||||
color: var(--text-secondary);
|
||||
text-decoration: none;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
transition: all 0.15s;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.nav-item:hover {
|
||||
background: #18181b;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.nav-item.active {
|
||||
background: #18181b;
|
||||
color: var(--text-primary);
|
||||
border-color: #27272a;
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.nav-item svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* sidebar bottom section */
|
||||
.sidebar-footer {
|
||||
margin-top: auto;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.user-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -699,6 +640,7 @@ footer a:hover {
|
||||
flex-direction: column;
|
||||
overflow-y: auto;
|
||||
background: #0d0d12;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.topbar {
|
||||
@@ -707,11 +649,24 @@ footer a:hover {
|
||||
justify-content: space-between;
|
||||
padding: 1rem 2.5rem;
|
||||
border-bottom: 1px solid #18181b;
|
||||
background: #0d0d12;
|
||||
background: rgba(13, 13, 18, 0.94);
|
||||
backdrop-filter: blur(16px);
|
||||
flex-shrink: 0;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 5;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.topbar-brand,
|
||||
.topbar-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.topbar-brand {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.topbar-title {
|
||||
@@ -720,11 +675,76 @@ footer a:hover {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.room-title {
|
||||
max-width: 24rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.topbar-btn {
|
||||
width: auto;
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
|
||||
.topbar-user {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.7rem;
|
||||
min-height: 44px;
|
||||
padding: 0.3rem 0.85rem 0.3rem 0.3rem;
|
||||
border-radius: var(--radius-full);
|
||||
border: 1px solid var(--border);
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
|
||||
}
|
||||
|
||||
.topbar-user-name {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.topbar-user .user-avatar {
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
border-radius: 16px;
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
border: 1px solid rgba(255, 255, 255, 0.04);
|
||||
color: var(--text-primary);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
|
||||
}
|
||||
|
||||
.topbar-link-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 40px;
|
||||
padding: 0.55rem 0.9rem;
|
||||
border-radius: var(--radius-full);
|
||||
background: transparent;
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.85rem;
|
||||
font-family: var(--font);
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.topbar-link-btn:hover {
|
||||
border-color: rgba(239, 68, 68, 0.4);
|
||||
color: #f87171;
|
||||
background: rgba(239, 68, 68, 0.06);
|
||||
}
|
||||
|
||||
.page-content {
|
||||
padding: 2rem;
|
||||
flex: 1;
|
||||
max-width: 900px;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
/* welcome hero */
|
||||
@@ -1057,6 +1077,10 @@ footer a:hover {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.story-action-form {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.story-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -1164,11 +1188,11 @@ footer a:hover {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
padding: 0;
|
||||
border-radius: var(--radius-sm);
|
||||
background: transparent;
|
||||
border-radius: 14px;
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
@@ -1176,10 +1200,52 @@ footer a:hover {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.story-action-btn svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
.story-action-btn:hover {
|
||||
background: var(--bg-surface-hover);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border-accent);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.story-action-btn-toggle {
|
||||
color: var(--accent);
|
||||
border-color: rgba(99, 102, 241, 0.35);
|
||||
background: rgba(99, 102, 241, 0.08);
|
||||
}
|
||||
|
||||
.story-action-btn-toggle:hover {
|
||||
color: #c7d2fe;
|
||||
border-color: rgba(99, 102, 241, 0.5);
|
||||
background: rgba(99, 102, 241, 0.16);
|
||||
}
|
||||
|
||||
.story-action-btn-activate {
|
||||
color: #f8fafc;
|
||||
border-color: rgba(148, 163, 184, 0.26);
|
||||
background: rgba(148, 163, 184, 0.08);
|
||||
}
|
||||
|
||||
.story-action-btn-activate:hover {
|
||||
color: #ffffff;
|
||||
border-color: rgba(148, 163, 184, 0.42);
|
||||
background: rgba(148, 163, 184, 0.16);
|
||||
}
|
||||
|
||||
.story-action-btn-reset {
|
||||
color: var(--success-text);
|
||||
border-color: rgba(16, 185, 129, 0.26);
|
||||
background: rgba(16, 185, 129, 0.06);
|
||||
}
|
||||
|
||||
.story-action-btn-reset:hover {
|
||||
color: #6ee7b7;
|
||||
border-color: rgba(16, 185, 129, 0.4);
|
||||
background: rgba(16, 185, 129, 0.14);
|
||||
}
|
||||
|
||||
.story-action-btn.story-action-delete:hover {
|
||||
@@ -1249,22 +1315,6 @@ footer a:hover {
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.mobile-menu-btn {
|
||||
display: none;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
padding: 0.25rem;
|
||||
border-radius: var(--radius-sm);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.mobile-menu-btn:hover {
|
||||
color: var(--text-primary);
|
||||
background: var(--bg-surface-hover);
|
||||
}
|
||||
|
||||
.sse-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
@@ -1283,55 +1333,32 @@ footer a:hover {
|
||||
animation: pulse 2s ease infinite;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
|
||||
.sidebar-backdrop {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
backdrop-filter: blur(4px);
|
||||
z-index: 90;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.app-shell {
|
||||
grid-template-columns: 1fr;
|
||||
.topbar {
|
||||
padding: 1rem 1.1rem;
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.mobile-menu-btn {
|
||||
display: block;
|
||||
.topbar-brand,
|
||||
.topbar-actions {
|
||||
width: 100%;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.sidebar-backdrop.open {
|
||||
display: block;
|
||||
opacity: 1;
|
||||
.topbar-actions {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
width: 280px;
|
||||
z-index: 100;
|
||||
transform: translateX(-100%);
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
background: var(--bg); /* Opaque background for mobile menu */
|
||||
border-right: 1px solid var(--border);
|
||||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
|
||||
.page-content {
|
||||
padding: 1.1rem;
|
||||
}
|
||||
|
||||
.sidebar.open {
|
||||
transform: translateX(0);
|
||||
.room-title {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.dashboard-grid {
|
||||
grid-template-columns: 1fr;
|
||||
.topbar-user {
|
||||
order: 2;
|
||||
}
|
||||
}
|
||||
|
||||
+39
-85
@@ -1,60 +1,22 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Dashboard — SprintPadawan</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Outfit:wght@500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link rel="stylesheet" href="/static/styles/main.css" />
|
||||
<script src="/static/js/htmx.min.js" defer></script>
|
||||
</head>
|
||||
{{template "app-head" (dict "Title" "Dashboard" "UseHTMX" true "UseSSE"
|
||||
false)}}
|
||||
<body class="app-body">
|
||||
<div class="app-shell">
|
||||
<div id="sidebar-backdrop" class="sidebar-backdrop" onclick="document.getElementById('app-sidebar').classList.remove('open'); document.getElementById('sidebar-backdrop').classList.remove('open')"></div>
|
||||
<!-- sidebar -->
|
||||
<aside class="sidebar" id="app-sidebar">
|
||||
<div class="sidebar-logo">
|
||||
<div class="logo-icon">⚡</div>
|
||||
<span class="logo-text"><span>Sprint</span>Padawan</span>
|
||||
</div>
|
||||
|
||||
<nav class="sidebar-nav">
|
||||
<a href="/" class="nav-item active">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="3" width="7" height="7" />
|
||||
<rect x="14" y="3" width="7" height="7" />
|
||||
<rect x="3" y="14" width="7" height="7" />
|
||||
<rect x="14" y="14" width="7" height="7" />
|
||||
</svg>
|
||||
Rooms
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<div class="sidebar-footer">
|
||||
<div class="user-row">
|
||||
<div class="user-avatar">{{slice .Username 0 1}}</div>
|
||||
<div class="user-info">
|
||||
<span class="user-name">{{.Username}}</span>
|
||||
<span class="user-role">Member</span>
|
||||
</div>
|
||||
<div class="main-content">
|
||||
<header class="topbar">
|
||||
<div class="topbar-brand">
|
||||
{{template "brand-mark" .}}
|
||||
<span class="topbar-title">Planning Rooms</span>
|
||||
</div>
|
||||
<form method="POST" action="/logout">
|
||||
<button class="sign-out-btn" type="submit">
|
||||
<div class="topbar-actions">
|
||||
<button
|
||||
class="btn-primary topbar-btn"
|
||||
hx-get="/rooms/new"
|
||||
hx-target="body"
|
||||
hx-swap="beforeend"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="14"
|
||||
@@ -66,37 +28,13 @@
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path
|
||||
d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"
|
||||
/>
|
||||
<polyline points="16 17 21 12 16 7" />
|
||||
<line x1="21" y1="12" x2="9" y2="12" />
|
||||
<line x1="12" y1="5" x2="12" y2="19"></line>
|
||||
<line x1="5" y1="12" x2="19" y2="12"></line>
|
||||
</svg>
|
||||
Sign Out
|
||||
Create Room
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div class="main-content">
|
||||
<header class="topbar">
|
||||
<div style="display: flex; align-items: center; gap: 1rem;">
|
||||
<button class="mobile-menu-btn" onclick="document.getElementById('app-sidebar').classList.toggle('open'); document.getElementById('sidebar-backdrop').classList.toggle('open')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="3" y1="12" x2="21" y2="12"></line>
|
||||
<line x1="3" y1="6" x2="21" y2="6"></line>
|
||||
<line x1="3" y1="18" x2="21" y2="18"></line>
|
||||
</svg>
|
||||
</button>
|
||||
<span class="topbar-title">Planning Rooms</span>
|
||||
{{template "session-controls" .}}
|
||||
</div>
|
||||
<button class="btn-primary" style="width: auto; padding: 0.5rem 1rem;" hx-get="/rooms/new" hx-target="body" hx-swap="beforeend">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="12" y1="5" x2="12" y2="19"></line>
|
||||
<line x1="5" y1="12" x2="19" y2="12"></line>
|
||||
</svg>
|
||||
Create Room
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<main class="page-content">
|
||||
@@ -115,16 +53,33 @@
|
||||
<a href="/rooms/{{.ID}}" class="room-card">
|
||||
<div class="room-header">
|
||||
<span class="room-name">{{.Name}}</span>
|
||||
<div style="display: flex; gap: 0.5rem; align-items: center;">
|
||||
<div
|
||||
style="
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
"
|
||||
>
|
||||
{{if .IsOwner}}
|
||||
<span class="room-owner-badge" style="position: static; margin: 0; padding: 0.2rem 0.5rem;">Owner</span>
|
||||
<span
|
||||
class="room-owner-badge"
|
||||
style="
|
||||
position: static;
|
||||
margin: 0;
|
||||
padding: 0.2rem 0.5rem;
|
||||
"
|
||||
>
|
||||
Owner
|
||||
</span>
|
||||
{{end}}
|
||||
<span class="room-code">{{.Code}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="room-meta">
|
||||
<span class="room-scale">{{.Scale}}</span>
|
||||
<span class="room-members">{{.MemberCount}} members</span>
|
||||
<span class="room-members"
|
||||
>{{.MemberCount}} members</span
|
||||
>
|
||||
</div>
|
||||
</a>
|
||||
{{end}}
|
||||
@@ -138,7 +93,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- modal container -->
|
||||
<div id="modal-container"></div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
{{define "app-head"}}
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{{.Title}} — SprintPadawan</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Outfit:wght@500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link rel="stylesheet" href="/static/styles/main.css" />
|
||||
{{if .UseHTMX}}
|
||||
<script src="/static/js/htmx.min.js" defer></script>
|
||||
{{end}} {{if .UseSSE}}
|
||||
<script src="/static/js/sse.js" defer></script>
|
||||
{{end}}
|
||||
</head>
|
||||
{{end}}
|
||||
|
||||
{{define "auth-head"}}
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{{.Title}} — SprintPadawan</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Outfit:wght@500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link rel="stylesheet" href="/static/styles/main.css" />
|
||||
</head>
|
||||
{{end}}
|
||||
|
||||
{{define "brand-mark"}}
|
||||
<a href="/" class="brand-mark">
|
||||
<span class="logo-icon">⚡</span>
|
||||
<span class="logo-text"><span>Sprint</span>Padawan</span>
|
||||
</a>
|
||||
{{end}}
|
||||
|
||||
{{define "session-controls"}}
|
||||
<div class="topbar-user">
|
||||
<div class="user-avatar">{{slice .Username 0 1}}</div>
|
||||
<span class="topbar-user-name">{{.Username}}</span>
|
||||
</div>
|
||||
<form method="POST" action="/logout">
|
||||
<button class="topbar-link-btn" type="submit">Sign Out</button>
|
||||
</form>
|
||||
{{end}}
|
||||
+1
-12
@@ -1,17 +1,6 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Sign In — SprintPadawan</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Outfit:wght@500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link rel="stylesheet" href="/static/styles/main.css" />
|
||||
</head>
|
||||
{{template "auth-head" (dict "Title" "Sign In")}}
|
||||
<body>
|
||||
<div class="auth-card">
|
||||
<div class="auth-logo">
|
||||
|
||||
+7
-14
@@ -1,17 +1,6 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Register — SprintPadawan</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Outfit:wght@500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link rel="stylesheet" href="/static/styles/main.css" />
|
||||
</head>
|
||||
{{template "auth-head" (dict "Title" "Register")}}
|
||||
<body>
|
||||
<div class="auth-card">
|
||||
<div class="auth-logo">
|
||||
@@ -70,7 +59,9 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="confirm_password">Confirm Password</label>
|
||||
<label class="form-label" for="confirm_password"
|
||||
>Confirm Password</label
|
||||
>
|
||||
<input
|
||||
class="form-input"
|
||||
type="password"
|
||||
@@ -82,7 +73,9 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button class="btn-primary" type="submit">Create Account</button>
|
||||
<button class="btn-primary" type="submit">
|
||||
Create Account
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p class="auth-footer">
|
||||
|
||||
+10
-306
@@ -1,128 +1,14 @@
|
||||
{{define "room.html"}}
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{{.Room.Name}} — SprintPadawan</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Outfit:wght@500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link rel="stylesheet" href="/static/styles/main.css" />
|
||||
<script src="/static/js/htmx.min.js" defer></script>
|
||||
<script src="/static/js/sse.js" defer></script>
|
||||
</head>
|
||||
{{template "app-head" (dict "Title" .Room.Name "UseHTMX" true "UseSSE"
|
||||
true)}}
|
||||
<body class="app-body">
|
||||
<div class="app-shell">
|
||||
<div
|
||||
id="sidebar-backdrop"
|
||||
class="sidebar-backdrop"
|
||||
onclick="
|
||||
document
|
||||
.getElementById('app-sidebar')
|
||||
.classList.remove('open');
|
||||
document
|
||||
.getElementById('sidebar-backdrop')
|
||||
.classList.remove('open');
|
||||
"
|
||||
></div>
|
||||
|
||||
<aside class="sidebar" id="app-sidebar">
|
||||
<div class="sidebar-logo">
|
||||
<div class="logo-icon">⚡</div>
|
||||
<span class="logo-text"><span>Sprint</span>Padawan</span>
|
||||
</div>
|
||||
|
||||
<nav class="sidebar-nav">
|
||||
<a href="/" class="nav-item">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="3" y="3" width="7" height="7" />
|
||||
<rect x="14" y="3" width="7" height="7" />
|
||||
<rect x="3" y="14" width="7" height="7" />
|
||||
<rect x="14" y="14" width="7" height="7" />
|
||||
</svg>
|
||||
Rooms
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<div class="sidebar-footer">
|
||||
<div class="user-row">
|
||||
<div class="user-avatar">
|
||||
{{slice .User.Username 0 1}}
|
||||
</div>
|
||||
<div class="user-info">
|
||||
<span class="user-name">{{.User.Username}}</span>
|
||||
<span class="user-role">Member</span>
|
||||
</div>
|
||||
</div>
|
||||
<form method="POST" action="/logout">
|
||||
<button class="sign-out-btn" type="submit">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path
|
||||
d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"
|
||||
/>
|
||||
<polyline points="16 17 21 12 16 7" />
|
||||
<line x1="21" y1="12" x2="9" y2="12" />
|
||||
</svg>
|
||||
Sign Out
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div class="main-content">
|
||||
<header class="topbar">
|
||||
<div style="display: flex; align-items: center; gap: 1rem">
|
||||
<button
|
||||
class="mobile-menu-btn"
|
||||
onclick="
|
||||
document
|
||||
.getElementById('app-sidebar')
|
||||
.classList.toggle('open');
|
||||
document
|
||||
.getElementById('sidebar-backdrop')
|
||||
.classList.toggle('open');
|
||||
"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="20"
|
||||
height="20"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<line x1="3" y1="12" x2="21" y2="12"></line>
|
||||
<line x1="3" y1="6" x2="21" y2="6"></line>
|
||||
<line x1="3" y1="18" x2="21" y2="18"></line>
|
||||
</svg>
|
||||
</button>
|
||||
<div class="topbar-brand">
|
||||
{{template "brand-mark" .}}
|
||||
<a href="/" class="back-btn">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
@@ -139,20 +25,19 @@
|
||||
<polyline points="12 19 5 12 12 5"></polyline>
|
||||
</svg>
|
||||
</a>
|
||||
<span class="topbar-title">{{.Room.Name}}</span>
|
||||
<span class="topbar-title room-title"
|
||||
>{{.Room.Name}}</span
|
||||
>
|
||||
<span class="room-code-badge">{{.Room.Code}}</span>
|
||||
</div>
|
||||
<div
|
||||
style="display: flex; align-items: center; gap: 0.75rem"
|
||||
>
|
||||
<div class="topbar-actions">
|
||||
<span class="scale-badge">{{.Room.Scale}}</span>
|
||||
{{if .IsOwner}}
|
||||
<button
|
||||
hx-get="/rooms/{{.Room.ID}}/stories/new"
|
||||
hx-target="#modal-container"
|
||||
hx-swap="innerHTML"
|
||||
class="btn-primary"
|
||||
style="width: auto; padding: 0.5rem 1rem"
|
||||
class="btn-primary topbar-btn"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
@@ -170,7 +55,7 @@
|
||||
</svg>
|
||||
Add Story
|
||||
</button>
|
||||
{{end}}
|
||||
{{end}} {{template "session-controls" .User}}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -210,185 +95,4 @@
|
||||
{{template "sse-script"}}
|
||||
</body>
|
||||
</html>
|
||||
{{end}} {{define "stories-panel"}}
|
||||
<div class="stories-panel" id="stories-panel">
|
||||
<div
|
||||
style="
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 1.5rem;
|
||||
"
|
||||
>
|
||||
<h3 class="panel-title">Stories</h3>
|
||||
<div class="sse-indicator">
|
||||
<span class="sse-dot"></span>
|
||||
<span>Live</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stories-list" id="stories-list">
|
||||
{{template "stories-list" .}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}} {{define "stories-list"}} {{range .Stories}} {{$isActive := eq (derefInt
|
||||
$.Room.ActiveStoryID) .ID}}
|
||||
<div
|
||||
class="story-card {{if .Voted}}story-revealed{{end}} {{if $isActive}}story-active{{end}}"
|
||||
id="story-{{.ID}}"
|
||||
>
|
||||
<div class="story-header">
|
||||
<span class="story-title">{{.Title}}</span>
|
||||
<div class="story-actions">
|
||||
{{if .Voted}}
|
||||
<span class="story-badge story-badge-revealed">Revealed</span>
|
||||
{{if $.IsOwner}}
|
||||
<form
|
||||
method="POST"
|
||||
action="/rooms/{{$.Room.ID}}/stories/{{.ID}}/unreveal"
|
||||
hx-post="/rooms/{{$.Room.ID}}/stories/{{.ID}}/unreveal"
|
||||
hx-target="#stories-panel"
|
||||
hx-swap="outerHTML"
|
||||
style="margin: 0"
|
||||
>
|
||||
<button type="submit" class="story-btn story-btn-secondary">
|
||||
Hide
|
||||
</button>
|
||||
</form>
|
||||
{{end}} {{else if $.IsOwner}} {{if $isActive}}
|
||||
<form
|
||||
method="POST"
|
||||
action="/rooms/{{$.Room.ID}}/reveal"
|
||||
hx-post="/rooms/{{$.Room.ID}}/reveal"
|
||||
hx-target="#stories-panel"
|
||||
hx-swap="outerHTML"
|
||||
style="margin: 0"
|
||||
>
|
||||
<input type="hidden" name="story_id" value="{{.ID}}" />
|
||||
<button type="submit" class="story-btn story-btn-primary">
|
||||
Reveal
|
||||
</button>
|
||||
</form>
|
||||
<span class="story-badge story-badge-active">Active</span>
|
||||
{{else}}
|
||||
<form
|
||||
method="POST"
|
||||
action="/rooms/{{$.Room.ID}}/active"
|
||||
hx-post="/rooms/{{$.Room.ID}}/active"
|
||||
hx-target="#stories-panel"
|
||||
hx-swap="outerHTML"
|
||||
style="margin: 0"
|
||||
>
|
||||
<input type="hidden" name="story_id" value="{{.ID}}" />
|
||||
<button type="submit" class="story-btn story-btn-secondary">
|
||||
Set Active
|
||||
</button>
|
||||
</form>
|
||||
{{end}} {{end}} {{if $.IsOwner}}
|
||||
<button
|
||||
type="button"
|
||||
class="story-action-btn"
|
||||
hx-get="/rooms/{{$.Room.ID}}/stories/{{.ID}}/edit"
|
||||
hx-target="#modal-container"
|
||||
hx-swap="innerHTML"
|
||||
title="Rename"
|
||||
>
|
||||
✎
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="story-action-btn story-action-delete"
|
||||
hx-post="/rooms/{{$.Room.ID}}/stories/{{.ID}}/delete"
|
||||
hx-target="#stories-panel"
|
||||
hx-swap="outerHTML"
|
||||
hx-confirm="Delete this story?"
|
||||
title="Delete"
|
||||
>
|
||||
🗑
|
||||
</button>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{if $isActive}}
|
||||
<div id="vote-area">
|
||||
{{template "vote-area" (dict "RoomData" $ "Story" .)}}
|
||||
</div>
|
||||
{{end}} {{if .Voted}}
|
||||
<div class="revealed-votes">
|
||||
{{range (index $.StoryVotes .ID)}}
|
||||
<div class="revealed-vote">
|
||||
<span class="revealed-vote-user">{{.Username}}</span>
|
||||
<span class="revealed-vote-value">{{.Value}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="empty-state">
|
||||
<p>No stories yet. Add one to start voting.</p>
|
||||
</div>
|
||||
{{end}} {{end}} {{define "vote-area"}} {{$data := .RoomData}} {{$story :=
|
||||
.Story}} {{$userVote := index $data.UserVotes $story.ID}}
|
||||
<div class="vote-form" id="vote-form-{{$story.ID}}">
|
||||
{{range scaleToOptions $data.Room.Scale}}
|
||||
<button
|
||||
type="button"
|
||||
hx-post="/rooms/{{$data.Room.ID}}/vote"
|
||||
hx-target="#vote-form-{{$story.ID}}"
|
||||
hx-swap="outerHTML"
|
||||
hx-vals='{"story_id":"{{$story.ID}}","value":"{{.}}"}'
|
||||
class="vote-option {{if eq . $userVote}}vote-selected{{end}}"
|
||||
>
|
||||
{{.}}
|
||||
</button>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}} {{define "members-panel"}}
|
||||
<div class="members-panel" id="members-panel">
|
||||
<h3 class="panel-title">Members ({{len .Members}})</h3>
|
||||
<div class="members-list">
|
||||
{{range .Members}}
|
||||
<div class="member-row">
|
||||
<div
|
||||
class="user-avatar"
|
||||
style="width: 28px; height: 28px; font-size: 0.7rem"
|
||||
>
|
||||
{{slice .Username 0 1}}
|
||||
</div>
|
||||
<span class="member-name">{{.Username}}</span>
|
||||
{{if .HasVoted}}
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="var(--success-text)"
|
||||
stroke-width="3"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
style="margin-left: auto"
|
||||
>
|
||||
<polyline points="20 6 9 17 4 12"></polyline>
|
||||
</svg>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}} {{define "sse-script"}}
|
||||
<script>
|
||||
document.addEventListener("htmx:sseOpen", function() {
|
||||
document.body.classList.add("sse-connected");
|
||||
});
|
||||
|
||||
document.addEventListener("htmx:sseClose", function() {
|
||||
document.body.classList.remove("sse-connected");
|
||||
});
|
||||
|
||||
document.addEventListener("htmx:sseError", function() {
|
||||
document.body.classList.remove("sse-connected");
|
||||
});
|
||||
</script>
|
||||
{{end}}
|
||||
|
||||
@@ -0,0 +1,316 @@
|
||||
{{define "stories-panel"}}
|
||||
<div class="stories-panel" id="stories-panel">
|
||||
<div
|
||||
style="
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 1.5rem;
|
||||
"
|
||||
>
|
||||
<h3 class="panel-title">Stories</h3>
|
||||
<div class="sse-indicator">
|
||||
<span class="sse-dot"></span>
|
||||
<span>Live</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stories-list" id="stories-list">
|
||||
{{template "stories-list" .}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "stories-list"}} {{range .Stories}} {{$isActive := eq (derefInt
|
||||
$.Room.ActiveStoryID) .ID}}
|
||||
<div
|
||||
class="story-card {{if .Voted}}story-revealed{{end}} {{if $isActive}}story-active{{end}}"
|
||||
id="story-{{.ID}}"
|
||||
>
|
||||
<div class="story-header">
|
||||
<span class="story-title">{{.Title}}</span>
|
||||
<div class="story-actions">
|
||||
{{if $isActive}}
|
||||
<span class="story-badge story-badge-active">Active</span>
|
||||
{{end}} {{if $.IsOwner}} {{if .Voted}}
|
||||
<form
|
||||
method="POST"
|
||||
action="/rooms/{{$.Room.ID}}/stories/{{.ID}}/unreveal"
|
||||
hx-post="/rooms/{{$.Room.ID}}/stories/{{.ID}}/unreveal"
|
||||
hx-target="#stories-panel"
|
||||
hx-swap="outerHTML"
|
||||
class="story-action-form"
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
class="story-action-btn story-action-btn-toggle"
|
||||
title="Hide votes"
|
||||
aria-label="Hide votes"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path
|
||||
d="M10.733 5.076A10.744 10.744 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.673 2.68"
|
||||
/>
|
||||
<path
|
||||
d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"
|
||||
/>
|
||||
<line x1="2" y1="2" x2="22" y2="22" />
|
||||
<path d="M9.88 9.88a3 3 0 1 0 4.24 4.24" />
|
||||
</svg>
|
||||
</button>
|
||||
</form>
|
||||
{{else}}
|
||||
<form
|
||||
method="POST"
|
||||
action="/rooms/{{$.Room.ID}}/reveal"
|
||||
hx-post="/rooms/{{$.Room.ID}}/reveal"
|
||||
hx-target="#stories-panel"
|
||||
hx-swap="outerHTML"
|
||||
class="story-action-form"
|
||||
>
|
||||
<input type="hidden" name="story_id" value="{{.ID}}" />
|
||||
<button
|
||||
type="submit"
|
||||
class="story-action-btn story-action-btn-toggle"
|
||||
title="Reveal votes"
|
||||
aria-label="Reveal votes"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path
|
||||
d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"
|
||||
/>
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
</button>
|
||||
</form>
|
||||
{{end}} {{if not $isActive}}
|
||||
<form
|
||||
method="POST"
|
||||
action="/rooms/{{$.Room.ID}}/active"
|
||||
hx-post="/rooms/{{$.Room.ID}}/active"
|
||||
hx-target="#stories-panel"
|
||||
hx-swap="outerHTML"
|
||||
class="story-action-form"
|
||||
>
|
||||
<input type="hidden" name="story_id" value="{{.ID}}" />
|
||||
<button
|
||||
type="submit"
|
||||
class="story-action-btn story-action-btn-activate"
|
||||
title="Set active"
|
||||
aria-label="Set active"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<polygon points="10 8 16 12 10 16 10 8" />
|
||||
<path d="M4 6v12" />
|
||||
</svg>
|
||||
</button>
|
||||
</form>
|
||||
{{end}} {{if $.IsOwner}}
|
||||
<form
|
||||
method="POST"
|
||||
action="/rooms/{{$.Room.ID}}/stories/{{.ID}}/reset"
|
||||
hx-post="/rooms/{{$.Room.ID}}/stories/{{.ID}}/reset"
|
||||
hx-target="#stories-panel"
|
||||
hx-swap="outerHTML"
|
||||
class="story-action-form"
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
class="story-action-btn story-action-btn-reset"
|
||||
title="Reset votes"
|
||||
aria-label="Reset votes"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M21 2v6h-6" />
|
||||
<path d="M3 12a9 9 0 0 1 15.55-6.36L21 8" />
|
||||
<path d="M3 22v-6h6" />
|
||||
<path d="M21 12a9 9 0 0 1-15.55 6.36L3 16" />
|
||||
</svg>
|
||||
</button>
|
||||
</form>
|
||||
<button
|
||||
type="button"
|
||||
class="story-action-btn"
|
||||
hx-get="/rooms/{{$.Room.ID}}/stories/{{.ID}}/edit"
|
||||
hx-target="#modal-container"
|
||||
hx-swap="innerHTML"
|
||||
title="Rename"
|
||||
aria-label="Rename story"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M12 20h9" />
|
||||
<path
|
||||
d="M16.5 3.5a2.121 2.121 0 1 1 3 3L7 19l-4 1 1-4Z"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="story-action-btn story-action-delete"
|
||||
hx-post="/rooms/{{$.Room.ID}}/stories/{{.ID}}/delete"
|
||||
hx-target="#stories-panel"
|
||||
hx-swap="outerHTML"
|
||||
hx-confirm="Delete this story?"
|
||||
title="Delete"
|
||||
aria-label="Delete story"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M3 6h18" />
|
||||
<path d="M8 6V4h8v2" />
|
||||
<path d="M19 6l-1 14H6L5 6" />
|
||||
<path d="M10 11v6" />
|
||||
<path d="M14 11v6" />
|
||||
</svg>
|
||||
</button>
|
||||
{{end}} {{end}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{if $isActive}}
|
||||
<div id="vote-area">
|
||||
{{template "vote-area" (dict "RoomData" $ "Story" .)}}
|
||||
</div>
|
||||
{{end}} {{if .Voted}}
|
||||
<div class="revealed-votes">
|
||||
{{range (index $.StoryVotes .ID)}}
|
||||
<div class="revealed-vote">
|
||||
<span class="revealed-vote-user">{{.Username}}</span>
|
||||
<span class="revealed-vote-value">{{.Value}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="empty-state">
|
||||
<p>No stories yet. Add one to start voting.</p>
|
||||
</div>
|
||||
{{end}} {{end}}
|
||||
|
||||
{{define "vote-area"}} {{$data := .RoomData}} {{$story := .Story}} {{$userVote
|
||||
:= index $data.UserVotes $story.ID}}
|
||||
<div class="vote-form" id="vote-form-{{$story.ID}}">
|
||||
{{range scaleToOptions $data.Room.Scale}}
|
||||
<button
|
||||
type="button"
|
||||
hx-post="/rooms/{{$data.Room.ID}}/vote"
|
||||
hx-target="#vote-form-{{$story.ID}}"
|
||||
hx-swap="outerHTML"
|
||||
hx-vals='{"story_id":"{{$story.ID}}","value":"{{.}}"}'
|
||||
class="vote-option {{if eq . $userVote}}vote-selected{{end}}"
|
||||
>
|
||||
{{.}}
|
||||
</button>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "members-panel"}}
|
||||
<div class="members-panel" id="members-panel">
|
||||
<h3 class="panel-title">Members ({{len .Members}})</h3>
|
||||
<div class="members-list">
|
||||
{{range .Members}}
|
||||
<div class="member-row">
|
||||
<div
|
||||
class="user-avatar"
|
||||
style="width: 28px; height: 28px; font-size: 0.7rem"
|
||||
>
|
||||
{{slice .Username 0 1}}
|
||||
</div>
|
||||
<span class="member-name">{{.Username}}</span>
|
||||
{{if .HasVoted}}
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="var(--success-text)"
|
||||
stroke-width="3"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
style="margin-left: auto"
|
||||
>
|
||||
<polyline points="20 6 9 17 4 12"></polyline>
|
||||
</svg>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "sse-script"}}
|
||||
<script>
|
||||
document.addEventListener("htmx:sseOpen", function() {
|
||||
document.body.classList.add("sse-connected");
|
||||
});
|
||||
|
||||
document.addEventListener("htmx:sseClose", function() {
|
||||
document.body.classList.remove("sse-connected");
|
||||
});
|
||||
|
||||
document.addEventListener("htmx:sseError", function() {
|
||||
document.body.classList.remove("sse-connected");
|
||||
});
|
||||
</script>
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user