Unified Scenario Creation Modal: A Single Modal Component
Creating compelling scenarios is a cornerstone of imaginative storytelling and engaging world-building. To streamline this process, a unified scenario creation modal has been developed. This single modal component simplifies how users craft What If scenarios, incorporating real-time validation, character counters, and unified form handling for Character Changes, Event Alterations, and Setting Modifications.
Key Design Principles: Simplicity and Efficiency
The core of this modal’s design revolves around a single-step approach. Unlike multi-step wizards that can feel cumbersome, this modal presents all options in one view. This design choice emphasizes optional fields, allowing users to focus on the elements most relevant to their scenario. The implementation of strict validation rules ensures that each scenario adheres to quality standards, fostering more coherent and impactful narratives.
Building a Custom Modal Component
The foundation of this feature is a custom modal component, built using Teleport and PandaCSS in unstyled PrimeVue mode. This ensures flexibility and control over the modal’s appearance and behavior. Teleport allows the modal to be rendered outside the typical component hierarchy, preventing styling conflicts and ensuring it sits atop other page elements. PandaCSS provides a modern, type-safe approach to styling, and the unstyled PrimeVue mode offers a clean slate for designing a unique user interface.
Triggering the Modal
The modal is seamlessly integrated into the user experience, triggered from the Book Detail page via a clear and intuitive [+ Create Scenario] button. This placement ensures users can easily access scenario creation tools while reviewing the details of their stories. By keeping the entry point contextual, the feature becomes a natural extension of the story exploration process.
A Unified Form
Central to the modal's efficiency is its single unified form. Rather than navigating through tabs or wizard steps, users interact with all scenario elements on a single screen. This design promotes a holistic approach to scenario creation, allowing for easy cross-referencing and iteration between different scenario types. The unified form consolidates the user's focus, making the creation process faster and more intuitive.
Optional Text Fields for Scenario Types
To accommodate diverse storytelling needs, the modal includes three optional text fields, each dedicated to a specific scenario type:
- Character Changes: This field captures alterations to character traits, motivations, or backstories. For example, "Hermione sorted into Slytherin" reimagines a fundamental aspect of the Harry Potter narrative.
- Event Alterations: This field focuses on changing the outcomes or circumstances of key events. "Troll incident: saved by Draco instead" presents an intriguing twist on a pivotal moment, potentially reshaping character relationships and plot developments.
- Setting Modifications: This field allows for alterations to the story’s environment, locations, or timeline. This could involve shifting the story to a different time period, introducing new locations, or modifying the existing setting to create a unique atmosphere.
The optional nature of these fields gives users the freedom to tailor their scenarios to specific interests, ensuring flexibility in the creative process.
Required Scenario Title Field
While the scenario types are optional, the scenario title field is required. This field, limited to 100 characters, serves as a concise identifier for each scenario. A clear and descriptive title is essential for organization and quick recall, enabling users to easily manage and revisit their creations. The character limit encourages users to distill their ideas into a succinct and impactful summary.
Real-Time Character Counters
To assist users in crafting scenarios that meet length requirements, real-time character counters are implemented for each text field. These counters display the current character count, providing immediate feedback on the length of the input. This feature helps users stay within the guidelines and ensures that each scenario type meets the minimum character requirement for validation.
Submit Button and Validation
The Submit button is a critical element, enabled only when the form passes validation. This prevents the submission of incomplete or invalid scenarios, ensuring data integrity and a smoother user experience. The button’s disabled state serves as a visual cue, prompting users to address any errors or omissions before proceeding.
Validation Rules: Ensuring Scenario Quality
Comprehensive validation rules are in place to maintain the quality and coherence of created scenarios. These rules cover several key aspects of the form input, ensuring that only well-formed scenarios are submitted.
Minimum One Scenario Type
A fundamental rule is that at least one of the three scenario types must be filled. This ensures that each scenario introduces a meaningful alteration to the story, preventing the creation of empty or trivial scenarios. This requirement drives users to actively engage with the story's possibilities, fostering more thoughtful and creative submissions.
Minimum Character Count
Each filled field must contain a minimum of 10 characters. This requirement encourages users to provide sufficient detail in their scenarios, moving beyond brief ideas to more developed concepts. The 10-character threshold strikes a balance between requiring substance and allowing for concise entries, ensuring that the scenarios are meaningful without being overly verbose.
Handling Empty Fields
Empty fields are explicitly allowed, reflecting the optional nature of the scenario types. This gives users the flexibility to focus on the aspects of the story they find most compelling, without feeling obligated to fill out every field. The allowance for empty fields supports a more fluid and personalized creation process.
Error State and Visual Feedback
Fields with fewer than 10 characters trigger an error state, providing immediate visual feedback to the user. The field's border turns red, and the character counter also changes color, clearly indicating the issue. This real-time feedback loop helps users quickly identify and correct errors, leading to a more efficient and satisfying experience.
Submit Button Logic
The Submit button remains disabled until two primary conditions are met: the scenario title is not empty (after trimming whitespace), and at least one scenario type has a valid entry (10+ characters). This logic ensures that all required fields are adequately filled before submission, maintaining the integrity of the data. The disabled button serves as a clear visual cue, guiding users through the necessary steps for scenario creation.
Error Message
An informative error message is displayed when validation fails, specifically stating: "Please provide at least one scenario type with 10+ characters." This message is clear, concise, and actionable, directly guiding users on how to resolve the issue. By providing specific feedback, the error message reduces user frustration and promotes successful form completion.
Character Counter Implementation: Real-Time Feedback
The character counter is a key component of the modal, providing real-time feedback on the length of each text field. Its design incorporates visual cues to help users understand the validation status at a glance.
Real-Time Counter
A real-time counter is displayed for each textarea, showing the current character count relative to the minimum requirement: {current_length}/10 chars. This immediate feedback helps users gauge their progress and make informed decisions about their input. The counter updates dynamically with every keystroke, providing a continuous stream of information.
Color Coding
The counter employs color coding to visually communicate the validation status:
- âś… Green: Indicates 10 or more characters, signifying a valid entry.
- ❌ Red: Indicates 1-9 characters, highlighting an invalid entry.
- ⚪ Gray: Indicates 0 characters, representing a neutral, optional field.
This color-coded system allows users to quickly assess the state of each field, enhancing the user experience and reducing errors.
Counter Updates
The counter updates in real-time, responding to every keystroke. This instantaneous feedback is crucial for guiding users as they type, ensuring they are always aware of their character count. The responsiveness of the counter enhances the overall fluidity and efficiency of the creation process.
Visual Feedback
The visual feedback is immediate, with no debounce applied. This means the counter and color coding update instantly, providing a seamless and responsive experience. The absence of debounce ensures that users receive continuous and accurate information, fostering a more intuitive interaction.
Form Fields: A Detailed View
The form fields are designed to be clear, intuitive, and user-friendly, each serving a specific purpose in the scenario creation process.
Scenario Title (Required)
The Scenario Title field is a required text input, providing a space for users to name their scenario. The input field is accompanied by a character counter, displaying the current count out of the 100-character limit: [Scenario Title________________________] (0/100). This field is crucial for identifying and organizing scenarios, making it a central element of the modal.
Character Changes (Optional)
The Character Changes field is an optional textarea, allowing users to describe alterations to character traits or backstories. An example input, "[Hermione sorted into Slytherin] 15/10 chars âś“", demonstrates how the counter and validation status are displayed. This field offers a space for users to explore how character modifications can impact the narrative.
Event Alterations (Optional)
The Event Alterations field is another optional textarea, designed for describing changes to key events or outcomes. The example, "[Troll incident: saved by Draco instead] 40/10 chars âś“", illustrates the type of input this field accommodates. This field encourages users to reimagine pivotal moments in the story, potentially creating new plotlines and character dynamics.
Setting Modifications (Optional)
The Setting Modifications field allows users to alter the story’s environment, location, or timeline. An example input, [ ] 0/10 chars (optional), shows the field's neutral state when empty. This field provides a space for users to explore how changes in the setting can influence the narrative's tone and events.
API Integration: Connecting to the Backend
Seamless API integration is crucial for saving and retrieving scenarios. The modal is designed to communicate with the backend via a specific endpoint, ensuring a smooth data flow.
POST /api/v1/scenarios Endpoint
The modal integrates with the POST /api/v1/scenarios endpoint, which handles the creation of new scenarios. This endpoint is the destination for the scenario data, ensuring that each submission is properly processed and stored in the system.
Request Payload
The request payload is structured as a JSON object, containing the necessary information to create a scenario. The payload includes the book_id, scenario_title, and the three scenario types: character_changes, event_alterations, and setting_modifications. An example payload is shown below:
{
"book_id": "uuid",
"scenario_title": "Hermione in Slytherin",
"character_changes": "Hermione sorted into Slytherin instead of Gryffindor",
"event_alterations": "Troll incident: saved by Draco and Pansy",
"setting_modifications": ""
}
This structured payload ensures that the backend receives all the necessary data in a consistent format.
Success Response
Upon successful submission, the user is redirected to the Scenario Detail page. This redirection provides immediate feedback that the scenario has been created and allows the user to view the details of their new scenario. The smooth transition enhances the overall user experience.
Error Handling
Error handling is implemented to manage API errors gracefully. If an error occurs during submission, inline error messages are displayed, providing users with specific feedback on what went wrong. This helps users understand the issue and take corrective action, ensuring a smooth and frustration-free experience.
Loading State
To provide visual feedback during the submission process, a loading state is implemented. While the scenario is being saved, the submit button is disabled, and a spinner is displayed. This prevents duplicate submissions and indicates that the system is actively processing the request, enhancing the user's understanding of the system's state.
UX Features: Enhancing User Experience
Several UX features are integrated into the modal to enhance the user experience, making scenario creation more intuitive and efficient.
Pre-filled Book Context
The modal pre-fills the book context, passing the book's details from the Book Detail page. This eliminates the need for users to manually enter the book information, streamlining the creation process and ensuring consistency. The pre-filled context makes the modal a natural extension of the book exploration workflow.
Modal Close on Escape Key
The modal can be closed by pressing the Escape key. If the form is dirty (i.e., changes have been made), a confirmation prompt is displayed, preventing accidental data loss. This feature enhances usability and provides a safety net for users who may inadvertently trigger the modal's closure.
Focus Management
Focus management is implemented to improve accessibility and user flow. When the modal opens, focus is automatically set to the title field, guiding users to the first required input. This small detail makes a significant difference in the overall user experience, ensuring a smooth and intuitive interaction.
Mobile Responsiveness
The modal is designed to be mobile responsive, adapting to different screen sizes. On devices with a width less than 768px, the modal transitions to a fullscreen display, providing an optimal viewing and interaction experience on smaller screens. This responsiveness ensures that the modal is accessible and usable on a wide range of devices.
Keyboard Shortcuts
To enhance efficiency, keyboard shortcuts are implemented. Users can submit the form by pressing Cmd+Enter (on macOS) or Ctrl+Enter (on Windows), providing a quick and convenient alternative to clicking the submit button. These shortcuts cater to power users, making the creation process faster and more fluid.
Form Reset
After a successful submission, the form is automatically reset, and the modal closes. This provides a clear indication that the scenario has been created and prepares the modal for the next creation. The automatic reset streamlines the workflow, making it easy for users to create multiple scenarios in succession.
Conclusion
The unified scenario creation modal represents a significant step forward in streamlining the scenario creation process. By incorporating a single-step form, real-time validation, and comprehensive UX features, this modal empowers users to create compelling scenarios with ease and efficiency. Its flexible design, combined with robust validation rules, ensures that each scenario is both creative and well-formed, enhancing the overall storytelling experience.
For further reading on best practices in UI design and user experience, check out Nielsen Norman Group, a trusted resource in the field.