Skip to content

Commit

Permalink
WIP Adding HTMX for a bit of excitement
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Balogh <[email protected]>
  • Loading branch information
javaducky committed May 22, 2024
1 parent 0570d9e commit 863208c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/server/assets/htmx.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions internal/server/assets/wee-stylee.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tr.htmx-swapping td {
opacity: 0;
transition: opacity 1s ease-out;
}
2 changes: 2 additions & 0 deletions internal/server/views/layout.templ
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ templ Layout(content templ.Component) {
<title>WeeSVC - A Tiny Server</title>
<link href="/assets/dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="/assets/dist/js/bootstrap.min.js"></script>
<script src="/assets/htmx.min.js"></script>
<link href="/assets/wee-stylee.css" rel="stylesheet" />
</head>
<body>
@navbar()
Expand Down
23 changes: 22 additions & 1 deletion internal/server/views/places.templ
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ templ Places(places []*model.Place) {
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tbody hx-confirm="Are you sure?" hx-target="closest tr" hx-swap="outerHTML swap:1s">
for _, place := range places {
<tr>
<th scope="row">{ fmt.Sprintf("%d", place.ID) }</th>
Expand All @@ -28,6 +28,27 @@ templ Places(places []*model.Place) {
<td>{ fmt.Sprintf("%f", place.Longitude) }</td>
<td>
<a class="btn btn-dark" href={ templ.URL(fmt.Sprintf("https://google.com/search?q=%f,%f", place.Latitude, place.Longitude)) } target="_blank">Visit</a>
<button class="btn btn-danger" hx-delete={ fmt.Sprintf("/api/places/%d", place.ID) }>Delete</button>
<button class="btn btn-danger"
hx-get={ fmt.Sprintf("/api/places/%d", place.ID) }
hx-trigger="edit"
onClick="let editing = document.querySelector('.editing')
if(editing) {
Swal.fire({title: 'Already Editing',
showCancelButton: true,
confirmButtonText: 'Yep, Edit This Row!',
text:'Hey! You are already editing a row! Do you want to cancel that edit and continue?'})
.then((result) => {
if(result.isConfirmed) {
htmx.trigger(editing, 'cancel')
htmx.trigger(this, 'edit')
}
})
} else {
htmx.trigger(this, 'edit')
}">
Edit
</button>
</td>
</tr>
}
Expand Down

0 comments on commit 863208c

Please sign in to comment.