Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | <template> <div class="border rounded-lg p-3 bg-white shadow-sm" :class="{ 'border-green-400': isCompleted, 'border-gray-200': !isCompleted, }" > <!-- Home team --> <div class="flex justify-between items-center py-1" :class="{ 'font-bold text-green-700': isHomeWinner }" > <div class="flex items-center space-x-2"> <span v-if="bracketSlot.home_seed" class="text-xs text-gray-400 w-4 text-right" > {{ bracketSlot.home_seed }} </span> <span class="text-sm"> {{ bracketSlot.home_team_name || 'TBD' }} </span> </div> <span class="text-sm font-mono"> {{ bracketSlot.home_score ?? '-' }} </span> </div> <hr class="border-gray-100" /> <!-- Away team --> <div class="flex justify-between items-center py-1" :class="{ 'font-bold text-green-700': isAwayWinner }" > <div class="flex items-center space-x-2"> <span v-if="bracketSlot.away_seed" class="text-xs text-gray-400 w-4 text-right" > {{ bracketSlot.away_seed }} </span> <span class="text-sm"> {{ bracketSlot.away_team_name || 'TBD' }} </span> </div> <span class="text-sm font-mono"> {{ bracketSlot.away_score ?? '-' }} </span> </div> <!-- Date/Time display (view mode) --> <div v-if="bracketSlot.match_id && !editing" class="mt-1 flex items-center justify-between text-xs text-gray-500" > <span> {{ displayDate }} <span v-if="displayTime" class="ml-1">{{ displayTime }}</span> </span> <button @click="startEditing" class="ml-2 text-gray-400 hover:text-blue-600" title="Edit date/time" > ✎ </button> </div> <!-- Date/Time inline edit mode --> <div v-if="editing" class="mt-2 space-y-2"> <div class="flex space-x-2"> <input type="date" v-model="editDate" class="flex-1 text-xs border border-gray-300 rounded px-2 py-1 focus:outline-none focus:ring-1 focus:ring-blue-500" /> <input type="time" v-model="editTime" class="flex-1 text-xs border border-gray-300 rounded px-2 py-1 focus:outline-none focus:ring-1 focus:ring-blue-500" /> </div> <div class="flex justify-end space-x-2"> <button @click="cancelEditing" class="text-xs px-2 py-1 text-gray-600 border border-gray-300 rounded hover:bg-gray-50" > Cancel </button> <button @click="saveDateTime" :disabled="saving" class="text-xs px-2 py-1 bg-blue-600 text-white rounded hover:bg-blue-700 disabled:opacity-50" > {{ saving ? 'Saving...' : 'Save' }} </button> </div> </div> <!-- Status & Actions --> <div class="mt-2 flex justify-between items-center"> <span class="text-xs" :class="statusClass"> {{ statusLabel }} </span> <button v-if="canAdvance" @click="$emit('advance', bracketSlot.id)" :disabled="actionLoading" class="text-xs px-2 py-1 bg-blue-600 text-white rounded hover:bg-blue-700 disabled:opacity-50" > Advance Winner </button> </div> </div> </template> <script> import { ref, computed } from 'vue'; import { useAuthStore } from '@/stores/auth'; import { getApiBaseUrl } from '../../config/api'; export default { name: 'BracketSlotCard', props: { bracketSlot: { type: Object, required: true }, actionLoading: { type: Boolean, default: false }, }, emits: ['advance', 'updated'], setup(props, { emit }) { const authStore = useAuthStore(); const editing = ref(false); const saving = ref(false); const editDate = ref(''); const editTime = ref(''); const isCompleted = computed( () => props.bracketSlot.match_status === 'completed' ); const isHomeWinner = computed( () => isCompleted.value && props.bracketSlot.home_score != null && props.bracketSlot.away_score != null && props.bracketSlot.home_score > props.bracketSlot.away_score ); const isAwayWinner = computed( () => isCompleted.value && props.bracketSlot.home_score != null && props.bracketSlot.away_score != null && props.bracketSlot.away_score > props.bracketSlot.home_score ); const canAdvance = computed( () => isCompleted.value && props.bracketSlot.home_score !== props.bracketSlot.away_score && props.bracketSlot.round !== 'final' ); const statusLabel = computed(() => { if (!props.bracketSlot.match_id) return 'Awaiting teams'; if (props.bracketSlot.match_status === 'completed') return 'Completed'; if (props.bracketSlot.match_status === 'live') return 'Live'; return 'Scheduled'; }); const statusClass = computed(() => { if (!props.bracketSlot.match_id) return 'text-gray-400'; if (props.bracketSlot.match_status === 'completed') return 'text-green-600'; if (props.bracketSlot.match_status === 'live') return 'text-red-600 font-bold'; return 'text-blue-600'; }); // --- Date/Time display helpers --- const displayDate = computed(() => { const d = props.bracketSlot.match_date; if (!d) return ''; return d; }); const displayTime = computed(() => { return formatLocalTime(props.bracketSlot.scheduled_kickoff); }); const formatLocalTime = isoString => { if (!isoString) return null; const d = new Date(isoString); return d.toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit', hour12: true, }); }; const extractLocalTime = isoString => { if (!isoString) return ''; const d = new Date(isoString); return d.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false, }); }; const toScheduledKickoffUTC = (dateStr, time) => { if (!dateStr || !time) return null; const localDateTime = new Date(`${dateStr}T${time}`); return localDateTime.toISOString(); }; // --- Edit mode --- const startEditing = () => { editDate.value = props.bracketSlot.match_date || ''; editTime.value = extractLocalTime(props.bracketSlot.scheduled_kickoff); editing.value = true; }; const cancelEditing = () => { editing.value = false; }; const saveDateTime = async () => { if (!props.bracketSlot.match_id) return; try { saving.value = true; const body = {}; if (editDate.value) { body.match_date = editDate.value; } if (editDate.value && editTime.value) { body.scheduled_kickoff = toScheduledKickoffUTC( editDate.value, editTime.value ); } await authStore.apiRequest( `${getApiBaseUrl()}/api/matches/${props.bracketSlot.match_id}`, { method: 'PATCH', body: JSON.stringify(body), } ); editing.value = false; emit('updated'); } catch (err) { console.error('Failed to update match date/time:', err); } finally { saving.value = false; } }; return { editing, saving, editDate, editTime, isCompleted, isHomeWinner, isAwayWinner, canAdvance, statusLabel, statusClass, displayDate, displayTime, startEditing, cancelEditing, saveDateTime, }; }, }; </script> |