Skip to content

Commit

Permalink
feat: add sweetalert confirmation dialogs to delete actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarow committed Dec 28, 2023
1 parent 6db6a9f commit aefc485
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 13 deletions.
6 changes: 6 additions & 0 deletions static/sweetalert2.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions templates/base.templ
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ templ Base() {
<script src="/static/hyperscript.js"></script>
<script src="/static/sortable.js"></script>
<script src="/static/theme-change.js"></script>
<script src="/static/sweetalert2.js"></script>
</head>
<body id="content">
{ children... }
Expand Down
9 changes: 9 additions & 0 deletions templates/base_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion templates/components/create_game_form.templ
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ templ CreateGameForm(players []model.Player) {
@PlayerInput(players)
</div>
<div class="modal-action">
<button hx-post="/games" hx-target="closest body" hx-swap="outerHTML" class="btn">Submit</button>
<button hx-post="/games" hx-target="#content" class="btn">Submit</button>
<button class="btn">Cancel</button>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion templates/components/create_game_form_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion templates/components/edit_round_form.templ
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ templ EditRoundForm(game skat.Game, round skat.Round, roundIdx int) {
</div>
</div>
<div class="card-actions justify-end pt-5 modal-action">
<button hx-put={ fmt.Sprintf("/games/%v/rounds/%v", game.ID, round.ID) } hx-target="closest body" class="btn btn-primary">Submit</button>
<button hx-put={ fmt.Sprintf("/games/%v/rounds/%v", game.ID, round.ID) } hx-target="#content" class="btn btn-primary">Submit</button>
<button class="btn">Cancel</button>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion templates/components/edit_round_form_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion templates/components/game_card.templ
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,19 @@ templ GameCard(game skat.Game, detailsBtn, editBtn, deleteBtn bool) {
</button>
}
if deleteBtn {
<button class="btn" hx-delete={ fmt.Sprintf("/games/%v", game.ID) } hx-swap="outerHTML" hx-target="closest body">
<button
class="btn"
hx-delete={ fmt.Sprintf("/games/%v", game.ID) }
hx-target="#content"
hx-trigger="confirmed"
_="on click call Swal.fire({title: 'Are you sure?', text:'Deletion cannot be undone', icon: 'question', showCancelButton: true, width: 300})
if result.isConfirmed trigger confirmed"
>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0"></path>
</svg>
</button>
<div id="test" _="on confirmed log 'received event on div'"></div>
}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/components/game_card_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions templates/components/rounds_list.templ
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ templ RoundsList(game skat.Game) {
hx-target="#edit_round_form"
_="on htmx:afterSwap from #edit_round_form call edit_round_modal.showModal()"
>
<svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8 sm:w-6 sm:h-6 md:w-4 md:h-4" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8 m:w-5 sm:h-5" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10"></path>
</svg>
</a>
</li>
<li>
<a
hx-delete={ fmt.Sprintf("/games/%v/rounds/%v", game.ID, round.ID) }
hx-target="closest body"
hx-target="#content"
hx-trigger="confirmed"
_="on click call Swal.fire({title: 'Are you sure?', text:'Deletion cannot be undone', icon: 'question', showCancelButton: true, width: 300})
if result.isConfirmed trigger confirmed"
>
<svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8 sm:w-6 sm:h-6 md:w-4 md:h-4" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8 sm:w-5 sm:h-5 " fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0"></path>
</svg>
</a>
Expand Down Expand Up @@ -80,7 +83,7 @@ templ AddRoundForm(game skat.Game) {
<div class="card bg-base-200 shadow-xl">
<div class="card-body">
<h2 class="card-title">Round { fmt.Sprintf("%v", len(game.Rounds) + 1 ) }</h2>
<form hx-post={ fmt.Sprintf("/games/%v/rounds", game.ID) } hx-target="closest body">
<form hx-post={ fmt.Sprintf("/games/%v/rounds", game.ID) } hx-target="#content">
<div class="flex flex-row flex-wrap gap-2 pb-4">
for _, player := range game.Players {
<label class="form-control">
Expand Down
6 changes: 3 additions & 3 deletions templates/components/rounds_list_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aefc485

Please sign in to comment.