Skip to content

Commit

Permalink
website: remove templates.Site from public website
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie committed Feb 6, 2024
1 parent 13cc132 commit c3ed134
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 24 deletions.
13 changes: 6 additions & 7 deletions website/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,12 @@ func Execute(ctx context.Context, cfg config.Config) error {

// public routes
r.Route("/", public.Route(ctx, public.State{
Config: cfg,
Daypass: dpass,
Templates: siteTemplates,
TemplateExecutor: siteTemplates.Executor(),
Manager: manager,
Streamer: streamer,
Storage: storage,
Config: cfg,
Daypass: dpass,
Templates: siteTemplates.Executor(),
Manager: manager,
Streamer: streamer,
Storage: storage,
}))

// setup the http server
Expand Down
2 changes: 1 addition & 1 deletion website/public/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewChatInput(r *http.Request) ChatInput {
func (s State) GetChat(w http.ResponseWriter, r *http.Request) {
input := NewChatInput(r)

err := s.TemplateExecutor.Execute(w, r, input)
err := s.Templates.Execute(w, r, input)
if err != nil {
s.errorHandler(w, r, err)
return
Expand Down
2 changes: 1 addition & 1 deletion website/public/faves.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewFavesInput(r *http.Request) FavesInput {
func (s State) GetFaves(w http.ResponseWriter, r *http.Request) {
input := NewFavesInput(r)

err := s.TemplateExecutor.Execute(w, r, input)
err := s.Templates.Execute(w, r, input)
if err != nil {
s.errorHandler(w, r, err)
return
Expand Down
2 changes: 1 addition & 1 deletion website/public/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ func (s State) getHome(w http.ResponseWriter, r *http.Request) error {
}
input.News = news.Entries

return s.TemplateExecutor.Execute(w, r, input)
return s.Templates.Execute(w, r, input)
}
2 changes: 1 addition & 1 deletion website/public/lastplayed.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s State) getLastPlayed(w http.ResponseWriter, r *http.Request) error {
return err
}

return s.TemplateExecutor.Execute(w, r, input)
return s.Templates.Execute(w, r, input)
}

func (s State) GetLastPlayed(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion website/public/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s State) GetNews(w http.ResponseWriter, r *http.Request) {
return
}

err = s.TemplateExecutor.Execute(w, r, input)
err = s.Templates.Execute(w, r, input)
if err != nil {
s.errorHandler(w, r, err)
return
Expand Down
2 changes: 1 addition & 1 deletion website/public/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s State) getQueue(w http.ResponseWriter, r *http.Request) error {
return err
}

return s.TemplateExecutor.Execute(w, r, input)
return s.Templates.Execute(w, r, input)
}

func (s State) GetQueue(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion website/public/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func (s State) getSchedule(w http.ResponseWriter, r *http.Request) error {

input := NewScheduleInput(r)

return s.TemplateExecutor.Execute(w, r, input)
return s.Templates.Execute(w, r, input)
}
2 changes: 1 addition & 1 deletion website/public/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (SearchInput) TemplateBundle() string {
func (s State) GetSearch(w http.ResponseWriter, r *http.Request) {
input := NewSearchInput(r)

err := s.TemplateExecutor.Execute(w, r, input)
err := s.Templates.Execute(w, r, input)
if err != nil {
s.errorHandler(w, r, err)
return
Expand Down
2 changes: 1 addition & 1 deletion website/public/staff.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (StaffInput) TemplateBundle() string {
func (s State) GetStaff(w http.ResponseWriter, r *http.Request) {
input := NewStaffInput(r)

err := s.TemplateExecutor.Execute(w, r, input)
err := s.Templates.Execute(w, r, input)
if err != nil {
s.errorHandler(w, r, err)
return
Expand Down
11 changes: 5 additions & 6 deletions website/public/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ const theme = "default"
type State struct {
config.Config

Daypass *daypass.Daypass
Templates *templates.Site
TemplateExecutor templates.Executor
Manager radio.ManagerService
Streamer radio.StreamerService
Storage radio.StorageService
Daypass *daypass.Daypass
Templates templates.Executor
Manager radio.ManagerService
Streamer radio.StreamerService
Storage radio.StorageService
}

func (s *State) errorHandler(w http.ResponseWriter, r *http.Request, err error) {
Expand Down
4 changes: 2 additions & 2 deletions website/public/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ func (s State) getSubmit(w http.ResponseWriter, r *http.Request, form *Submissio
return errors.E(op, err)
}

return s.TemplateExecutor.Execute(w, r, input)
return s.Templates.Execute(w, r, input)
}

func (s State) PostSubmit(w http.ResponseWriter, r *http.Request) {
// setup response function that differs between htmx/non-htmx request
responseFn := func(form SubmissionForm) {
var err error
if IsHTMX(r) {
err = s.TemplateExecutor.Execute(w, r, form)
err = s.Templates.Execute(w, r, form)
} else {
err = s.getSubmit(w, r, &form)
}
Expand Down

0 comments on commit c3ed134

Please sign in to comment.