@@ -1055,9 +1055,37 @@ <h3>${proj.title}</h3>
10551055animateCounter ( "statsGames" , games ) ;
10561056animateCounter ( "statsMath" , math ) ;
10571057animateCounter ( "statsUtilities" , utils ) ;
1058- const viewed = JSON . parse ( localStorage . getItem ( "recentProjects" ) || "[]" ) ;
1059- animateCounter ( "heroViewedCount" , viewed . length ) ;
1060-
1058+ // === FIX: Recently Viewed Counter ===
1059+ const viewed = JSON . parse ( localStorage . getItem ( "recentlyViewed" ) || "[]" ) ;
1060+ const heroCounter = document . getElementById ( "heroViewedCount" ) ;
1061+ if ( heroCounter ) {
1062+ heroCounter . textContent = viewed . length ;
1063+ }
1064+
1065+ // Function to update counter when projects are viewed
1066+ function updateRecentlyViewedCounter ( ) {
1067+ const viewed = JSON . parse ( localStorage . getItem ( "recentlyViewed" ) || "[]" ) ;
1068+ const heroCounter = document . getElementById ( "heroViewedCount" ) ;
1069+ if ( heroCounter ) {
1070+ heroCounter . textContent = viewed . length ;
1071+ }
1072+ // Also update the grid if the function exists
1073+ if ( window . renderRecentlyViewedGrid ) {
1074+ window . renderRecentlyViewedGrid ( ) ;
1075+ }
1076+ return viewed . length ;
1077+ }
1078+ window . updateRecentlyViewedCounter = updateRecentlyViewedCounter ;
1079+
1080+ // Watch for changes to localStorage
1081+ const originalSetItem = localStorage . setItem ;
1082+ localStorage . setItem = function ( key , value ) {
1083+ originalSetItem . apply ( this , arguments ) ;
1084+ if ( key === "recentlyViewed" ) {
1085+ setTimeout ( updateRecentlyViewedCounter , 50 ) ;
1086+ }
1087+ } ;
1088+ // === END FIX ===
10611089 console . log (
10621090 `✅ Loaded ${ total } projects: ${ games } games, ${ math } math, ${ utils } utilities`
10631091 ) ;
@@ -1066,14 +1094,20 @@ <h3>${proj.title}</h3>
10661094 setTimeout ( ( ) => {
10671095 // Play buttons
10681096 document . querySelectorAll ( ".btn-play" ) . forEach ( ( btn ) => {
1069- btn . addEventListener ( "click" , ( e ) => {
1070- e . stopPropagation ( ) ;
1071- const projectName = btn . getAttribute ( "data-project" ) ;
1072- if ( projectName && window . openProjectSafe ) {
1073- window . openProjectSafe ( projectName , btn ) ;
1074- }
1075- } ) ;
1076- } ) ;
1097+ btn . addEventListener ( "click" , ( e ) => {
1098+ e . stopPropagation ( ) ;
1099+ const projectName = btn . getAttribute ( "data-project" ) ;
1100+ if ( projectName && window . openProjectSafe ) {
1101+ window . openProjectSafe ( projectName , btn ) ;
1102+ // Update counter after opening project
1103+ setTimeout ( ( ) => {
1104+ if ( window . updateRecentlyViewedCounter ) {
1105+ window . updateRecentlyViewedCounter ( ) ;
1106+ }
1107+ } , 200 ) ;
1108+ }
1109+ } ) ;
1110+ } ) ;
10771111
10781112 // Favorite buttons
10791113 document . querySelectorAll ( ".btn-favorite" ) . forEach ( ( btn ) => {
@@ -1203,7 +1237,34 @@ <h3>${proj.title}</h3>
12031237 } ;
12041238 console . log ( '✅ toPascalCase function added' ) ;
12051239 }
1206-
1240+ // Complete recently viewed update
1241+ function refreshRecentlyViewed ( ) {
1242+ const viewed = JSON . parse ( localStorage . getItem ( "recentlyViewed" ) || "[]" ) ;
1243+ const grid = document . getElementById ( "recentlyViewedGrid" ) ;
1244+
1245+ // Update counter
1246+ const heroCounter = document . getElementById ( "heroViewedCount" ) ;
1247+ if ( heroCounter ) {
1248+ heroCounter . textContent = viewed . length ;
1249+ }
1250+
1251+ // Update grid (if you want to refresh it too)
1252+ if ( grid && window . renderRecentlyViewedGrid ) {
1253+ window . renderRecentlyViewedGrid ( ) ;
1254+ }
1255+ }
1256+ // Function to update recently viewed counter
1257+ function updateRecentlyViewedCounter ( ) {
1258+ const viewed = JSON . parse ( localStorage . getItem ( "recentlyViewed" ) || "[]" ) ;
1259+ const heroCounter = document . getElementById ( "heroViewedCount" ) ;
1260+ if ( heroCounter ) {
1261+ heroCounter . textContent = viewed . length ;
1262+ }
1263+ return viewed . length ;
1264+ }
1265+
1266+ // Make it globally accessible
1267+ window . updateRecentlyViewedCounter = updateRecentlyViewedCounter ;
12071268 // FIX 2: Fix modal focus error
12081269 setTimeout ( function ( ) {
12091270 const modal = document . getElementById ( 'projectModal' ) ;
0 commit comments