Spaces:
Running
Running
Update index.html
Browse filesUpdated with api calls
- index.html +143 -65
index.html
CHANGED
@@ -158,19 +158,96 @@
|
|
158 |
</section>
|
159 |
|
160 |
<!-- Results Section (Initially Hidden) -->
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
<!-- Market Overview -->
|
176 |
<div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
|
@@ -693,63 +770,64 @@
|
|
693 |
|
694 |
// Main analysis function
|
695 |
async function analyzeMarket() {
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
}
|
702 |
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
// Update progress bar animation
|
710 |
-
let progress = 0;
|
711 |
-
const progressInterval = setInterval(() => {
|
712 |
-
progress += Math.random() * 10;
|
713 |
-
if (progress > 100) progress = 100;
|
714 |
-
competitorProgress.style.width = `${progress}%`;
|
715 |
-
}, 300);
|
716 |
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
750 |
|
751 |
// Function to show market analysis with fetched data
|
752 |
function showMarketAnalysis(product) {
|
|
|
|
|
|
|
753 |
// In a real implementation, this would use actual API data
|
754 |
// For this demo, we'll use sample data that simulates API responses
|
755 |
|
|
|
158 |
</section>
|
159 |
|
160 |
<!-- Results Section (Initially Hidden) -->
|
161 |
+
<!-- The rest of your HTML code continues here -->
|
162 |
+
<!-- Full content merged with backend-connected analyzeMarket function -->
|
163 |
+
|
164 |
+
<!-- Results Section (Initially Hidden) -->
|
165 |
+
<section id="resultsSection" class="hidden">
|
166 |
+
<!-- Sample content block -->
|
167 |
+
<div class="bg-white rounded-xl shadow-md p-6 mt-6">
|
168 |
+
<h2 class="text-2xl font-bold text-gray-800 mb-4" id="productTitle">Market Analysis</h2>
|
169 |
+
<p class="text-sm text-gray-500">Last updated: <span id="dynamicUpdateTime"></span></p>
|
170 |
+
<p class="text-sm text-gray-500">Top Brands: <span id="topBrands">(loading...)</span></p>
|
171 |
+
<p class="text-sm text-gray-500">Competitor Count: <span id="competitorCount">(loading...)</span></p>
|
172 |
+
</div>
|
173 |
+
<!-- Add charts and trend blocks as needed -->
|
174 |
+
</section>
|
175 |
+
|
176 |
+
<script>
|
177 |
+
const productInput = document.getElementById('productInput');
|
178 |
+
const analyzeBtn = document.getElementById('analyzeBtn');
|
179 |
+
const analyzeText = document.getElementById('analyzeText');
|
180 |
+
const analyzeSpinner = document.getElementById('analyzeSpinner');
|
181 |
+
const progressSection = document.getElementById('progressSection');
|
182 |
+
const resultsSection = document.getElementById('resultsSection');
|
183 |
+
const competitorProgress = document.getElementById('competitorProgress');
|
184 |
+
const dynamicUpdateTime = document.getElementById('dynamicUpdateTime');
|
185 |
+
const topBrands = document.getElementById('topBrands');
|
186 |
+
const competitorCount = document.getElementById('competitorCount');
|
187 |
+
const productTitle = document.getElementById('productTitle');
|
188 |
+
|
189 |
+
analyzeBtn.addEventListener('click', analyzeMarket);
|
190 |
+
productInput.addEventListener('keypress', function(e) {
|
191 |
+
if (e.key === 'Enter') analyzeMarket();
|
192 |
+
});
|
193 |
+
|
194 |
+
async function analyzeMarket() {
|
195 |
+
const product = productInput.value.trim().toLowerCase();
|
196 |
+
if (!product) {
|
197 |
+
alert('Please enter a product category');
|
198 |
+
return;
|
199 |
+
}
|
200 |
+
|
201 |
+
analyzeText.textContent = 'Analyzing';
|
202 |
+
analyzeSpinner.classList.remove('hidden');
|
203 |
+
progressSection.classList.remove('hidden');
|
204 |
+
resultsSection.classList.add('hidden');
|
205 |
+
|
206 |
+
let progress = 0;
|
207 |
+
const progressInterval = setInterval(() => {
|
208 |
+
progress += Math.random() * 10;
|
209 |
+
if (progress > 100) progress = 100;
|
210 |
+
competitorProgress.style.width = `${progress}%`;
|
211 |
+
}, 300);
|
212 |
+
|
213 |
+
try {
|
214 |
+
const response = await axios.get(`http://localhost:5000/api/analyze?product=${encodeURIComponent(product)}`);
|
215 |
+
const data = response.data;
|
216 |
+
|
217 |
+
clearInterval(progressInterval);
|
218 |
+
analyzeText.textContent = 'Analyze';
|
219 |
+
analyzeSpinner.classList.add('hidden');
|
220 |
+
progressSection.classList.add('hidden');
|
221 |
+
|
222 |
+
const now = new Date();
|
223 |
+
dynamicUpdateTime.textContent = now.toLocaleDateString('en-US', { month: 'long', year: 'numeric' });
|
224 |
+
|
225 |
+
productTitle.textContent = `${product.charAt(0).toUpperCase() + product.slice(1)} Market Analysis`;
|
226 |
+
if (data.amazonProducts && data.amazonProducts.length) {
|
227 |
+
topBrands.textContent = data.amazonProducts.map(p => p.title.split(' ')[0]).slice(0, 3).join(', ');
|
228 |
+
competitorCount.textContent = data.amazonProducts.length;
|
229 |
+
} else {
|
230 |
+
topBrands.textContent = 'N/A';
|
231 |
+
competitorCount.textContent = 'N/A';
|
232 |
+
}
|
233 |
+
|
234 |
+
resultsSection.classList.remove('hidden');
|
235 |
+
setTimeout(() => {
|
236 |
+
resultsSection.scrollIntoView({ behavior: 'smooth' });
|
237 |
+
}, 100);
|
238 |
+
} catch (error) {
|
239 |
+
console.error('Analysis error:', error);
|
240 |
+
alert('Error analyzing market. Please try again.');
|
241 |
+
analyzeText.textContent = 'Analyze';
|
242 |
+
analyzeSpinner.classList.add('hidden');
|
243 |
+
progressSection.classList.add('hidden');
|
244 |
+
clearInterval(progressInterval);
|
245 |
+
}
|
246 |
+
}
|
247 |
+
</script>
|
248 |
+
</body>
|
249 |
+
</html>
|
250 |
+
|
251 |
|
252 |
<!-- Market Overview -->
|
253 |
<div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
|
|
|
770 |
|
771 |
// Main analysis function
|
772 |
async function analyzeMarket() {
|
773 |
+
const product = productInput.value.trim().toLowerCase();
|
774 |
+
if (!product) {
|
775 |
+
alert('Please enter a product category');
|
776 |
+
return;
|
777 |
+
}
|
|
|
778 |
|
779 |
+
// Show loading state
|
780 |
+
analyzeText.textContent = 'Analyzing';
|
781 |
+
analyzeSpinner.classList.remove('hidden');
|
782 |
+
progressSection.classList.remove('hidden');
|
783 |
+
resultsSection.classList.add('hidden');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
784 |
|
785 |
+
let progress = 0;
|
786 |
+
const progressInterval = setInterval(() => {
|
787 |
+
progress += Math.random() * 10;
|
788 |
+
if (progress > 100) progress = 100;
|
789 |
+
competitorProgress.style.width = `${progress}%`;
|
790 |
+
}, 300);
|
791 |
+
|
792 |
+
try {
|
793 |
+
// 🚀 Real API call to backend
|
794 |
+
const response = await axios.get(`http://localhost:5000/api/analyze?product=${encodeURIComponent(product)}`);
|
795 |
+
const data = response.data;
|
796 |
+
|
797 |
+
clearInterval(progressInterval);
|
798 |
+
analyzeText.textContent = 'Analyze';
|
799 |
+
analyzeSpinner.classList.add('hidden');
|
800 |
+
progressSection.classList.add('hidden');
|
801 |
+
|
802 |
+
// 💡 For now, just log the result
|
803 |
+
console.log(data);
|
804 |
+
|
805 |
+
// Use parts of the response to populate UI
|
806 |
+
document.getElementById('productTitle').textContent = `${product.charAt(0).toUpperCase() + product.slice(1)} Market Analysis`;
|
807 |
+
document.getElementById('dynamicUpdateTime').textContent = new Date().toLocaleDateString('en-US', { month: 'long', year: 'numeric' });
|
808 |
+
|
809 |
+
// If you want to fill out mock UI:
|
810 |
+
updateUI({ ...getDefaultData(product), trends: data.trends, products: data.amazonProducts });
|
811 |
+
|
812 |
+
resultsSection.classList.remove('hidden');
|
813 |
+
setTimeout(() => {
|
814 |
+
resultsSection.scrollIntoView({ behavior: 'smooth' });
|
815 |
+
}, 100);
|
816 |
+
} catch (error) {
|
817 |
+
console.error('Analysis error:', error);
|
818 |
+
alert('Error analyzing market. Please try again.');
|
819 |
+
analyzeText.textContent = 'Analyze';
|
820 |
+
analyzeSpinner.classList.add('hidden');
|
821 |
+
progressSection.classList.add('hidden');
|
822 |
+
clearInterval(progressInterval);
|
823 |
+
}
|
824 |
+
}
|
825 |
|
826 |
// Function to show market analysis with fetched data
|
827 |
function showMarketAnalysis(product) {
|
828 |
+
console.warn("showMarketAnalysis is deprecated. Use analyzeMarket's real data response instead.");
|
829 |
+
}
|
830 |
+
|
831 |
// In a real implementation, this would use actual API data
|
832 |
// For this demo, we'll use sample data that simulates API responses
|
833 |
|