[O] Show confirm dialog when unlinking a card

This commit is contained in:
Azalea
2024-02-22 19:06:18 -05:00
parent 50029fbb24
commit 5597bf5d1e
4 changed files with 46 additions and 20 deletions

View File

@@ -79,8 +79,10 @@ button:focus, button:focus-visible
button.error button.error
color: unset color: unset
&:hover &:hover
background: $c-error border-color: $c-error
border-color: transparent color: $c-error
//background: $c-error
//border-color: transparent
button.icon button.icon
padding: 0.6em padding: 0.6em

View File

@@ -2,13 +2,8 @@
<script lang="ts"> <script lang="ts">
import { fade } from 'svelte/transition' import { fade } from 'svelte/transition'
import { clz } from "../libs/ui";
interface ConfirmProps { import type { ConfirmProps } from "../libs/generalTypes";
title: string
message: string
confirm: () => void
cancel?: () => void
}
// Props // Props
export let show: ConfirmProps export let show: ConfirmProps
@@ -16,19 +11,26 @@
{#if show} {#if show}
<div class="overlay" transition:fade> <div class="overlay" transition:fade>
<h1>{show.title}</h1> <div>
<span>{show.message}</span> <h2>{show.title}</h2>
<span>{show.message}</span>
<div class="actions"> <div class="actions">
{#if show.cancel} {#if show.cancel}
<!-- Svelte LSP is very annoying here --> <!-- Svelte LSP is very annoying here -->
<button on:click={() => show.cancel && show.cancel()}>Cancel</button> <button on:click={() => show.cancel && show.cancel()}>Cancel</button>
{/if} {/if}
<button on:click={() => show.confirm()}>Confirm</button> <button on:click={() => show.confirm()} class={clz({error: show.dangerous})}>Confirm</button>
</div>
</div> </div>
</div> </div>
{/if} {/if}
<style lang="sass"> <style lang="sass">
.actions
display: flex
gap: 16px
button
width: 100%
</style> </style>

View File

@@ -41,3 +41,12 @@ export interface CardSummary {
ongeki: CardSummaryGame | null ongeki: CardSummaryGame | null
diva: CardSummaryGame | null diva: CardSummaryGame | null
} }
export interface ConfirmProps {
title: string
message: string
confirm: () => void
cancel?: () => void
dangerous?: boolean
}

View File

@@ -3,13 +3,15 @@
<script lang="ts"> <script lang="ts">
import { slide, fade } from "svelte/transition" import { slide, fade } from "svelte/transition"
import { clz } from "../../libs/ui"; import { clz } from "../../libs/ui";
import type { Card, CardSummary, CardSummaryGame, UserMe } from "../../libs/generalTypes"; import type { Card, CardSummary, CardSummaryGame, ConfirmProps, UserMe } from "../../libs/generalTypes";
import { CARD, USER } from "../../libs/sdk"; import { CARD, USER } from "../../libs/sdk";
import moment from "moment" import moment from "moment"
import Icon from "@iconify/svelte"; import Icon from "@iconify/svelte";
import Confirm from "../../components/Confirm.svelte";
// State // State
let state: 'ready' | 'linking-AC' | 'linking-SN' | 'loading' = "loading" let state: 'ready' | 'linking-AC' | 'linking-SN' | 'loading' = "loading"
let showConfirm: ConfirmProps | null = null
let error: string = "" let error: string = ""
let me: UserMe | null = null let me: UserMe | null = null
@@ -141,8 +143,17 @@
} }
async function unlink(card: Card) { async function unlink(card: Card) {
await CARD.unlink(card.luid) showConfirm = {
await updateMe() title: "Unlink Card",
message: "Are you sure you want to unlink this card?",
confirm: async () => {
await CARD.unlink(card.luid)
await updateMe()
showConfirm = null
},
cancel: () => showConfirm = null,
dangerous: true
}
} }
// Access code input // Access code input
@@ -298,6 +309,8 @@
</div> </div>
</div> </div>
{/if} {/if}
<Confirm show={showConfirm} />
</div> </div>
<style lang="sass"> <style lang="sass">