Skip to content

Fix: Resolve code conflicts, remove automations, and improve code fluency#9

Merged
MarcoS9309 merged 2 commits into
mainfrom
copilot/fix-77c868f1-02a0-4a25-8259-892a2d2f2a63
Aug 31, 2025
Merged

Fix: Resolve code conflicts, remove automations, and improve code fluency#9
MarcoS9309 merged 2 commits into
mainfrom
copilot/fix-77c868f1-02a0-4a25-8259-892a2d2f2a63

Conversation

Copilot AI commented Aug 31, 2025

Copy link
Copy Markdown
Contributor

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 DOMContentLoaded event listeners that were causing initialization issues:

  • Removed auto-initialization from PsicodramaGame, FabulasEmocionales, and MarcoNavigation classes
  • Replaced with explicit manual initialization functions
  • Added controlled initialization in HTML files to prevent conflicts

⚡ Resolved Event Handling Conflicts

There were conflicting event handling approaches causing functionality issues:

  • Before: Mixed onclick handlers in HTML with event delegation in JavaScript
  • After: Standardized on onclick handlers for simplicity and reliability
  • Removed redundant event delegation code that was interfering with onclick functionality

🔗 Fixed Navigation URL Issues

Navigation URLs were using absolute paths that wouldn't work properly in GitHub Pages:

// Before: Absolute paths
url: "/index.html"

// After: Smart relative paths
const basePath = isInSubfolder ? '../' : './';
url: basePath + "index.html"

✨ Improved Code Structure

  • Consistent initialization patterns across all modules
  • Better separation of concerns
  • Cleaner global function management
  • Reduced code complexity while preserving functionality

Key Changes

js/navigation.js:

  • Removed auto-initialization
  • Fixed URL paths to work from subfolders
  • Added manual initNavigation() function

js/game.js:

  • Removed conflicting event delegation
  • Simplified to work with onclick handlers
  • Added manual initGame() function

FabulasEmocionales/app.js:

  • Removed event delegation conflicts
  • Streamlined initialization
  • Added manual initFabulas() function

HTML files:

  • Added explicit initialization calls
  • Maintained all existing functionality

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
![Homepage with working navigation](https://github.com/user-attachments/assets/0441e1e9-8cf7-4147-a442-dbf71195f475)

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.

…toring

Co-authored-by: MarcoS9309 <217665993+MarcoS9309@users.noreply.github.com>
Copilot AI changed the title [WIP] Revisa el codigo, corrige errores, conflictos, elimina automatizaciones, mejora su fluidez sinperder contexto. Fix: Resolve code conflicts, remove automations, and improve code fluency Aug 31, 2025
Copilot AI requested a review from MarcoS9309 August 31, 2025 14:26
@MarcoS9309 MarcoS9309 marked this pull request as ready for review August 31, 2025 14:48
Copilot AI review requested due to automatic review settings August 31, 2025 14:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread js/navigation.js
Comment on lines +10 to +11
const isInSubfolder = window.location.pathname.includes('/FabulasEmocionales/') ||
window.location.pathname.includes('/ProyectoIntercultural/');

Copilot AI Aug 31, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
@MarcoS9309 MarcoS9309 merged commit 5e1d24c into main Aug 31, 2025
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants