Skip to content

Commit 17292be

Browse files
committed
Feat: Implement full reset functionality for 'New story' button
Enhanced the 'resetStoryView' function to clear all selected parameters, input fields, and reset the UI state of the parameter containers to their initial configuration. This includes deselecting chips, clearing textareas and character inputs, and managing the visibility and state of parameter containers and the 'Generate story' button.
1 parent fcfe4cf commit 17292be

File tree

2 files changed

+77
-16
lines changed

2 files changed

+77
-16
lines changed

examples/bedtime-story-teller/assets/app.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,68 @@ function resetStoryView() {
197197
document.getElementById('story-container').style.display = 'none';
198198
document.getElementById('prompt-display').innerHTML = '';
199199
document.getElementById('story-response').textContent = '';
200+
201+
// Reset parameter selections
202+
document.querySelectorAll('.chip.selected').forEach(chip => {
203+
chip.classList.remove('selected');
204+
});
205+
206+
document.querySelectorAll('.selected-value').forEach(selectedValue => {
207+
selectedValue.innerHTML = '';
208+
selectedValue.style.display = 'none';
209+
});
210+
211+
// Reset Story type optional text
212+
document.querySelectorAll('.parameter-container:nth-child(3) .optional-text').forEach(optionalText => {
213+
optionalText.textContent = '(optional)';
214+
});
215+
216+
// Clear character inputs and remove extra groups
217+
const characterInputGroups = document.querySelectorAll('.character-input-group');
218+
characterInputGroups.forEach((group, index) => {
219+
if (index === 0) { // Only clear the first group, others will be removed
220+
group.querySelector('.character-name').value = '';
221+
group.querySelector('.character-role').selectedIndex = 0;
222+
group.querySelector('.character-description').value = '';
223+
group.querySelector('.delete-character-button').style.display = 'none';
224+
} else {
225+
group.remove();
226+
}
227+
});
228+
document.querySelector('.add-character-button').style.display = 'block'; // Ensure add character button is visible
229+
230+
// Clear "Other" textarea
231+
const otherTextarea = document.querySelector('.other-textarea');
232+
if (otherTextarea) {
233+
otherTextarea.value = '';
234+
const charCounter = document.querySelector('.char-counter');
235+
if (charCounter) {
236+
charCounter.textContent = `0 / ${otherTextarea.maxLength}`;
237+
}
238+
}
239+
240+
// Hide "Generate story" button
241+
const generateStoryButton = document.querySelector('.generate-story-button');
242+
if (generateStoryButton) {
243+
generateStoryButton.style.display = 'none';
244+
}
245+
246+
// Reset parameter containers state
247+
const parameterContainers = document.querySelectorAll('.parameter-container');
248+
parameterContainers.forEach((container, index) => {
249+
const content = container.querySelector('.parameter-content');
250+
const arrow = container.querySelector('.arrow-icon');
251+
252+
if (index === 0) { // Age container
253+
content.style.display = 'block';
254+
arrow.classList.add('rotated');
255+
container.classList.remove('disabled');
256+
} else {
257+
container.classList.add('disabled');
258+
content.style.display = 'none';
259+
arrow.classList.remove('rotated');
260+
}
261+
});
200262
}
201263

202264
document.addEventListener('DOMContentLoaded', () => {

examples/bedtime-story-teller/assets/style.css

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ body {
479479
color: #008184;
480480
padding: 8px 16px;
481481
border-radius: 200px;
482+
border: none;
482483
cursor: pointer;
483484
display: flex;
484485
align-items: center;
@@ -547,13 +548,26 @@ body {
547548

548549
.modal-body {
549550
padding: 15px 0;
551+
text-align: center;
552+
}
553+
554+
.modal-body p {
555+
color: #2C353A;
556+
font-size: 20px;
557+
font-style: normal;
558+
font-weight: 700;
559+
}
560+
561+
.modal-body-small {
562+
font-size: 14px !important;
563+
font-style: normal !important;
564+
font-weight: 400 !important;
550565
}
551566

552567
.modal-footer {
553568
display: flex;
554569
justify-content: flex-end;
555570
padding-top: 10px;
556-
border-top: 1px solid #ddd;
557571
}
558572

559573
#clear-story-button,
@@ -610,21 +624,6 @@ body {
610624
color: #2C353A;
611625
}
612626

613-
#clear-story-button {
614-
/* Style similar to other buttons */
615-
border-radius: 8px;
616-
background: #AA4335; /* A different color to distinguish */
617-
color: white;
618-
font-family: "Open Sans";
619-
font-size: 12px;
620-
font-weight: 600;
621-
padding: 8px 16px;
622-
border: none;
623-
cursor: pointer;
624-
margin-top: 16px;
625-
align-self: center; /* Center the button */
626-
}
627-
628627
.spinner {
629628
border: 4px solid #f3f3f3;
630629
border-top: 4px solid #3498db;

0 commit comments

Comments
 (0)