|
| 1 | +<script lang="ts"> |
| 2 | + import Card from './Card.svelte'; |
| 3 | + import Button from './Button.svelte'; |
| 4 | + import Map from './Map.svelte'; |
| 5 | + import { updateImage, type Picture } from '$lib/api/admin'; |
| 6 | +
|
| 7 | + interface Props { |
| 8 | + image: Picture; |
| 9 | + onClose: () => void; |
| 10 | + onSave: (updated: Picture) => void; |
| 11 | + } |
| 12 | +
|
| 13 | + let { image, onClose, onSave }: Props = $props(); |
| 14 | +
|
| 15 | + // Local state for editable fields |
| 16 | + let editCoordinates = $state({ lat: image.latitude, lng: image.longitude }); |
| 17 | + let editDifficulty = $state<'EASY' | 'MEDIUM' | 'HARD'>(image.difficulty); |
| 18 | + let editShowInDaily = $state(image.showInDaily); |
| 19 | + let editShowInVersus = $state(image.showInVersus); |
| 20 | + let editShowInTournament = $state(image.showInTournament); |
| 21 | + let saving = $state(false); |
| 22 | +
|
| 23 | + const difficultyOptions = [ |
| 24 | + { value: 'EASY', label: 'Easy', color: 'bg-lime' }, |
| 25 | + { value: 'MEDIUM', label: 'Medium', color: 'bg-cyan' }, |
| 26 | + { value: 'HARD', label: 'Hard', color: 'bg-magenta' } |
| 27 | + ]; |
| 28 | +
|
| 29 | + function handleMapSelect(coords: { lat: number; lng: number }) { |
| 30 | + editCoordinates = coords; |
| 31 | + } |
| 32 | +
|
| 33 | + async function handleSave() { |
| 34 | + saving = true; |
| 35 | + try { |
| 36 | + const updated = await updateImage(image.id, { |
| 37 | + latitude: editCoordinates.lat, |
| 38 | + longitude: editCoordinates.lng, |
| 39 | + difficulty: editDifficulty, |
| 40 | + showInDaily: editShowInDaily, |
| 41 | + showInVersus: editShowInVersus, |
| 42 | + showInTournament: editShowInTournament |
| 43 | + }); |
| 44 | + if (updated) { |
| 45 | + onSave(updated); |
| 46 | + } else { |
| 47 | + alert('Failed to update image'); |
| 48 | + } |
| 49 | + } catch (error) { |
| 50 | + alert('Failed to update image'); |
| 51 | + } |
| 52 | + saving = false; |
| 53 | + } |
| 54 | +</script> |
| 55 | + |
| 56 | +<!-- Fullscreen Edit Modal --> |
| 57 | +<div |
| 58 | + class="fixed inset-0 bg-primary z-50 flex flex-col" |
| 59 | + role="dialog" |
| 60 | + tabindex="-1" |
| 61 | + onkeydown={(e) => e.key === 'Escape' && onClose()} |
| 62 | +> |
| 63 | + <!-- Header --> |
| 64 | + <div class="p-5 flex items-center justify-between bg-white flex-shrink-0 brutal-border-b"> |
| 65 | + <h2 class="text-xl font-black uppercase">Edit Image</h2> |
| 66 | + <button |
| 67 | + type="button" |
| 68 | + onclick={onClose} |
| 69 | + class="w-10 h-10 bg-magenta text-white brutal-border font-black text-lg hover:bg-magenta/80 transition-colors flex items-center justify-center" |
| 70 | + title="Close" |
| 71 | + > |
| 72 | + × |
| 73 | + </button> |
| 74 | + </div> |
| 75 | + |
| 76 | + <!-- Content --> |
| 77 | + <div class="flex-1 overflow-auto p-6"> |
| 78 | + <div class="w-full h-full max-w-7xl mx-auto flex flex-col lg:flex-row gap-6"> |
| 79 | + <!-- Image Panel (Left) --> |
| 80 | + <div class="lg:w-1/2 flex flex-col min-h-[300px] lg:min-h-0"> |
| 81 | + <Card class="flex flex-col p-0 overflow-hidden h-full"> |
| 82 | + <div class="p-5"> |
| 83 | + <h3 class="text-lg font-black uppercase">Image Preview</h3> |
| 84 | + </div> |
| 85 | + <div class="relative grow bg-gray w-full block"> |
| 86 | + <img src={image.imageUrl} alt="Location" class="w-full h-full object-cover" /> |
| 87 | + </div> |
| 88 | + </Card> |
| 89 | + </div> |
| 90 | + |
| 91 | + <!-- Map Panel (Right) --> |
| 92 | + <div class="lg:w-1/2 flex flex-col min-h-[300px] lg:min-h-0"> |
| 93 | + <Card class="flex flex-col p-0 overflow-hidden h-full"> |
| 94 | + <div class="p-5"> |
| 95 | + <h3 class="text-lg font-black uppercase">Location (click to change)</h3> |
| 96 | + <p class="text-xs font-mono opacity-60 mt-1"> |
| 97 | + {editCoordinates.lat.toFixed(6)}, {editCoordinates.lng.toFixed(6)} |
| 98 | + </p> |
| 99 | + </div> |
| 100 | + <div class="grow"> |
| 101 | + <Map onSelect={handleMapSelect} guessLocation={editCoordinates} centerOnGuess={true} /> |
| 102 | + </div> |
| 103 | + </Card> |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + |
| 107 | + <!-- Settings Section --> |
| 108 | + <div class="max-w-7xl mx-auto mt-6"> |
| 109 | + <Card> |
| 110 | + <div class="grid md:grid-cols-2 gap-6"> |
| 111 | + <!-- Difficulty --> |
| 112 | + <div> |
| 113 | + <label class="block text-sm font-bold uppercase mb-2">Difficulty</label> |
| 114 | + <div class="grid grid-cols-3 gap-2"> |
| 115 | + {#each difficultyOptions as option} |
| 116 | + <button |
| 117 | + type="button" |
| 118 | + onclick={() => (editDifficulty = option.value as 'EASY' | 'MEDIUM' | 'HARD')} |
| 119 | + class="brutal-border px-4 py-3 font-bold text-sm uppercase transition-all {editDifficulty === |
| 120 | + option.value |
| 121 | + ? `${option.color} text-white` |
| 122 | + : 'bg-white hover:bg-gray/50'}" |
| 123 | + > |
| 124 | + {option.label} |
| 125 | + </button> |
| 126 | + {/each} |
| 127 | + </div> |
| 128 | + </div> |
| 129 | + |
| 130 | + <!-- Mode Visibility --> |
| 131 | + <div> |
| 132 | + <label class="block text-sm font-bold uppercase mb-2">Show In Game Modes</label> |
| 133 | + <div class="flex flex-wrap gap-4"> |
| 134 | + <label class="flex items-center gap-2 cursor-pointer"> |
| 135 | + <input |
| 136 | + type="checkbox" |
| 137 | + bind:checked={editShowInDaily} |
| 138 | + class="w-5 h-5 brutal-border accent-orange" |
| 139 | + /> |
| 140 | + <span class="font-bold">Daily</span> |
| 141 | + </label> |
| 142 | + <label class="flex items-center gap-2 cursor-pointer"> |
| 143 | + <input |
| 144 | + type="checkbox" |
| 145 | + bind:checked={editShowInVersus} |
| 146 | + class="w-5 h-5 brutal-border accent-cyan" |
| 147 | + /> |
| 148 | + <span class="font-bold">Versus</span> |
| 149 | + </label> |
| 150 | + <label class="flex items-center gap-2 cursor-pointer"> |
| 151 | + <input |
| 152 | + type="checkbox" |
| 153 | + bind:checked={editShowInTournament} |
| 154 | + class="w-5 h-5 brutal-border accent-magenta" |
| 155 | + /> |
| 156 | + <span class="font-bold">Tournament</span> |
| 157 | + </label> |
| 158 | + </div> |
| 159 | + </div> |
| 160 | + </div> |
| 161 | + </Card> |
| 162 | + </div> |
| 163 | + </div> |
| 164 | + |
| 165 | + <!-- Footer --> |
| 166 | + <div class="p-5 bg-white flex-shrink-0 brutal-border-t flex justify-end gap-3"> |
| 167 | + <Button variant="magenta" onclick={onClose} disabled={saving}>Cancel</Button> |
| 168 | + <Button variant="cyan" onclick={handleSave} disabled={saving}> |
| 169 | + {saving ? 'Saving...' : 'Save Changes'} |
| 170 | + </Button> |
| 171 | + </div> |
| 172 | +</div> |
0 commit comments