-
Notifications
You must be signed in to change notification settings - Fork 0
Implement live AI-generated content and real-time stats on home route #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
bc3b1c5
9c34e82
198c774
5dd4648
29fabcd
bac1078
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||||||||||||||
| import React, { useState, useEffect, useMemo } from 'react'; | ||||||||||||||||||
| import { ICONS, PRODUCTS as INITIAL_PRODUCTS, CATEGORIES, WHATSAPP_NUMBER as INITIAL_WA, ADMIN_PASSCODE, OWNER_PASSCODE, HERO_SLIDES, VISUALS } from './constants'; | ||||||||||||||||||
| import { Product, Message, GroundingSource, Category } from './types'; | ||||||||||||||||||
| import { Product, Message, GroundingSource, Category, HomeContent } from './types'; | ||||||||||||||||||
| import { gemini } from './services/geminiService'; | ||||||||||||||||||
|
|
||||||||||||||||||
| // Helper function to get category-specific gradient pattern | ||||||||||||||||||
|
|
@@ -68,6 +68,14 @@ const App: React.FC = () => { | |||||||||||||||||
| const [isLoading, setIsLoading] = useState(false); | ||||||||||||||||||
| const [isRecording, setIsRecording] = useState(false); | ||||||||||||||||||
|
|
||||||||||||||||||
| // --- HOME CONTENT STATE --- | ||||||||||||||||||
| const [homeContent, setHomeContent] = useState<HomeContent | null>(null); | ||||||||||||||||||
| const [liveStats, setLiveStats] = useState({ | ||||||||||||||||||
| totalProducts: 0, | ||||||||||||||||||
| inStock: 0, | ||||||||||||||||||
| categories: 0 | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| // --- THEME SYNC --- | ||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||
| const root = window.document.documentElement; | ||||||||||||||||||
|
|
@@ -95,6 +103,29 @@ const App: React.FC = () => { | |||||||||||||||||
| return () => window.removeEventListener('scroll', handleScroll); | ||||||||||||||||||
| }, []); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Fetch home content on mount | ||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||
| const fetchHomeData = async () => { | ||||||||||||||||||
| try { | ||||||||||||||||||
| const content = await gemini.fetchHomeContent(); | ||||||||||||||||||
| setHomeContent(content); | ||||||||||||||||||
| } catch (err) { | ||||||||||||||||||
| console.error('Failed to fetch AI-generated home content, using fallback:', err); | ||||||||||||||||||
|
||||||||||||||||||
| console.error('Failed to fetch AI-generated home content, using fallback:', err); | |
| console.error('Failed to fetch home content from Gemini API, using fallback:', err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated error message to specifically reference "Gemini API" for consistency with other error messages. Commit 29fabcd
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AI-generated content is fetched on every page load without any caching mechanism. This results in unnecessary API calls and costs. Consider implementing a caching strategy (e.g., localStorage with TTL, or state management with a refresh mechanism) to avoid redundant API calls when the user navigates between pages or refreshes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented localStorage caching with 24-hour TTL. AI content is now cached and only refetched when cache expires or is invalid, preventing unnecessary API calls. Commit 29fabcd
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The icon mapping could fail silently if the AI returns an icon name that doesn't exist in the ICONS object. When ICONS[feature.icon as keyof typeof ICONS] is undefined, the component renders nothing in the icon container. Consider adding a fallback icon or validation to ensure a consistent UI even when the AI returns unexpected icon names.
| {IconComponent ? <IconComponent className="w-6 h-6 text-nexlyn" /> : null} | |
| {IconComponent ? ( | |
| <IconComponent className="w-6 h-6 text-nexlyn" /> | |
| ) : ( | |
| <span className="w-6 h-6 flex items-center justify-center text-nexlyn text-lg font-bold"> | |
| ? | |
| </span> | |
| )} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Shield icon as fallback when AI returns unknown icon names. This ensures a consistent UI even with unexpected icon values. Commit 29fabcd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import GroundingSource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unused
GroundingSourceimport. Commit 29fabcd