updated nav

This commit is contained in:
2025-12-30 11:37:29 -07:00
parent 76fade5cdc
commit 493d15eae8
10 changed files with 108 additions and 19 deletions
+17
View File
@@ -1,9 +1,11 @@
package site package site
import ( import (
"errors"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"os"
"path" "path"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -51,6 +53,14 @@ func (s *Server) serveTemplates(w http.ResponseWriter, r *http.Request) {
acct, acct,
) )
if err != nil { if err != nil {
// TODO: handle 401
// TODO: handle 403
// TODO: handle 404
if isFileNotFoundError(err) {
}
// TODO: handle 'not found' as a 404? // TODO: handle 'not found' as a 404?
fmt.Println("[ERROR]: failed to load or parse layout template:", err) fmt.Println("[ERROR]: failed to load or parse layout template:", err)
http.Redirect(w, r, "/", http.StatusTemporaryRedirect) http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
@@ -60,6 +70,13 @@ func (s *Server) serveTemplates(w http.ResponseWriter, r *http.Request) {
w.Write(b) w.Write(b)
} }
func isFileNotFoundError(err error) bool {
var pe *os.PathError
isPathErr := errors.As(err, &pe)
return isPathErr && pe.Err != nil && pe.Err.Error() == "no such file or directory"
}
// TODO: clean this up... // TODO: clean this up...
// TODO: somehow tell what the path params are and pass them up. // TODO: somehow tell what the path params are and pass them up.
// - then consider pushing this functionality into the template library. // - then consider pushing this functionality into the template library.
@@ -1,3 +1,5 @@
{{/* TODO: delete, once not needed */}}
{{/* "dot" . */}} {{/* "dot" . */}}
<nav> <nav>
+87 -1
View File
@@ -16,8 +16,94 @@
{{- block "head" . }}{{ end }} {{- block "head" . }}{{ end }}
</head> </head>
<body> <body style="margin: 0; padding: 0;">
<header style="margin: 0; padding: 0;">
<nav
style="
margin: 0;
padding: 1em;
background-color: #bdf;
font-size: 1.25em;
display: flex;
flex-direction: column;
align-items: center;
"
>
<ul>
<li>
<a href="/">
Home
</a>
</li>
{{- if .UserID }}
<li>
<a href="/accounts/{{.Account.ID}}">
Account
</a>
</li>
<li>
<a href="/accounts/{{.Account.ID}}/reports">
Reports
</a>
</li>
<li>
<a href="/accounts/{{.Account.ID}}/inventory">
Inventory
</a>
</li>
<li>
<a href="/logout">
Log Out
</a>
</li>
{{- else }}
<li>
<a href="/login">
Log In / Sign Up
</a>
</li>
{{- end }}
</ul>
</nav>
</header>
<main style="margin: 0; padding: 1em;">
{{/* This is where the page_body template will be inserted into the page */}} {{/* This is where the page_body template will be inserted into the page */}}
{{- block "body" . }}{{ end }} {{- block "body" . }}{{ end }}
</main>
<footer
style="
margin: 0;
padding: 2em;
background-color: #bdf;
display: flex;
flex-direction: column;
align-items: center;
"
>
<address
style="
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5em;
"
>
<a href="mailto:contact-us@inventory-plus-plus.com">Contact Us</a>
<a href="mailto:support@inventory-plus-plus.com">Support</a>
</address>
</footer>
</body> </body>
</html> </html>
@@ -1,7 +1,5 @@
{{- define "title" }} Inventory++ Create an Account {{ end }} {{- define "title" }} Inventory++ Create an Account {{ end }}
{{- componentBody "nav_bar" "dot" . }}
{{/* TODO: will need to verify the email address */}} {{/* TODO: will need to verify the email address */}}
<section style="margin-top: 2em;"> <section style="margin-top: 2em;">
@@ -1,8 +1,5 @@
{{- define "title" }} Inventory++ Account {{ end }} {{- define "title" }} Inventory++ Account {{ end }}
{{- componentBody "nav_bar" "dot" . }}
<h1>Account: {{ .Account.Email }}</h1> <h1>Account: {{ .Account.Email }}</h1>
{{- $etsyUser := .Etsy.GetUserPointerByAccountID .Account.ID }} {{- $etsyUser := .Etsy.GetUserPointerByAccountID .Account.ID }}
@@ -1,6 +1,3 @@
{{- define "title" }} Inventory++ {{ end }} {{- define "title" }} Inventory++ {{ end }}
{{ componentBody "nav_bar" "dot" . }}
<h1>Inventory management page: WIP</h1> <h1>Inventory management page: WIP</h1>
@@ -1,7 +1,5 @@
{{- define "title" }} Inventory++ Reports {{ end }} {{- define "title" }} Inventory++ Reports {{ end }}
{{ componentBody "nav_bar" "dot" . }}
{{ $storeID := .Request.URL.Query.Get "store-id" }} {{ $storeID := .Request.URL.Query.Get "store-id" }}
<h1>Reports</h1> <h1>Reports</h1>
@@ -1,5 +1,3 @@
{{ componentBody "nav_bar" "dot" . }}
<h1>Home</h1> <h1>Home</h1>
{{- if and .UserID (not .Account.ID) }} {{- if and .UserID (not .Account.ID) }}
@@ -1,7 +1,5 @@
{{/* TODO: delete this page, when certain it's not wanted anymore */}} {{/* TODO: delete this page, when certain it's not wanted anymore */}}
{{ componentBody "nav_bar" "dot" . }}
<h1>Log In</h1> <h1>Log In</h1>
<form action="login" method="post"> <form action="login" method="post">
@@ -1,7 +1,5 @@
{{/* TODO: not used - read for deletion */}} {{/* TODO: not used - read for deletion */}}
{{ componentBody "nav_bar" "dot" . }}
<h1>Sign Up</h1> <h1>Sign Up</h1>
<form action="accounts" method="post"> <form action="accounts" method="post">