|
| 1 | +<script> |
| 2 | + import { updateAvailable, updateDismissed, applyUpdate } from '../lib/updateAvailable.js' |
| 3 | + import { timerState } from '../lib/stores.js' |
| 4 | + import { t } from '../lib/i18n.js' |
| 5 | +
|
| 6 | + let visible = $derived($updateAvailable && !$updateDismissed) |
| 7 | + let panelEl = $state(null) |
| 8 | + let matchInProgress = $derived( |
| 9 | + $timerState?.phase === 'loading' || $timerState?.phase === 'shooting' |
| 10 | + ) |
| 11 | +
|
| 12 | + function dismiss() { |
| 13 | + updateDismissed.set(true) |
| 14 | + } |
| 15 | +
|
| 16 | + function reload() { |
| 17 | + applyUpdate() |
| 18 | + } |
| 19 | +
|
| 20 | + $effect(() => { |
| 21 | + if (!visible) return |
| 22 | + const previouslyFocused = document.activeElement |
| 23 | + panelEl?.focus() |
| 24 | + function onKey(e) { if (e.key === 'Escape') dismiss() } |
| 25 | + document.addEventListener('keydown', onKey) |
| 26 | + return () => { |
| 27 | + document.removeEventListener('keydown', onKey) |
| 28 | + if (previouslyFocused instanceof HTMLElement) previouslyFocused.focus() |
| 29 | + } |
| 30 | + }) |
| 31 | +</script> |
| 32 | +
|
| 33 | +{#if visible} |
| 34 | + <div class="modal-backdrop" role="presentation" onclick={dismiss}> |
| 35 | + <!-- svelte-ignore a11y_click_events_have_key_events --> |
| 36 | + <div |
| 37 | + class="modal-panel" |
| 38 | + role="dialog" |
| 39 | + aria-modal="true" |
| 40 | + aria-labelledby="update-modal-title" |
| 41 | + tabindex="-1" |
| 42 | + bind:this={panelEl} |
| 43 | + onclick={(e) => e.stopPropagation()} |
| 44 | + > |
| 45 | + <div class="modal-header"> |
| 46 | + <h2 id="update-modal-title" class="modal-title">{$t('updateAvailable')}</h2> |
| 47 | + </div> |
| 48 | +
|
| 49 | + <p class="modal-body">{$t('updateAvailableBody')}</p> |
| 50 | +
|
| 51 | + {#if matchInProgress} |
| 52 | + <p class="modal-warning">{$t('reloadDuringMatchWarning')}</p> |
| 53 | + {/if} |
| 54 | +
|
| 55 | + <div class="modal-actions"> |
| 56 | + <button class="btn-secondary" onclick={dismiss}>{$t('later')}</button> |
| 57 | + <button class="btn-primary" onclick={reload}>{$t('reloadNow')}</button> |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | +{/if} |
| 62 | +
|
| 63 | +<style> |
| 64 | + .modal-backdrop { |
| 65 | + position: fixed; |
| 66 | + inset: 0; |
| 67 | + z-index: 300; |
| 68 | + background: rgba(0, 0, 0, 0.6); |
| 69 | + display: flex; |
| 70 | + align-items: center; |
| 71 | + justify-content: center; |
| 72 | + } |
| 73 | +
|
| 74 | + .modal-panel { |
| 75 | + background: var(--bg-secondary); |
| 76 | + border: 1px solid rgba(255, 255, 255, 0.08); |
| 77 | + border-radius: var(--radius-lg, var(--radius)); |
| 78 | + padding: 1.25rem; |
| 79 | + width: min(90vw, 420px); |
| 80 | + display: flex; |
| 81 | + flex-direction: column; |
| 82 | + gap: 0.75rem; |
| 83 | + } |
| 84 | +
|
| 85 | + .modal-header { |
| 86 | + display: flex; |
| 87 | + align-items: center; |
| 88 | + gap: 0.5rem; |
| 89 | + } |
| 90 | +
|
| 91 | + .modal-title { |
| 92 | + font-size: 1rem; |
| 93 | + font-weight: 700; |
| 94 | + color: var(--text-primary); |
| 95 | + margin: 0; |
| 96 | + letter-spacing: 0.04em; |
| 97 | + } |
| 98 | +
|
| 99 | + .modal-body { |
| 100 | + margin: 0; |
| 101 | + font-size: 0.9rem; |
| 102 | + color: var(--text-secondary); |
| 103 | + line-height: 1.45; |
| 104 | + } |
| 105 | +
|
| 106 | + .modal-warning { |
| 107 | + margin: 0; |
| 108 | + padding: 0.6rem 0.75rem; |
| 109 | + font-size: 0.82rem; |
| 110 | + color: var(--warning); |
| 111 | + background: rgba(255, 181, 71, 0.12); |
| 112 | + border: 1px solid rgba(255, 181, 71, 0.3); |
| 113 | + border-radius: var(--radius); |
| 114 | + line-height: 1.4; |
| 115 | + } |
| 116 | +
|
| 117 | + .modal-actions { |
| 118 | + display: flex; |
| 119 | + justify-content: flex-end; |
| 120 | + gap: 0.5rem; |
| 121 | + } |
| 122 | +
|
| 123 | + .btn-primary { |
| 124 | + padding: 0.5rem 1rem; |
| 125 | + font-size: 0.85rem; |
| 126 | + font-weight: 700; |
| 127 | + background: var(--accent); |
| 128 | + color: var(--bg-primary); |
| 129 | + border: none; |
| 130 | + border-radius: var(--radius); |
| 131 | + letter-spacing: 0.04em; |
| 132 | + } |
| 133 | +
|
| 134 | + .btn-primary:hover { |
| 135 | + filter: brightness(1.1); |
| 136 | + } |
| 137 | +
|
| 138 | + .btn-secondary { |
| 139 | + padding: 0.5rem 1rem; |
| 140 | + font-size: 0.85rem; |
| 141 | + font-weight: 600; |
| 142 | + background: var(--bg-surface); |
| 143 | + color: var(--text-secondary); |
| 144 | + border: 1px solid rgba(255, 255, 255, 0.08); |
| 145 | + border-radius: var(--radius); |
| 146 | + } |
| 147 | +
|
| 148 | + .btn-secondary:hover { |
| 149 | + color: var(--text-primary); |
| 150 | + border-color: rgba(255, 255, 255, 0.15); |
| 151 | + } |
| 152 | +</style> |
0 commit comments