Skip to content

Commit

Permalink
Changing the navbar to be a template instead of rewritten
Browse files Browse the repository at this point in the history
  • Loading branch information
COMTOP1 committed Mar 4, 2024
1 parent 3096318 commit bf5beef
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 167 deletions.
3 changes: 2 additions & 1 deletion server/templates/_base.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<p style="margin-bottom: 10px;">Dark Mode</p>
</div>
<br><br>
{{block "content" .}}{{end}}
{{template "_navbar" .}}
{{template "content" .}}
<br><br>
{{ $year := thisYear }}
<footer id="footer">Streamer (version: {{ getVersion }}) - created by Liam Burnand 2022{{if ne $year 2022}}-{{ $year }}{{end}}</footer>
Expand Down
32 changes: 32 additions & 0 deletions server/templates/_navbar.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{define "_navbar"}}
{{ $page := .ActivePage }}
<div class="tabs is-toggle is-toggle-rounded">
<ul>
<li {{if eq $page "home"}}class="is-active"{{end}}>
<a href="/">
<span>Home</span>
</a>
</li>
<li {{if eq $page "resume"}}class="is-active"{{end}}>
<a href="/resume">
<span>Resume</span>
</a>
</li>
<li {{if eq $page "list"}}class="is-active"{{end}}>
<a href="/list">
<span>List</span>
</a>
</li>
<li {{if eq $page "save"}}class="is-active"{{end}}>
<a href="/save">
<span>Save</span>
</a>
</li>
<li {{if eq $page "recall"}}class="is-active"{{end}}>
<a href="/recall">
<span>Recall</span>
</a>
</li>
</ul>
</div>
{{end}}
29 changes: 0 additions & 29 deletions server/templates/list.tmpl
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
{{define "content"}}
<div class="tabs is-toggle is-toggle-rounded">
<ul>
<li>
<a href="/">
<span>Home</span>
</a>
</li>
<li>
<a href="/resume">
<span>Resume</span>
</a>
</li>
<li class="is-active">
<a href="/list">
<span>List</span>
</a>
</li>
<li>
<a href="/save">
<span>Save</span>
</a>
</li>
<li>
<a href="/recall">
<span>Recall</span>
</a>
</li>
</ul>
</div>
<div class="card" id="enter">
<div class="card-content">
<p class="title">Listing all streams, active and saved</p>
Expand Down
29 changes: 0 additions & 29 deletions server/templates/main.tmpl
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
{{define "content"}}
<div class="tabs is-toggle is-toggle-rounded">
<ul>
<li class="is-active">
<a href="/">
<span>Home</span>
</a>
</li>
<li>
<a href="/resume">
<span>Resume</span>
</a>
</li>
<li>
<a href="/list">
<span>List</span>
</a>
</li>
<li>
<a href="/save">
<span>Save</span>
</a>
</li>
<li>
<a href="/recall">
<span>Recall</span>
</a>
</li>
</ul>
</div>
<div id="start_window">
<div class="card">
<div class="card-content">
Expand Down
29 changes: 0 additions & 29 deletions server/templates/recall.tmpl
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
{{define "content"}}
<div class="tabs is-toggle is-toggle-rounded">
<ul>
<li>
<a href="/">
<span>Home</span>
</a>
</li>
<li>
<a href="/resume">
<span>Resume</span>
</a>
</li>
<li>
<a href="/list">
<span>List</span>
</a>
</li>
<li>
<a href="/save">
<span>Save</span>
</a>
</li>
<li class="is-active">
<a href="/recall">
<span>Recall</span>
</a>
</li>
</ul>
</div>
<div class="card" id="recall_stream_window">
<div class="card-content">
<p class="title">Recall a stream</p><br>
Expand Down
29 changes: 0 additions & 29 deletions server/templates/resume.tmpl
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
{{define "content"}}
<div class="tabs is-toggle is-toggle-rounded">
<ul>
<li>
<a href="/">
<span>Home</span>
</a>
</li>
<li class="is-active">
<a href="/resume">
<span>Resume</span>
</a>
</li>
<li>
<a href="/list">
<span>List</span>
</a>
</li>
<li>
<a href="/save">
<span>Save</span>
</a>
</li>
<li>
<a href="/recall">
<span>Recall</span>
</a>
</li>
</ul>
</div>
<div class="card" id="enter_window">
<div class="card-content">
<p class="title">Resume a stream</p><br>
Expand Down
29 changes: 0 additions & 29 deletions server/templates/save.tmpl
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
{{define "content"}}
<div class="tabs is-toggle is-toggle-rounded">
<ul>
<li>
<a href="/">
<span>Home</span>
</a>
</li>
<li>
<a href="/resume">
<span>Resume</span>
</a>
</li>
<li>
<a href="/list">
<span>List</span>
</a>
</li>
<li class="is-active">
<a href="/save">
<span>Save</span>
</a>
</li>
<li>
<a href="/recall">
<span>Recall</span>
</a>
</li>
</ul>
</div>
<div id="save_window">
<div class="card">
<div class="card-content">
Expand Down
21 changes: 11 additions & 10 deletions server/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
ErrorTemplate Template = "error.tmpl"
NotFound404Template Template = "404NotFound.tmpl"
baseTemplate Template = "_base.tmpl"
navbarTemplate Template = "_navbar.tmpl"
statusComponentsTemplate Template = "_statusComponents.tmpl"
stopComponentsTemplate Template = "_stopComponents.tmpl"
)
Expand All @@ -50,7 +51,7 @@ func (t *Templater) RenderTemplate(w io.Writer, data interface{}, mainTmpl Templ

t1.Funcs(t.getFuncMaps())

t1, err = t1.ParseFS(tmpls, baseTemplate.String(), statusComponentsTemplate.String(), stopComponentsTemplate.String(), mainTmpl.String())
t1, err = t1.ParseFS(tmpls, baseTemplate.String(), navbarTemplate.String(), statusComponentsTemplate.String(), stopComponentsTemplate.String(), mainTmpl.String())

if err != nil {
log.Printf("failed to get templates for template(RenderTemplate): %+v", err)
Expand All @@ -74,15 +75,15 @@ func (t *Templater) getFuncMaps() template.FuncMap {
// This section is for go template linter
var (
AllTemplates = [][]string{
{"facebookHelp.tmpl", "_base.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"list.tmpl", "_base.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"main.tmpl", "_base.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"recall.tmpl", "_base.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"resume.tmpl", "_base.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"save.tmpl", "_base.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"youtubeHelp.tmpl", "_base.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"error.tmpl", "_base.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"404NotFound.tmpl", "_base.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"facebookHelp.tmpl", "_base.tmpl", "_navbar.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"list.tmpl", "_base.tmpl", "_navbar.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"main.tmpl", "_base.tmpl", "_navbar.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"recall.tmpl", "_base.tmpl", "_navbar.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"resume.tmpl", "_base.tmpl", "_navbar.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"save.tmpl", "_base.tmpl", "_navbar.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"youtubeHelp.tmpl", "_base.tmpl", "_navbar.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"error.tmpl", "_base.tmpl", "_navbar.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
{"404NotFound.tmpl", "_base.tmpl", "_navbar.tmpl", "_statusComponents.tmpl", "_stopComponents.tmpl"},
}

_ = AllTemplates
Expand Down
11 changes: 8 additions & 3 deletions server/views/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func (v *Views) CustomHTTPErrorHandler(err error, c echo.Context) {
}
c.Response().WriteHeader(status)
var data struct {
Code int
Error any
ActivePage string
Code int
Error any
}
if he == nil {
data.Error = err
Expand All @@ -35,5 +36,9 @@ func (v *Views) CustomHTTPErrorHandler(err error, c echo.Context) {
}

func (v *Views) Error404(c echo.Context) error {
return v.template.RenderTemplate(c.Response().Writer, nil, templates.NotFound404Template)
data := struct {
ActivePage string
}{}

return v.template.RenderTemplate(c.Response().Writer, data, templates.NotFound404Template)
}
6 changes: 5 additions & 1 deletion server/views/facebookHelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ func (v *Views) FacebookHelpFunc(c echo.Context) error {
log.Println("facebook called")
}

return v.template.RenderTemplate(c.Response().Writer, nil, templates.FacebookHelpTemplate)
data := struct {
ActivePage string
}{}

return v.template.RenderTemplate(c.Response().Writer, data, templates.FacebookHelpTemplate)
}
6 changes: 4 additions & 2 deletions server/views/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ func (v *Views) HomeFunc(c echo.Context) error {
}

data := struct {
Error string
ActivePage string
Error string
}{
Error: err,
ActivePage: "home",
Error: err,
}

return v.template.RenderTemplate(c.Response().Writer, data, templates.MainTemplate)
Expand Down
8 changes: 7 additions & 1 deletion server/views/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ func (v *Views) ListFunc(c echo.Context) error {
log.Println("List GET called")
}

return v.template.RenderTemplate(c.Response().Writer, nil, templates.ListTemplate)
data := struct {
ActivePage string
}{
ActivePage: "list",
}

return v.template.RenderTemplate(c.Response().Writer, data, templates.ListTemplate)
} else if c.Request().Method == "POST" {
if v.conf.Verbose {
log.Println("List POST called")
Expand Down
8 changes: 7 additions & 1 deletion server/views/recall.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ func (v *Views) RecallFunc(c echo.Context) error {
log.Println("Recall GET called")
}

return v.template.RenderTemplate(c.Response().Writer, nil, templates.RecallTemplate)
data := struct {
ActivePage string
}{
ActivePage: "recall",
}

return v.template.RenderTemplate(c.Response().Writer, data, templates.RecallTemplate)
} else if c.Request().Method == "POST" {
if v.conf.Verbose {
log.Println("Recall POST called")
Expand Down
8 changes: 7 additions & 1 deletion server/views/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ func (v *Views) ResumeFunc(c echo.Context) error {
log.Println("Resume GET called")
}

return v.template.RenderTemplate(c.Response().Writer, nil, templates.ResumeTemplate)
data := struct {
ActivePage string
}{
ActivePage: "resume",
}

return v.template.RenderTemplate(c.Response().Writer, data, templates.ResumeTemplate)
} else if c.Request().Method == "POST" {
if v.conf.Verbose {
log.Println("Resume POST called")
Expand Down
8 changes: 7 additions & 1 deletion server/views/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ func (v *Views) SaveFunc(c echo.Context) error {
log.Println("Save GET called")
}

return v.template.RenderTemplate(c.Response().Writer, nil, templates.SaveTemplate)
data := struct {
ActivePage string
}{
ActivePage: "save",
}

return v.template.RenderTemplate(c.Response().Writer, data, templates.SaveTemplate)
} else if c.Request().Method == "POST" {
if v.conf.Verbose {
log.Println("Save POST called")
Expand Down
6 changes: 5 additions & 1 deletion server/views/youtubeHelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ func (v *Views) YoutubeHelpFunc(c echo.Context) error {
log.Println("YouTube called")
}

return v.template.RenderTemplate(c.Response().Writer, nil, templates.YouTubeHelpTemplate)
data := struct {
ActivePage string
}{}

return v.template.RenderTemplate(c.Response().Writer, data, templates.YouTubeHelpTemplate)
}

0 comments on commit bf5beef

Please sign in to comment.