Fix date field editing to support both text and emoji formats

- Updated month/weekday/year field handlers to check for both 'Date:' and '🗓️:' formats
- Field updates now preserve the existing format (text or emoji)
- New date lines created in text format to match current standard
- Updated all field type checks (temperature, time, location) for dual-format support
- Fixes issue where editing date fields didn't update the prompt
This commit is contained in:
Spicy_Marinara
2025-10-22 01:04:30 +02:00
parent 8ad349c1d1
commit ae7c7b9f49
+26 -22
View File
@@ -385,23 +385,27 @@ export function updateInfoBoxField(field, value) {
} }
const updatedLines = lines.map((line, index) => { const updatedLines = lines.map((line, index) => {
if (field === 'month' && line.includes('🗓️:')) { if (field === 'month' && (line.includes('🗓️:') || line.startsWith('Date:'))) {
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] = "Date: Weekday" or "🗓️: Weekday", parts[1] = " Month", parts[2] = " Year"
parts[1] = ' ' + value; parts[1] = ' ' + value;
return parts.join(','); return parts.join(',');
} else if (parts.length === 1) { } else if (parts.length === 1) {
// No existing month/year, add them // No existing month/year, add them
return `${parts[0]}, ${value}, YEAR`; return `${parts[0]}, ${value}, YEAR`;
} }
} else if (field === 'weekday' && line.includes('🗓️:')) { } else if (field === 'weekday' && (line.includes('🗓️:') || line.startsWith('Date:'))) {
const parts = line.split(','); const parts = line.split(',');
// Keep the emoji, just update the weekday // Keep the format (text or emoji), just update the weekday
const month = parts[1] ? parts[1].trim() : 'Month'; const month = parts[1] ? parts[1].trim() : 'Month';
const year = parts[2] ? parts[2].trim() : 'YEAR'; const year = parts[2] ? parts[2].trim() : 'YEAR';
return `🗓️: ${value}, ${month}, ${year}`; if (line.startsWith('Date:')) {
} else if (field === 'year' && line.includes('🗓️:')) { return `Date: ${value}, ${month}, ${year}`;
} else {
return `🗓️: ${value}, ${month}, ${year}`;
}
} else if (field === 'year' && (line.includes('🗓️:') || line.startsWith('Date:'))) {
const parts = line.split(','); const parts = line.split(',');
if (parts.length >= 3) { if (parts.length >= 3) {
parts[2] = ' ' + value; parts[2] = ' ' + value;
@@ -474,14 +478,14 @@ export function updateInfoBoxField(field, value) {
// Find the divider line // Find the divider line
const dividerIndex = updatedLines.findIndex(line => line.includes('---')); const dividerIndex = updatedLines.findIndex(line => line.includes('---'));
if (dividerIndex >= 0) { if (dividerIndex >= 0) {
// Create initial date line with the edited field // Create initial date line with the edited field (use text format to match current standard)
let newDateLine = ''; let newDateLine = '';
if (field === 'weekday') { if (field === 'weekday') {
newDateLine = `🗓️: ${value}, Month, YEAR`; newDateLine = `Date: ${value}, Month, YEAR`;
} else if (field === 'month') { } else if (field === 'month') {
newDateLine = `🗓️: Weekday, ${value}, YEAR`; newDateLine = `Date: Weekday, ${value}, YEAR`;
} else if (field === 'year') { } else if (field === 'year') {
newDateLine = `🗓️: Weekday, Month, ${value}`; newDateLine = `Date: Weekday, Month, ${value}`;
} }
// Insert after the divider // Insert after the divider
updatedLines.splice(dividerIndex + 1, 0, newDateLine); updatedLines.splice(dividerIndex + 1, 0, newDateLine);
@@ -493,7 +497,7 @@ export function updateInfoBoxField(field, value) {
let weatherLineFound = false; let weatherLineFound = false;
for (const line of updatedLines) { for (const line of updatedLines) {
// Check if this is a weather line (has emoji and forecast, not one of the special fields) // Check if this is a weather line (has emoji and forecast, not one of the special fields)
if (line.match(/^[^:]+:\s*.+$/) && !line.includes('🗓️') && !line.includes('🌡️') && !line.includes('🕒') && !line.includes('🗺️') && !line.includes('Info Box') && !line.includes('---')) { if (line.match(/^[^:]+:\s*.+$/) && !line.includes('🗓️') && !line.startsWith('Date:') && !line.includes('🌡️') && !line.startsWith('Temperature:') && !line.includes('🕒') && !line.startsWith('Time:') && !line.includes('🗺️') && !line.startsWith('Location:') && !line.includes('Info Box') && !line.includes('---')) {
weatherLineFound = true; weatherLineFound = true;
break; break;
} }
@@ -504,12 +508,12 @@ export function updateInfoBoxField(field, value) {
if (dividerIndex >= 0) { if (dividerIndex >= 0) {
let newWeatherLine = ''; let newWeatherLine = '';
if (field === 'weatherEmoji') { if (field === 'weatherEmoji') {
newWeatherLine = `${value}: Weather`; newWeatherLine = `Weather: ${value}, Weather`;
} else if (field === 'weatherForecast') { } else if (field === 'weatherForecast') {
newWeatherLine = `🌤️: ${value}`; newWeatherLine = `Weather: 🌤️, ${value}`;
} }
// Insert after date line if it exists, otherwise after divider // Insert after date line if it exists, otherwise after divider
const dateIndex = updatedLines.findIndex(line => line.includes('🗓️:')); const dateIndex = updatedLines.findIndex(line => line.includes('🗓️:') || line.startsWith('Date:'));
const insertIndex = dateIndex >= 0 ? dateIndex + 1 : dividerIndex + 1; const insertIndex = dateIndex >= 0 ? dateIndex + 1 : dividerIndex + 1;
updatedLines.splice(insertIndex, 0, newWeatherLine); updatedLines.splice(insertIndex, 0, newWeatherLine);
} }
@@ -518,15 +522,15 @@ export function updateInfoBoxField(field, value) {
// If editing temperature but no temperature line exists, create one // If editing temperature but no temperature line exists, create one
if (field === 'temperature') { if (field === 'temperature') {
const tempLineFound = updatedLines.some(line => line.includes('🌡️:')); const tempLineFound = updatedLines.some(line => line.includes('🌡️:') || line.startsWith('Temperature:'));
if (!tempLineFound) { if (!tempLineFound) {
const dividerIndex = updatedLines.findIndex(line => line.includes('---')); const dividerIndex = updatedLines.findIndex(line => line.includes('---'));
if (dividerIndex >= 0) { if (dividerIndex >= 0) {
const newTempLine = `🌡️: ${value}`; const newTempLine = `Temperature: ${value}`;
// Find last non-empty line before creating position // Find last non-empty line before creating position
let insertIndex = dividerIndex + 1; let insertIndex = dividerIndex + 1;
for (let i = 0; i < updatedLines.length; i++) { for (let i = 0; i < updatedLines.length; i++) {
if (updatedLines[i].includes('🗓️:') || updatedLines[i].match(/^[^:]+:\s*.+$/)) { if (updatedLines[i].includes('🗓️:') || updatedLines[i].startsWith('Date:') || updatedLines[i].match(/^[^:]+:\s*.+$/)) {
insertIndex = i + 1; insertIndex = i + 1;
} }
} }
@@ -537,15 +541,15 @@ export function updateInfoBoxField(field, value) {
// If editing time but no time line exists, create one // If editing time but no time line exists, create one
if (field === 'timeStart') { if (field === 'timeStart') {
const timeLineFound = updatedLines.some(line => line.includes('🕒:')); const timeLineFound = updatedLines.some(line => line.includes('🕒:') || line.startsWith('Time:'));
if (!timeLineFound) { if (!timeLineFound) {
const dividerIndex = updatedLines.findIndex(line => line.includes('---')); const dividerIndex = updatedLines.findIndex(line => line.includes('---'));
if (dividerIndex >= 0) { if (dividerIndex >= 0) {
const newTimeLine = `🕒: ${value}${value}`; const newTimeLine = `Time: ${value}${value}`;
// Find last non-empty line before creating position // Find last non-empty line before creating position
let insertIndex = dividerIndex + 1; let insertIndex = dividerIndex + 1;
for (let i = 0; i < updatedLines.length; i++) { for (let i = 0; i < updatedLines.length; i++) {
if (updatedLines[i].includes('🗓️:') || updatedLines[i].includes('🌡️:') || updatedLines[i].match(/^[^:]+:\s*.+$/)) { if (updatedLines[i].includes('🗓️:') || updatedLines[i].startsWith('Date:') || updatedLines[i].includes('🌡️:') || updatedLines[i].startsWith('Temperature:') || updatedLines[i].match(/^[^:]+:\s*.+$/)) {
insertIndex = i + 1; insertIndex = i + 1;
} }
} }
@@ -556,11 +560,11 @@ export function updateInfoBoxField(field, value) {
// If editing location but no location line exists, create one // If editing location but no location line exists, create one
if (field === 'location') { if (field === 'location') {
const locationLineFound = updatedLines.some(line => line.includes('🗺️:')); const locationLineFound = updatedLines.some(line => line.includes('🗺️:') || line.startsWith('Location:'));
if (!locationLineFound) { if (!locationLineFound) {
const dividerIndex = updatedLines.findIndex(line => line.includes('---')); const dividerIndex = updatedLines.findIndex(line => line.includes('---'));
if (dividerIndex >= 0) { if (dividerIndex >= 0) {
const newLocationLine = `🗺️: ${value}`; const newLocationLine = `Location: ${value}`;
// Insert at the end (before any empty lines) // Insert at the end (before any empty lines)
let insertIndex = updatedLines.length; let insertIndex = updatedLines.length;
for (let i = updatedLines.length - 1; i >= 0; i--) { for (let i = updatedLines.length - 1; i >= 0; i--) {