diff --git a/index.js b/index.js index 1e04c02..e465652 100644 --- a/index.js +++ b/index.js @@ -2042,18 +2042,17 @@ function renderInfoBox() { // Row 1: Date, Weather, Temperature, Time widgets let html = '
'; - // Calendar widget - actual visual calendar - if (data.date) { - const monthShort = data.month.substring(0, 3).toUpperCase(); - const weekdayShort = data.weekday.substring(0, 3).toUpperCase(); - html += ` -
-
${monthShort}
-
${weekdayShort}
-
${data.year}
-
- `; - } + // Calendar widget - always show (editable even if empty) + const monthShort = data.month ? data.month.substring(0, 3).toUpperCase() : 'MON'; + const weekdayShort = data.weekday ? data.weekday.substring(0, 3).toUpperCase() : 'DAY'; + const yearDisplay = data.year || 'YEAR'; + html += ` +
+
${monthShort}
+
${weekdayShort}
+
${yearDisplay}
+
+ `; // Weather widget - emoji with forecast text if (data.weatherEmoji) { @@ -2311,30 +2310,53 @@ function renderThoughts() { * Updates a specific field in the Info Box data and re-renders. */ 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 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('πŸ—“οΈ:')) { const parts = line.split(','); if (parts.length >= 2) { // parts[0] = "πŸ—“οΈ: Weekday", parts[1] = " Month", parts[2] = " Year" parts[1] = ' ' + value; 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('πŸ—“οΈ:')) { const parts = line.split(','); - if (parts.length >= 1) { - // Keep the emoji, just update the weekday - parts[0] = 'πŸ—“οΈ: ' + value; - return parts.join(','); - } + // Keep the emoji, just update the weekday + const month = parts[1] ? parts[1].trim() : 'Month'; + const year = parts[2] ? parts[2].trim() : 'YEAR'; + return `πŸ—“οΈ: ${value}, ${month}, ${year}`; } else if (field === 'year' && line.includes('πŸ—“οΈ:')) { const parts = line.split(','); if (parts.length >= 3) { parts[2] = ' ' + value; 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('---')) { // This is the weather line @@ -2360,6 +2382,25 @@ function updateInfoBoxField(field, value) { 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'); // Update the message's swipe data