Fix date editing in Info Box - allow editing empty fields and properly handle all date components (weekday, month, year)
This commit is contained in:
@@ -2042,18 +2042,17 @@ function renderInfoBox() {
|
|||||||
// Row 1: Date, Weather, Temperature, Time widgets
|
// Row 1: Date, Weather, Temperature, Time widgets
|
||||||
let html = '<div class="rpg-dashboard rpg-dashboard-row-1">';
|
let html = '<div class="rpg-dashboard rpg-dashboard-row-1">';
|
||||||
|
|
||||||
// Calendar widget - actual visual calendar
|
// Calendar widget - always show (editable even if empty)
|
||||||
if (data.date) {
|
const monthShort = data.month ? data.month.substring(0, 3).toUpperCase() : 'MON';
|
||||||
const monthShort = data.month.substring(0, 3).toUpperCase();
|
const weekdayShort = data.weekday ? data.weekday.substring(0, 3).toUpperCase() : 'DAY';
|
||||||
const weekdayShort = data.weekday.substring(0, 3).toUpperCase();
|
const yearDisplay = data.year || 'YEAR';
|
||||||
html += `
|
html += `
|
||||||
<div class="rpg-dashboard-widget rpg-calendar-widget">
|
<div class="rpg-dashboard-widget rpg-calendar-widget">
|
||||||
<div class="rpg-calendar-top rpg-editable" contenteditable="true" data-field="month" title="Click to edit">${monthShort}</div>
|
<div class="rpg-calendar-top rpg-editable" contenteditable="true" data-field="month" title="Click to edit">${monthShort}</div>
|
||||||
<div class="rpg-calendar-day rpg-editable" contenteditable="true" data-field="weekday" title="Click to edit">${weekdayShort}</div>
|
<div class="rpg-calendar-day rpg-editable" contenteditable="true" data-field="weekday" title="Click to edit">${weekdayShort}</div>
|
||||||
<div class="rpg-calendar-year rpg-editable" contenteditable="true" data-field="year" title="Click to edit">${data.year}</div>
|
<div class="rpg-calendar-year rpg-editable" contenteditable="true" data-field="year" title="Click to edit">${yearDisplay}</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
|
||||||
|
|
||||||
// Weather widget - emoji with forecast text
|
// Weather widget - emoji with forecast text
|
||||||
if (data.weatherEmoji) {
|
if (data.weatherEmoji) {
|
||||||
@@ -2311,30 +2310,53 @@ function renderThoughts() {
|
|||||||
* Updates a specific field in the Info Box data and re-renders.
|
* Updates a specific field in the Info Box data and re-renders.
|
||||||
*/
|
*/
|
||||||
function updateInfoBoxField(field, value) {
|
function updateInfoBoxField(field, value) {
|
||||||
if (!lastGeneratedData.infoBox) return;
|
if (!lastGeneratedData.infoBox) {
|
||||||
|
// Initialize with empty info box if it doesn't exist
|
||||||
|
lastGeneratedData.infoBox = 'Info Box\n---\n';
|
||||||
|
}
|
||||||
|
|
||||||
// Reconstruct the Info Box text with updated field
|
// Reconstruct the Info Box text with updated field
|
||||||
const lines = lastGeneratedData.infoBox.split('\n');
|
const lines = lastGeneratedData.infoBox.split('\n');
|
||||||
const updatedLines = lines.map(line => {
|
let dateLineFound = false;
|
||||||
|
let dateLineIndex = -1;
|
||||||
|
|
||||||
|
// Find the date line
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
if (lines[i].includes('🗓️:')) {
|
||||||
|
dateLineFound = true;
|
||||||
|
dateLineIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedLines = lines.map((line, index) => {
|
||||||
if (field === 'month' && line.includes('🗓️:')) {
|
if (field === 'month' && line.includes('🗓️:')) {
|
||||||
const parts = line.split(',');
|
const parts = line.split(',');
|
||||||
if (parts.length >= 2) {
|
if (parts.length >= 2) {
|
||||||
// parts[0] = "🗓️: Weekday", parts[1] = " Month", parts[2] = " Year"
|
// parts[0] = "🗓️: Weekday", parts[1] = " Month", parts[2] = " Year"
|
||||||
parts[1] = ' ' + value;
|
parts[1] = ' ' + value;
|
||||||
return parts.join(',');
|
return parts.join(',');
|
||||||
|
} else if (parts.length === 1) {
|
||||||
|
// No existing month/year, add them
|
||||||
|
return `${parts[0]}, ${value}, YEAR`;
|
||||||
}
|
}
|
||||||
} else if (field === 'weekday' && line.includes('🗓️:')) {
|
} else if (field === 'weekday' && line.includes('🗓️:')) {
|
||||||
const parts = line.split(',');
|
const parts = line.split(',');
|
||||||
if (parts.length >= 1) {
|
|
||||||
// Keep the emoji, just update the weekday
|
// Keep the emoji, just update the weekday
|
||||||
parts[0] = '🗓️: ' + value;
|
const month = parts[1] ? parts[1].trim() : 'Month';
|
||||||
return parts.join(',');
|
const year = parts[2] ? parts[2].trim() : 'YEAR';
|
||||||
}
|
return `🗓️: ${value}, ${month}, ${year}`;
|
||||||
} else if (field === 'year' && line.includes('🗓️:')) {
|
} else if (field === 'year' && line.includes('🗓️:')) {
|
||||||
const parts = line.split(',');
|
const parts = line.split(',');
|
||||||
if (parts.length >= 3) {
|
if (parts.length >= 3) {
|
||||||
parts[2] = ' ' + value;
|
parts[2] = ' ' + value;
|
||||||
return parts.join(',');
|
return parts.join(',');
|
||||||
|
} else if (parts.length === 2) {
|
||||||
|
// No existing year, add it
|
||||||
|
return `${parts[0]}, ${parts[1]}, ${value}`;
|
||||||
|
} else if (parts.length === 1) {
|
||||||
|
// No existing month/year, add them
|
||||||
|
return `${parts[0]}, Month, ${value}`;
|
||||||
}
|
}
|
||||||
} else if (field === 'weatherEmoji' && line.match(/^[^:]+:\s*.+$/) && !line.includes('🗓️') && !line.includes('🌡️') && !line.includes('🕒') && !line.includes('🗺️') && !line.includes('Info Box') && !line.includes('---')) {
|
} else if (field === 'weatherEmoji' && line.match(/^[^:]+:\s*.+$/) && !line.includes('🗓️') && !line.includes('🌡️') && !line.includes('🕒') && !line.includes('🗺️') && !line.includes('Info Box') && !line.includes('---')) {
|
||||||
// This is the weather line
|
// This is the weather line
|
||||||
@@ -2360,6 +2382,25 @@ function updateInfoBoxField(field, value) {
|
|||||||
return line;
|
return line;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If editing a date field but no date line exists, create one after the divider
|
||||||
|
if ((field === 'month' || field === 'weekday' || field === 'year') && !dateLineFound) {
|
||||||
|
// Find the divider line
|
||||||
|
const dividerIndex = updatedLines.findIndex(line => line.includes('---'));
|
||||||
|
if (dividerIndex >= 0) {
|
||||||
|
// Create initial date line with the edited field
|
||||||
|
let newDateLine = '';
|
||||||
|
if (field === 'weekday') {
|
||||||
|
newDateLine = `🗓️: ${value}, Month, YEAR`;
|
||||||
|
} else if (field === 'month') {
|
||||||
|
newDateLine = `🗓️: Weekday, ${value}, YEAR`;
|
||||||
|
} else if (field === 'year') {
|
||||||
|
newDateLine = `🗓️: Weekday, Month, ${value}`;
|
||||||
|
}
|
||||||
|
// Insert after the divider
|
||||||
|
updatedLines.splice(dividerIndex + 1, 0, newDateLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lastGeneratedData.infoBox = updatedLines.join('\n');
|
lastGeneratedData.infoBox = updatedLines.join('\n');
|
||||||
|
|
||||||
// Update the message's swipe data
|
// Update the message's swipe data
|
||||||
|
|||||||
Reference in New Issue
Block a user