feat: initial toggling controls
This commit is contained in:
@@ -101,6 +101,7 @@ func streamingRoomStates(
|
||||
}
|
||||
|
||||
// if currently speaking? i guess first lower the hand and then raise new
|
||||
// TODO should return control for raised state
|
||||
func raiseGestureHandRoute(
|
||||
roomsM rooms.RoomManager,
|
||||
) http.HandlerFunc {
|
||||
@@ -130,13 +131,24 @@ func raiseGestureHandRoute(
|
||||
// TODO return error i guess
|
||||
}
|
||||
log.Printf(">> i attempt to get room with closure: %+v\n", outerClosureRoom)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
||||
// then htmx style i'll need to re-render the room, i suppose
|
||||
// oh, not really, the SSE should send the updated room state
|
||||
tableTemplates := "templates/room.gohtml"
|
||||
tmpl := template.Must(
|
||||
template.New("").ParseFS(templateFs, tableTemplates))
|
||||
gestureData := GestureData{
|
||||
Url: fmt.Sprintf("%s%d", raiseHandPath, gesture),
|
||||
Gesture: gesture,
|
||||
IsSelected: true,
|
||||
}
|
||||
err = tmpl.ExecuteTemplate(w, "activeButton", &gestureData)
|
||||
if err != nil {
|
||||
log.Printf("/rooms/releaseHand error saving hand: %s\n", err)
|
||||
return
|
||||
// TODO return error i guess
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO should return lowered control for passed hand gesture, i guess optional
|
||||
func releaseHandRoute(
|
||||
roomsM rooms.RoomManager,
|
||||
) http.HandlerFunc {
|
||||
@@ -147,6 +159,7 @@ func releaseHandRoute(
|
||||
// TODO return error i guess
|
||||
return
|
||||
}
|
||||
|
||||
err := roomsM.Update(r.Context(), session.RoomId, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||
toRoom = fromRoom
|
||||
toRoom.ReleaseHand(session.PersonId)
|
||||
@@ -157,10 +170,44 @@ func releaseHandRoute(
|
||||
return
|
||||
// TODO return error i guess
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
||||
r.ParseForm() // to return either 'inactive button" or 'no need to change html'
|
||||
gestureString := r.FormValue("gesture")
|
||||
if gestureString != "" {
|
||||
gestureIndex, err := strconv.Atoi(gestureString)
|
||||
if err != nil {
|
||||
log.Printf("/rooms/releaseHand error getting gesture index: %s %s", gestureString, err)
|
||||
return
|
||||
// TODO return error i guess
|
||||
}
|
||||
gesture, ok := rooms.GestureFromInt(gestureIndex)
|
||||
if !ok {
|
||||
log.Printf("/rooms/releaseHand error getting gesture: %s %s", gestureString, err)
|
||||
return
|
||||
// TODO return error i guess
|
||||
}
|
||||
|
||||
tableTemplates := "templates/room.gohtml"
|
||||
tmpl := template.Must(
|
||||
template.New("").ParseFS(templateFs, tableTemplates))
|
||||
gestureData := GestureData{
|
||||
Url: fmt.Sprintf("%s%d", raiseHandPath, gesture),
|
||||
Gesture: gesture,
|
||||
IsSelected: false,
|
||||
}
|
||||
err = tmpl.ExecuteTemplate(w, "inactiveButton", &gestureData)
|
||||
if err != nil {
|
||||
log.Printf("/rooms/releaseHand error saving hand: %s\n", err)
|
||||
return
|
||||
// TODO return error i guess
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func roomPageRoute(
|
||||
templateFs *embed.FS,
|
||||
roomsM rooms.RoomManager,
|
||||
@@ -200,16 +247,13 @@ func roomPageRoute(
|
||||
tmpl := template.Must(
|
||||
template.New("").ParseFS(templateFs, tableTemplates, templFile, baseFile))
|
||||
|
||||
type GestureData struct {
|
||||
Url string
|
||||
Gesture rooms.HandGesture
|
||||
}
|
||||
|
||||
var gesturesData []GestureData
|
||||
selectedGesture, isSelected := room.ParticipantHands[session.PersonId]
|
||||
for _, gesture := range rooms.GesturesHighToLow {
|
||||
gesturesData = append(gesturesData, GestureData{
|
||||
Url: fmt.Sprintf("%s%d", raiseHandPath, gesture),
|
||||
Gesture: gesture,
|
||||
IsSelected: isSelected && selectedGesture == gesture,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -239,3 +283,9 @@ func roomPageRoute(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type GestureData struct {
|
||||
Url string
|
||||
Gesture rooms.HandGesture
|
||||
IsSelected bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user