mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 11:51:10 -05:00
Refactor moderation dashboard and advanced search components to utilize Alpine.js for improved state management. Enhanced event handling and user experience by replacing legacy JavaScript functions with Alpine.js reactive methods. Updated auth modal comparison and button comparison tests to leverage Alpine.js for better interactivity and functionality.
This commit is contained in:
@@ -54,7 +54,7 @@
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-gray-50 p-8">
|
||||
<body class="bg-gray-50 p-8" x-data="componentTestSuite()">
|
||||
<div class="max-w-6xl mx-auto">
|
||||
<h1 class="text-3xl font-bold mb-8 text-center">UI Component Comparison Test</h1>
|
||||
<p class="text-center text-gray-600 mb-8">Comparing old include method vs new cotton component method for Button, Input, and Card components</p>
|
||||
@@ -582,73 +582,95 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Alpine.js -->
|
||||
<script src="{% static 'js/alpine.min.js' %}" defer></script>
|
||||
|
||||
<script>
|
||||
// Function to normalize HTML for comparison
|
||||
function normalizeHTML(html) {
|
||||
return html
|
||||
.replace(/\s+/g, ' ')
|
||||
.replace(/> </g, '><')
|
||||
.trim();
|
||||
}
|
||||
document.addEventListener('alpine:init', () => {
|
||||
// Component Test Suite Component
|
||||
Alpine.data('componentTestSuite', () => ({
|
||||
init() {
|
||||
// Extract HTML after Alpine.js initializes
|
||||
this.$nextTick(() => {
|
||||
setTimeout(() => this.extractComponentHTML(), 100);
|
||||
this.addCompareButton();
|
||||
});
|
||||
},
|
||||
|
||||
// Function to extract HTML from all component containers
|
||||
function extractComponentHTML() {
|
||||
const containers = document.querySelectorAll('.button-container');
|
||||
const includeHTMLs = [];
|
||||
const cottonHTMLs = [];
|
||||
let componentIndex = 1;
|
||||
// Function to normalize HTML for comparison
|
||||
normalizeHTML(html) {
|
||||
return html
|
||||
.replace(/\s+/g, ' ')
|
||||
.replace(/> </g, '><')
|
||||
.trim();
|
||||
},
|
||||
|
||||
containers.forEach((container, index) => {
|
||||
const label = container.getAttribute('data-label');
|
||||
// Look for button, input, or div (card) elements
|
||||
const element = container.querySelector('button') ||
|
||||
container.querySelector('input') ||
|
||||
container.querySelector('div.rounded-lg');
|
||||
|
||||
if (element && label) {
|
||||
const html = element.outerHTML;
|
||||
const normalized = normalizeHTML(html);
|
||||
// Function to extract HTML from all component containers
|
||||
extractComponentHTML() {
|
||||
const containers = this.$el.querySelectorAll('.button-container');
|
||||
const includeHTMLs = [];
|
||||
const cottonHTMLs = [];
|
||||
let componentIndex = 1;
|
||||
|
||||
containers.forEach((container, index) => {
|
||||
const label = container.getAttribute('data-label');
|
||||
// Look for button, input, or div (card) elements
|
||||
const element = container.querySelector('button') ||
|
||||
container.querySelector('input') ||
|
||||
container.querySelector('div.rounded-lg');
|
||||
|
||||
if (element && label) {
|
||||
const html = element.outerHTML;
|
||||
const normalized = this.normalizeHTML(html);
|
||||
|
||||
if (label === 'Include Version') {
|
||||
includeHTMLs.push(`<!-- Component ${componentIndex} -->\n${normalized}\n`);
|
||||
} else if (label === 'Cotton Version') {
|
||||
cottonHTMLs.push(`<!-- Component ${componentIndex} -->\n${normalized}\n`);
|
||||
componentIndex++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const includeElement = this.$el.querySelector('#include-html');
|
||||
const cottonElement = this.$el.querySelector('#cotton-html');
|
||||
|
||||
if (label === 'Include Version') {
|
||||
includeHTMLs.push(`<!-- Component ${componentIndex} -->\n${normalized}\n`);
|
||||
} else if (label === 'Cotton Version') {
|
||||
cottonHTMLs.push(`<!-- Component ${componentIndex} -->\n${normalized}\n`);
|
||||
componentIndex++;
|
||||
if (includeElement) includeElement.textContent = includeHTMLs.join('\n');
|
||||
if (cottonElement) cottonElement.textContent = cottonHTMLs.join('\n');
|
||||
},
|
||||
|
||||
// Function to compare HTML outputs
|
||||
compareHTML() {
|
||||
const includeHTML = this.$el.querySelector('#include-html')?.textContent || '';
|
||||
const cottonHTML = this.$el.querySelector('#cotton-html')?.textContent || '';
|
||||
|
||||
if (includeHTML === cottonHTML) {
|
||||
this.$dispatch('comparison-result', {
|
||||
success: true,
|
||||
message: '✅ HTML outputs are identical!'
|
||||
});
|
||||
} else {
|
||||
this.$dispatch('comparison-result', {
|
||||
success: false,
|
||||
message: '❌ HTML outputs differ. Check the HTML Output section for details.',
|
||||
includeHTML,
|
||||
cottonHTML
|
||||
});
|
||||
console.log('Include HTML:', includeHTML);
|
||||
console.log('Cotton HTML:', cottonHTML);
|
||||
}
|
||||
},
|
||||
|
||||
// Add compare button
|
||||
addCompareButton() {
|
||||
const compareBtn = document.createElement('button');
|
||||
compareBtn.textContent = 'Compare HTML Outputs';
|
||||
compareBtn.className = 'fixed bottom-4 right-4 bg-blue-500 text-white px-4 py-2 rounded shadow-lg hover:bg-blue-600';
|
||||
compareBtn.addEventListener('click', () => this.compareHTML());
|
||||
document.body.appendChild(compareBtn);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('include-html').textContent = includeHTMLs.join('\n');
|
||||
document.getElementById('cotton-html').textContent = cottonHTMLs.join('\n');
|
||||
}
|
||||
|
||||
// Extract HTML after page loads
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
setTimeout(extractComponentHTML, 100);
|
||||
});
|
||||
|
||||
// Function to compare HTML outputs
|
||||
function compareHTML() {
|
||||
const includeHTML = document.getElementById('include-html').textContent;
|
||||
const cottonHTML = document.getElementById('cotton-html').textContent;
|
||||
|
||||
if (includeHTML === cottonHTML) {
|
||||
alert('✅ HTML outputs are identical!');
|
||||
} else {
|
||||
alert('❌ HTML outputs differ. Check the HTML Output section for details.');
|
||||
console.log('Include HTML:', includeHTML);
|
||||
console.log('Cotton HTML:', cottonHTML);
|
||||
}
|
||||
}
|
||||
|
||||
// Add compare button
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const compareBtn = document.createElement('button');
|
||||
compareBtn.textContent = 'Compare HTML Outputs';
|
||||
compareBtn.className = 'fixed bottom-4 right-4 bg-blue-500 text-white px-4 py-2 rounded shadow-lg hover:bg-blue-600';
|
||||
compareBtn.onclick = compareHTML;
|
||||
document.body.appendChild(compareBtn);
|
||||
}));
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user