Fix: Resolve code conflicts, remove automations, and improve code fluency#9
Conversation
…toring Co-authored-by: MarcoS9309 <217665993+MarcoS9309@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the codebase to resolve initialization conflicts and improve code maintainability by removing automatic DOMContentLoaded event listeners and standardizing on manual initialization patterns.
Key changes include:
- Replaced automatic initialization with explicit manual initialization functions across all modules
- Fixed navigation URLs to use relative paths that work properly in GitHub Pages subdirectories
- Removed conflicting event delegation code in favor of simpler onclick handlers
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| js/navigation.js | Removed auto-initialization, added smart relative path handling, created manual initNavigation() function |
| js/game.js | Removed conflicting event delegation, simplified initialization with manual initGame() function |
| index.html | Added explicit initialization call for navigation |
| game.html | Added explicit initialization calls for both game and navigation |
| FabulasEmocionales/index.html | Added explicit initialization calls for fábulas and navigation |
| FabulasEmocionales/app.js | Removed event delegation conflicts, added manual initFabulas() function |
Comments suppressed due to low confidence (1)
js/game.js:167
- The global functions create a new game instance on-demand without calling init(), which differs from the explicit initialization pattern used elsewhere. Consider ensuring consistent initialization by calling
gameInstance.init()after creating the instance or requiring explicit initialization before use.
function mostrarPregunta() {
if (!gameInstance) gameInstance = new PsicodramaGame();
gameInstance.mostrarPregunta();
}
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const isInSubfolder = window.location.pathname.includes('/FabulasEmocionales/') || | ||
| window.location.pathname.includes('/ProyectoIntercultural/'); |
There was a problem hiding this comment.
The hardcoded folder names in the path detection logic make the code fragile. Consider using a more robust approach like checking if the current path contains any subdirectory or using a configuration-based approach to define valid subfolder names.
| const isInSubfolder = window.location.pathname.includes('/FabulasEmocionales/') || | |
| window.location.pathname.includes('/ProyectoIntercultural/'); | |
| // Determine if the current path is in a subfolder (i.e., has more than one segment) | |
| const pathSegments = window.location.pathname.split('/').filter(Boolean); | |
| const isInSubfolder = pathSegments.length > 1; |
This PR addresses several issues in the codebase to improve maintainability and resolve conflicts as requested in the issue "Revisa el codigo, corrige errores, conflictos, elimina automatizaciones, mejora su fluidez sin perder contexto."
Problems Fixed
🔧 Removed Automatic Initializations
The codebase had multiple conflicting
DOMContentLoadedevent listeners that were causing initialization issues:PsicodramaGame,FabulasEmocionales, andMarcoNavigationclasses⚡ Resolved Event Handling Conflicts
There were conflicting event handling approaches causing functionality issues:
🔗 Fixed Navigation URL Issues
Navigation URLs were using absolute paths that wouldn't work properly in GitHub Pages:
✨ Improved Code Structure
Key Changes
js/navigation.js:
initNavigation()functionjs/game.js:
initGame()functionFabulasEmocionales/app.js:
initFabulas()functionHTML files:
Testing
All functionality has been thoroughly tested:
- ✅ Navigation works across all pages
- ✅ Psicodrama game generates questions and responses correctly
- ✅ Fábulas system displays appropriate stories based on emotional state
- ✅ Cross-page navigation with correct relative URLs
The code is now cleaner, more maintainable, and follows consistent patterns while preserving all the original creative content and functionality context.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.