make chat.html self contained

jocadbz
Joca 2026-02-23 20:28:48 -03:00
parent d6fe1544e0
commit 13b0821eef
Signed by: jocadbz
GPG Key ID: B1836DCE2F50BDF7
2 changed files with 74 additions and 57 deletions

View File

@ -356,9 +356,8 @@ func main() {
log.Fatal("Error getting working directory:", err) log.Fatal("Error getting working directory:", err)
} }
// Parse base and partial templates // Parse partial templates
tmpl := template.Must(template.ParseFiles( tmpl := template.Must(template.ParseFiles(
filepath.Join(dir, "templates/base.html"),
filepath.Join(dir, "templates/partials/navbar.html"), filepath.Join(dir, "templates/partials/navbar.html"),
filepath.Join(dir, "templates/partials/cookie_banner.html"), filepath.Join(dir, "templates/partials/cookie_banner.html"),
)) ))

View File

@ -1,60 +1,78 @@
{{define "chat"}}{{template "base" .}}{{end}} {{define "chat"}}
<!DOCTYPE html>
{{define "chat-content"}} <html>
<div class="chat-container" data-board-id="{{.Board.ID}}" data-base-path="{{.BasePath}}" data-current-username="{{.CurrentUsername}}"> <head>
<div class="chat-breadcrumb"> <title>{{.Title}}</title>
<a href="{{.BasePath}}/">Home</a> <link rel="stylesheet" href="{{.StaticPath}}/style.css">
<span class="chat-breadcrumb-separator"></span> <script src="{{.StaticPath}}/validation.js" defer></script>
<a href="{{.BasePath}}/boards/">Boards</a> <script src="{{.StaticPath}}/drafts.js" defer></script>
<span class="chat-breadcrumb-separator"></span> <script src="{{.StaticPath}}/forms.js" defer></script>
<span>{{.Board.Name}}</span> <script src="{{.StaticPath}}/shortcuts.js" defer></script>
</div> <script src="{{.StaticPath}}/likes.js" defer></script>
<header class="chat-header"> <script src="{{.StaticPath}}/app.js" defer></script>
<div class="connection-status"> <script src="{{.StaticPath}}/chat.js" defer></script>
<div class="connection-dot connecting" id="connection-dot"></div> </head>
<span id="connection-text">Connecting...</span> <body class="chat-page">
</div> {{template "navbar" .}}
<h2>{{.Board.Name}}</h2> <main>
<p>{{.Board.Description}}</p> <div class="chat-container" data-board-id="{{.Board.ID}}" data-base-path="{{.BasePath}}" data-current-username="{{.CurrentUsername}}">
</header> <div class="chat-breadcrumb">
<div class="chat-messages" id="chat-messages"> <a href="{{.BasePath}}/">Home</a>
<div class="typing-indicator" id="typing-indicator"> <span class="chat-breadcrumb-separator"></span>
<span id="typing-users"></span><span class="typing-dots"><span>.</span><span>.</span><span>.</span></span> <a href="{{.BasePath}}/boards/">Boards</a>
</div> <span class="chat-breadcrumb-separator"></span>
{{range .Messages}} <span>{{.Board.Name}}</span>
<div class="chat-message{{if .Mentions}}{{range .Mentions}}{{if eq . $.CurrentUsername}} chat-message-highlighted{{end}}{{end}}{{end}}" id="msg-{{.ID}}" data-user="{{.Username}}" data-reply="{{.ReplyTo}}"> </div>
<div class="chat-message-header"> <header class="chat-header">
{{if .PfpFileID.Valid}} <div class="connection-status">
<img src="{{$.BasePath}}/file?id={{.PfpFileID.Int64}}" alt="PFP" class="chat-message-pfp"> <div class="connection-dot connecting" id="connection-dot"></div>
{{else}} <span id="connection-text">Connecting...</span>
<div class="chat-message-pfp" style="background-color: #001858;"></div> </div>
<h2>{{.Board.Name}}</h2>
<p>{{.Board.Description}}</p>
</header>
<div class="chat-messages" id="chat-messages">
<div class="typing-indicator" id="typing-indicator">
<span id="typing-users"></span><span class="typing-dots"><span>.</span><span>.</span><span>.</span></span>
</div>
{{range .Messages}}
<div class="chat-message{{if .Mentions}}{{range .Mentions}}{{if eq . $.CurrentUsername}} chat-message-highlighted{{end}}{{end}}{{end}}" id="msg-{{.ID}}" data-user="{{.Username}}" data-reply="{{.ReplyTo}}">
<div class="chat-message-header">
{{if .PfpFileID.Valid}}
<img src="{{$.BasePath}}/file?id={{.PfpFileID.Int64}}" alt="PFP" class="chat-message-pfp">
{{else}}
<div class="chat-message-pfp" style="background-color: #001858;"></div>
{{end}}
<span class="chat-message-username">{{.Username}}</span>
<span class="chat-message-timestamp">{{.Timestamp.Format "02/01/2006 15:04"}}</span>
</div>
{{if gt .ReplyTo 0}}
<div class="chat-message-reply" onclick="scrollToMessage({{.ReplyTo}})">Replying to message...</div>
{{end}}
<div class="chat-message-content">{{.Content}}</div>
<div class="post-actions">
<a href="javascript:void(0)" onclick="replyToMessage({{printf "%v" .ID}}, '{{.Username}}')">Reply</a>
</div>
</div>
{{end}} {{end}}
<span class="chat-message-username">{{.Username}}</span>
<span class="chat-message-timestamp">{{.Timestamp.Format "02/01/2006 15:04"}}</span>
</div> </div>
{{if gt .ReplyTo 0}} <button class="jump-to-bottom" id="jump-to-bottom" title="Jump to bottom" type="button">
<div class="chat-message-reply" onclick="scrollToMessage({{.ReplyTo}})">Replying to message...</div>
{{end}} <span class="unread-badge" id="unread-badge" style="display: none;">0</span>
<div class="chat-message-content">{{.Content}}</div> </button>
<div class="post-actions"> <div class="chat-input">
<a href="javascript:void(0)" onclick="replyToMessage({{printf "%v" .ID}}, '{{.Username}}')">Reply</a> <div id="reply-indicator" class="reply-indicator">
<span id="reply-username">Replying to </span>
<button onclick="cancelReply()" type="button">X</button>
</div>
<textarea id="chat-input-text" placeholder="Type a message..."></textarea>
<button onclick="sendMessage()" type="button">Send</button>
</div> </div>
</div> </div>
{{end}} <div id="autocomplete-popup" class="autocomplete-popup"></div>
</div> <script type="application/json" id="chat-usernames">{{.AllUsernames}}</script>
<button class="jump-to-bottom" id="jump-to-bottom" title="Jump to bottom" type="button"> </main>
{{template "cookie_banner" .}}
<span class="unread-badge" id="unread-badge" style="display: none;">0</span> </body>
</button> </html>
<div class="chat-input">
<div id="reply-indicator" class="reply-indicator">
<span id="reply-username">Replying to </span>
<button onclick="cancelReply()" type="button">X</button>
</div>
<textarea id="chat-input-text" placeholder="Type a message..."></textarea>
<button onclick="sendMessage()" type="button">Send</button>
</div>
</div>
<div id="autocomplete-popup" class="autocomplete-popup"></div>
<script type="application/json" id="chat-usernames">{{.AllUsernames}}</script>
{{end}} {{end}}