refactor(console): Fragmentize sidebar and co-locate scripts with templates#52
Merged
refactor(console): Fragmentize sidebar and co-locate scripts with templates#52
Conversation
… fragment
Move preview content generation from client-side JavaScript DOM
construction to a server-side Go template (buckets/preview.html).
The new GET /buckets/{name}/preview/{object...} endpoint returns an
HTML fragment with the appropriate media element and metadata table,
loaded via htmx.ajax(). This removes ~50 lines of JS (formatBytes,
escapeHtml, file-type classification, fetch-based DOM building) while
keeping client-only concerns (modal show/hide, view toggle, gallery
lazy load) in JavaScript.
dbe1ba6 to
07289ab
Compare
…-page reloads
Extract the sidebar bucket list and empty state into reusable
sub-templates (buckets/list.html, empty.html) included via
{{template}} in index.html.
- handleCreateBucket now returns the list fragment directly instead
of redirecting to /, so the sidebar updates in-place via htmx.
- handleDeleteBucket returns the list fragment plus an OOB swap that
resets #main-content to the empty state.
- handleObjects no longer renders index.html for non-htmx requests;
it redirects to / instead, removing the duplicated Buckets.Names()
call and the Buckets field from the objects data struct.
Move fragment-owned scripts into {{define "scripts:<name>"}} blocks
inside each template file. A new GET /scripts endpoint renders all
registered script blocks once at page load via hx-trigger="load".
This keeps scripts co-located with their HTML while preventing
re-execution on htmx swaps.
RegisterTemplateWithScripts registers both the template and its
scripts block in one call, eliminating dual-maintenance.
07289ab to
aca8cd8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
buckets/list.html,empty.html), included via{{template}}inindex.html.{{define "scripts:<name>"}}convention that keeps JavaScript co-located with its template file while preventing re-execution on htmx swaps. A newGET /scriptsendpoint renders all registered script blocks once at page load.RegisterTemplateWithScriptsto register both a template and its scripts block in one call.Changes
Sidebar fragmentization
handleCreateBucketreturns the list fragment directly (was:302 → /).handleDeleteBucketreturns the list fragment + OOB swap to reset#main-content(was:HX-Redirect: /).handleObjectsredirects non-htmx requests to/instead of duplicatingBuckets.Names()+index.htmlrender.Script co-location pattern
openPreview,setViewMode,initGalleryView, …) moved fromindex.htmlinto a{{define "scripts:buckets/objects"}}block at the bottom ofobjects.html.index.htmlloads them once via<div hx-get="/scripts" hx-trigger="load">.htmx:afterSettlelistener stays inindex.html(layout) to avoid duplicate registration.Test plan
go test ./...passesgolangci-lint run ./...clean