Enha: split onto more templates
This commit is contained in:
@ -40,5 +40,42 @@ func HandleCreateRoom(w http.ResponseWriter, r *http.Request) {
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
tmpl.ExecuteTemplate(w, "main", nil)
|
||||
tmpl.ExecuteTemplate(w, "base", nil)
|
||||
}
|
||||
|
||||
func HandleRoomEnter(w http.ResponseWriter, r *http.Request) {
|
||||
// parse payload
|
||||
roomID := r.URL.Query().Get("id")
|
||||
if roomID == "" {
|
||||
// error
|
||||
return
|
||||
}
|
||||
// create a room
|
||||
room, err := getRoomByID(roomID)
|
||||
if err != nil {
|
||||
msg := "failed to find the room"
|
||||
log.Error(msg, "error", err, "room_id", roomID)
|
||||
abortWithError(w, msg)
|
||||
return
|
||||
}
|
||||
ctx := context.WithValue(r.Context(), "current_room", room.ID)
|
||||
ctx, err = updateRoomInSession(ctx, room.ID)
|
||||
if err != nil {
|
||||
msg := "failed to set current room to session"
|
||||
log.Error(msg, "error", err)
|
||||
abortWithError(w, msg)
|
||||
return
|
||||
}
|
||||
// send msg of created room
|
||||
// h.Broker.Notifier <- broker.NotificationEvent{
|
||||
// EventName: models.MsgRoomListUpdate,
|
||||
// Payload: fmt.Sprintf("%s created a room named %s", r.CreatorName, r.RoomName),
|
||||
// }
|
||||
// return html
|
||||
tmpl, err := template.ParseGlob("components/*.html")
|
||||
if err != nil {
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
tmpl.ExecuteTemplate(w, "base", room)
|
||||
}
|
||||
|
Reference in New Issue
Block a user