fix: updateBedtimeRange variable scoping - originalText accessible in finally block
This commit is contained in:
@@ -2544,12 +2544,15 @@ async function updateBedtimeRange(guildId) {
|
|||||||
const [startHour, startMinute] = startTime.split(':').map(Number);
|
const [startHour, startMinute] = startTime.split(':').map(Number);
|
||||||
const [endHour, endMinute] = endTime.split(':').map(Number);
|
const [endHour, endMinute] = endTime.split(':').map(Number);
|
||||||
|
|
||||||
|
const button = document.querySelector(`button[onclick="updateBedtimeRange('${guildIdStr}')"]`);
|
||||||
|
const originalText = button ? button.textContent : 'Update Bedtime Range';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Show loading state
|
// Show loading state
|
||||||
const button = document.querySelector(`button[onclick="updateBedtimeRange('${guildIdStr}')"]`);
|
if (button) {
|
||||||
const originalText = button.textContent;
|
|
||||||
button.textContent = 'Updating...';
|
button.textContent = 'Updating...';
|
||||||
button.disabled = true;
|
button.disabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Send the update request
|
// Send the update request
|
||||||
const response = await fetch(`/servers/${guildIdStr}/bedtime-range`, {
|
const response = await fetch(`/servers/${guildIdStr}/bedtime-range`, {
|
||||||
@@ -2579,9 +2582,8 @@ async function updateBedtimeRange(guildId) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to update bedtime range:', error);
|
console.error('Failed to update bedtime range:', error);
|
||||||
showNotification(error.message || 'Failed to update bedtime range', 'error');
|
showNotification(error.message || 'Failed to update bedtime range', 'error');
|
||||||
|
} finally {
|
||||||
// Restore button state
|
// Restore button state
|
||||||
const button = document.querySelector(`button[onclick="updateBedtimeRange('${guildIdStr}')"]`);
|
|
||||||
if (button) {
|
if (button) {
|
||||||
button.textContent = originalText;
|
button.textContent = originalText;
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user