Files changed (1) hide show
  1. index.html +143 -65
index.html CHANGED
@@ -158,19 +158,96 @@
158
  </section>
159
 
160
  <!-- Results Section (Initially Hidden) -->
161
- <section id="resultsSection" class="hidden">
162
- <!-- Data Sources Info -->
163
- <div class="bg-blue-50 rounded-lg p-4 mb-6">
164
- <div class="flex items-center">
165
- <div class="p-2 rounded-full bg-blue-100 text-blue-600 mr-4">
166
- <i class="fas fa-database"></i>
167
- </div>
168
- <div>
169
- <h3 class="font-medium">Data Sources</h3>
170
- <p class="text-sm text-gray-600" id="dataSources">Aggregated from 12 sources including Amazon, Walmart, Google Trends, and Statista. Last updated: <span id="dynamicUpdateTime"></span></p>
171
- </div>
172
- </div>
173
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- const product = productInput.value.trim().toLowerCase();
697
-
698
- if (!product) {
699
- alert('Please enter a product category');
700
- return;
701
- }
702
 
703
- // Show loading state
704
- analyzeText.textContent = 'Analyzing';
705
- analyzeSpinner.classList.remove('hidden');
706
- progressSection.classList.remove('hidden');
707
- resultsSection.classList.add('hidden');
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
- // Simulate API calls (in a real app, these would be actual API calls)
718
- try {
719
- // Get current time for "last updated" display
720
- const now = new Date();
721
- const options = { month: 'long', year: 'numeric' };
722
- dynamicUpdateTime.textContent = now.toLocaleDateString('en-US', options);
723
-
724
- // Simulate data fetching delay
725
- await new Promise(resolve => setTimeout(resolve, 2500));
726
-
727
- // Clear loading state
728
- clearInterval(progressInterval);
729
- analyzeText.textContent = 'Analyze';
730
- analyzeSpinner.classList.add('hidden');
731
- progressSection.classList.add('hidden');
732
-
733
- // Show results with the appropriate data
734
- showMarketAnalysis(product);
735
-
736
- // Scroll to results
737
- setTimeout(() => {
738
- resultsSection.scrollIntoView({ behavior: 'smooth' });
739
- }, 100);
740
-
741
- } catch (error) {
742
- console.error('Analysis error:', error);
743
- alert('Error analyzing market. Please try again.');
744
- analyzeText.textContent = 'Analyze';
745
- analyzeSpinner.classList.add('hidden');
746
- progressSection.classList.add('hidden');
747
- clearInterval(progressInterval);
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