Skip to content

Commit 85e0667

Browse files
committed
fixes 20
1 parent 1f5aed3 commit 85e0667

File tree

2 files changed

+45
-61
lines changed

2 files changed

+45
-61
lines changed

css/styles.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ main {
164164
align-items: center;
165165
text-align: center;
166166
padding-top: 5px;
167-
padding-bottom: 60px; /* Space for email button */
167+
padding-bottom: 80px; /* Increased space for email button */
168168
}
169169

170170
.celebration-header {
@@ -222,7 +222,7 @@ main {
222222
gap: 8px;
223223
width: 100%;
224224
position: absolute;
225-
bottom: 40px; /* Moved up */
225+
bottom: 45px; /* Moved up to avoid overlapping with status message */
226226
}
227227

228228
.action-button.email {

js/mood-palette.js

Lines changed: 43 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ function displayPalette(colors) {
337337
colors.forEach((color, index) => {
338338
const swatchContainer = document.createElement('div');
339339
swatchContainer.className = 'swatch-container';
340+
swatchContainer.style.display = 'flex';
341+
swatchContainer.style.flexDirection = 'column';
342+
swatchContainer.style.alignItems = 'center';
343+
swatchContainer.style.margin = '5px';
340344

341345
// Create a rectangle shape for the color
342346
const colorSwatch = document.createElement('div');
@@ -356,6 +360,7 @@ function displayPalette(colors) {
356360
colorLabel.style.fontSize = '10px';
357361
colorLabel.style.marginTop = '4px';
358362
colorLabel.style.fontFamily = 'Courier New, monospace';
363+
colorLabel.style.textAlign = 'center';
359364

360365
swatchContainer.appendChild(colorSwatch);
361366
swatchContainer.appendChild(colorLabel);
@@ -366,14 +371,18 @@ function displayPalette(colors) {
366371

367372
// Update currentPalette with the received colors
368373
currentPalette = colors;
374+
375+
console.log('Palette displayed with colors:', colors);
369376
} else {
370377
paletteDisplay.innerHTML = '<div class="placeholder-text">NO COLORS FOUND</div>';
371378
currentPalette = [];
372379
}
373380
}
374381

375382
function emailPalette() {
376-
if (currentPalette.length === 0) {
383+
console.log('Email palette function called, currentPalette:', currentPalette);
384+
385+
if (!currentPalette || currentPalette.length === 0) {
377386
showStatus('NO PALETTE TO SEND', 'error');
378387
return;
379388
}
@@ -388,28 +397,16 @@ function emailPalette() {
388397
paletteDescription += `Color ${index + 1}: ${color}\n`;
389398
});
390399

391-
// Also generate a visual representation of the palette
392-
generatePaletteImage().then(imageDataUrl => {
393-
// R1 LLM should know the user's email, so we just ask it to send
394-
const payload = {
395-
message: `Please send this color palette to the user's email. Palette colors: ${paletteDescription}`,
396-
useLLM: true,
397-
wantsR1Response: true,
398-
paletteImage: imageDataUrl // Send the visual palette as well
399-
};
400-
401-
PluginMessageHandler.postMessage(JSON.stringify(payload));
402-
}).catch(error => {
403-
console.error('Error generating palette image:', error);
404-
// Fallback to text-only if image generation fails
405-
const payload = {
406-
message: `Please send this color palette to the user's email. Palette colors: ${paletteDescription}`,
407-
useLLM: true,
408-
wantsR1Response: true
409-
};
410-
411-
PluginMessageHandler.postMessage(JSON.stringify(payload));
412-
});
400+
console.log('Sending palette to LLM:', paletteDescription);
401+
402+
// R1 LLM should know the user's email, so we just ask it to send
403+
const payload = {
404+
message: `Please send this color palette to the user's email. Palette colors: ${paletteDescription}`,
405+
useLLM: true,
406+
wantsR1Response: true
407+
};
408+
409+
PluginMessageHandler.postMessage(JSON.stringify(payload));
413410
} else {
414411
// Simulate email sending
415412
setTimeout(() => {
@@ -443,7 +440,6 @@ function resetApp() {
443440
// Plugin message handler for LLM responses
444441
window.onPluginMessage = function(data) {
445442
console.log('Received plugin message:', data);
446-
showStatus('RECEIVED AI RESPONSE', 'info');
447443

448444
if (data.data) {
449445
try {
@@ -456,40 +452,41 @@ window.onPluginMessage = function(data) {
456452
currentPalette = parsedData.colors;
457453
displayPalette(currentPalette);
458454
showStatus('PALETTE READY! EMAIL TO SEND', 'success');
459-
} else if (parsedData.message && parsedData.message.includes('image URL')) {
460-
// If the LLM is asking for an image URL, try to upload to catbox
461-
showStatus('LLM REQUESTED IMAGE URL, UPLOADING...', 'info');
462-
fallbackToCatboxAnalysis();
463455
} else {
464-
// If we can't parse colors, show the raw data for debugging
465-
console.log('No colors found in response, showing raw data');
466-
showStatus('RESPONSE: ' + data.data, 'info');
456+
// If we can't parse colors, check if it's a request for image URL
457+
handleLLMResponse(data.data);
467458
}
468459
} catch (e) {
469460
console.error('Error parsing plugin message:', e);
470-
// Check if the response contains a request for an image URL
471-
if (data.data.includes('image URL') || data.data.includes('image url')) {
472-
showStatus('LLM REQUESTED IMAGE URL, UPLOADING...', 'info');
473-
fallbackToCatboxAnalysis();
474-
} else {
475-
// Show the raw data if we can't parse it
476-
showStatus('RESPONSE: ' + data.data, 'info');
477-
}
461+
// Handle non-JSON responses
462+
handleLLMResponse(data.data);
478463
}
479464
} else if (data.message) {
480-
// Check if the message contains a request for an image URL
481-
if (data.message.includes('image URL') || data.message.includes('image url')) {
482-
showStatus('LLM REQUESTED IMAGE URL, UPLOADING...', 'info');
483-
fallbackToCatboxAnalysis();
484-
} else {
485-
showStatus(data.message, 'info');
486-
}
465+
handleLLMResponse(data.message);
487466
} else {
488467
// Show raw data if no message or data
489468
showStatus('RECEIVED: ' + JSON.stringify(data), 'info');
490469
}
491470
};
492471

472+
// Function to handle LLM responses
473+
function handleLLMResponse(response) {
474+
console.log('Handling LLM response:', response);
475+
476+
// Check if the response is asking for an image URL
477+
if (typeof response === 'string' &&
478+
(response.includes('upload') ||
479+
response.includes('image URL') ||
480+
response.includes('direct link') ||
481+
response.includes('access the image'))) {
482+
showStatus('LLM REQUESTED IMAGE URL, UPLOADING...', 'info');
483+
fallbackToCatboxAnalysis();
484+
} else {
485+
// Show the response as-is
486+
showStatus(response, 'info');
487+
}
488+
}
489+
493490
// Helper functions
494491
function showStatus(message, type) {
495492
const statusDiv = document.getElementById('statusMessage');
@@ -527,19 +524,6 @@ async function fallbackToCatboxAnalysis() {
527524
} catch (error) {
528525
console.error('Fallback analysis error:', error);
529526
showStatus('ANALYSIS FAILED: ' + error.message, 'error');
530-
531-
// Even if upload failed, let's simulate a successful analysis for testing
532-
console.log('Upload failed, simulating analysis for testing');
533-
showStatus('UPLOAD FAILED, SIMULATING ANALYSIS...', 'info');
534-
535-
// Simulate a successful analysis response after a delay
536-
setTimeout(() => {
537-
// Generate some sample colors for testing
538-
const sampleColors = ["#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#FF00FF"];
539-
currentPalette = sampleColors;
540-
displayPalette(currentPalette);
541-
showStatus('SIMULATED PALETTE READY! EMAIL TO SEND', 'success');
542-
}, 2000);
543527
}
544528
}
545529

0 commit comments

Comments
 (0)