@@ -61,6 +61,7 @@ import "slick-carousel/slick/slick-theme.css";
6161import "./Testimonials.scss" ;
6262import TestimonialsItem from "./TestimonialsItem" ;
6363import config from "../../config/config" ;
64+ import { mockAPI } from "../../utils/mockData" ;
6465
6566const Testimonials = ( ) => {
6667 const [ productsState , setProductsState ] = useState ( {
@@ -73,22 +74,27 @@ const Testimonials = () => {
7374 const fetchData = async ( ) => {
7475 setProductsState ( ( prev ) => ( { ...prev , isLoading : true } ) ) ;
7576 try {
76- const token = localStorage . getItem ( "access" ) ;
77- if ( token ) {
78- const settingsResponse = await axios . get (
79- `${ config . apiUrl } /api/recommendation-settings/` ,
80- { headers : { Authorization : `Bearer ${ token } ` } }
81- ) ;
82- const algorithm =
83- settingsResponse . data . active_algorithm || "collaborative" ;
84- setProductsState ( ( prev ) => ( {
85- ...prev ,
86- currentAlgorithm : algorithm ,
87- } ) ) ;
88-
89- await fetchProducts ( algorithm , token ) ;
90- } else {
77+ if ( config . useMockData ) {
78+ // Use mock data for GitHub Pages
9179 await fetchProducts ( null , null ) ;
80+ } else {
81+ const token = localStorage . getItem ( "access" ) ;
82+ if ( token ) {
83+ const settingsResponse = await axios . get (
84+ `${ config . apiUrl } /api/recommendation-settings/` ,
85+ { headers : { Authorization : `Bearer ${ token } ` } } ,
86+ ) ;
87+ const algorithm =
88+ settingsResponse . data . active_algorithm || "collaborative" ;
89+ setProductsState ( ( prev ) => ( {
90+ ...prev ,
91+ currentAlgorithm : algorithm ,
92+ } ) ) ;
93+
94+ await fetchProducts ( algorithm , token ) ;
95+ } else {
96+ await fetchProducts ( null , null ) ;
97+ }
9298 }
9399 } catch ( error ) {
94100 console . error ( "Error in initial fetch:" , error ) ;
@@ -135,11 +141,20 @@ const Testimonials = () => {
135141
136142 const fetchProducts = async ( algorithm , token ) => {
137143 try {
144+ if ( config . useMockData ) {
145+ const data = await mockAPI . getRandomProducts ( 8 ) ;
146+ setProductsState ( ( prev ) => ( {
147+ ...prev ,
148+ products : data ,
149+ } ) ) ;
150+ return ;
151+ }
152+
138153 if ( token && algorithm ) {
139154 try {
140155 const previewResponse = await axios . get (
141156 `${ config . apiUrl } /api/recommendation-preview/?algorithm=${ algorithm } ` ,
142- { headers : { Authorization : `Bearer ${ token } ` } }
157+ { headers : { Authorization : `Bearer ${ token } ` } } ,
143158 ) ;
144159
145160 if ( previewResponse . data && previewResponse . data . length > 0 ) {
@@ -190,10 +205,10 @@ const Testimonials = () => {
190205 return productsState . currentAlgorithm === "collaborative"
191206 ? "Personalized Recommendations (Collaborative Filtering)"
192207 : productsState . currentAlgorithm === "content_based"
193- ? "Personalized Recommendations (Content-Based)"
194- : productsState . currentAlgorithm === "fuzzy_logic"
195- ? "Personalized Recommendations (Fuzzy Logic)"
196- : "Personalized Recommendations" ;
208+ ? "Personalized Recommendations (Content-Based)"
209+ : productsState . currentAlgorithm === "fuzzy_logic"
210+ ? "Personalized Recommendations (Fuzzy Logic)"
211+ : "Personalized Recommendations" ;
197212 }
198213 return "Discover Our Products" ;
199214 } ;
@@ -203,10 +218,10 @@ const Testimonials = () => {
203218 return productsState . currentAlgorithm === "collaborative"
204219 ? "Based on what users like you are buying"
205220 : productsState . currentAlgorithm === "content_based"
206- ? "Based on products similar to your preferences"
207- : productsState . currentAlgorithm === "fuzzy_logic"
208- ? "Based on fuzzy logic matching your preferences with uncertainty modeling"
209- : "Based on your shopping patterns" ;
221+ ? "Based on products similar to your preferences"
222+ : productsState . currentAlgorithm === "fuzzy_logic"
223+ ? "Based on fuzzy logic matching your preferences with uncertainty modeling"
224+ : "Based on your shopping patterns" ;
210225 }
211226 return "Check out selected proposals from our product database – scroll to see more and test our recommendation system in action!" ;
212227 } ;
0 commit comments