@@ -37,17 +37,29 @@ <h1>Explore</h1>
3737
3838 < div id ="shop " class ="explore-box ">
3939 < div class ="cookie-display ">
40- < p > Current Balance: 100🍪</ p >
40+ < p id ="cookie-display "> Current Balance: 100🍪</ p >
41+ </ div >
42+ < div class ="goal-toggle ">
43+ < button onclick ="toggleGoals() "> Toggle goals</ button >
4144 </ div >
4245 < div id ="goals " class ="shop-item-box goals-grid "> </ div >
4346 < div >
44- < div >
45- < input
46- type ="text "
47- placeholder ="search shop item "
48- class ="explore-input "
49- oninput ="updateQuery(this) "
50- />
47+ < div class ="explore-input-box ">
48+ < input
49+ id ="shop-query "
50+ type ="text "
51+ placeholder ="search shop item "
52+ class ="explore-input "
53+ oninput ="updateQuery(this) "
54+ />
55+ < button
56+ class ="explore-clear-query "
57+ type ="button "
58+ aria-label ="Clear search "
59+ onclick ="clearQuery() "
60+ >
61+ < i class ="codicon codicon-close "> </ i >
62+ </ button >
5163 </ div >
5264
5365 < div class ="explore-filters ">
@@ -188,13 +200,18 @@ <h3>price history</h3>
188200 var chart = null ;
189201 var goals = [ ] ;
190202 var goalAmounts = { } ;
203+ var goalsHidden = false ;
191204
192205 // user
193206 var users = { } ;
194207
195208 // project
196209 var projects = { } ;
197210
211+ // retrive cache
212+ retriveCacheState ( ) ;
213+ handleShopLoad ( ) ;
214+
198215 // general functions
199216
200217 function setTheme ( theme ) {
@@ -241,6 +258,19 @@ <h3>price history</h3>
241258 }
242259 }
243260
261+ // cache functions
262+ function cacheState ( state ) {
263+ vscode . setState ( { cache : state } ) ;
264+ }
265+
266+ function retriveCacheState ( ) {
267+ const state = vscode . getState ( ) ;
268+ shopItems = state ?. cache ?. shopItems ;
269+ userData = state ?. cache ?. userData ;
270+ goals = state ?. cache ?. goals ;
271+ goalsHidden = state ?. cache ?. goalsHidden ;
272+ }
273+
244274 function escapeHtml ( value ) {
245275 if ( ! value ) return "" ;
246276
@@ -350,6 +380,14 @@ <h3>price history</h3>
350380
351381 function handleShopLoad ( ) {
352382 if ( shopItems && goals && userData ) {
383+ // cache state
384+ cacheState ( {
385+ shopItems : shopItems ,
386+ userData : userData ,
387+ goals : goals ,
388+ goalsHidden : goalsHidden ,
389+ } ) ;
390+
353391 populateShop ( ) ;
354392 populateGoals ( ) ;
355393 }
@@ -362,6 +400,9 @@ <h3>price history</h3>
362400 return item . name ;
363401 } ) ;
364402
403+ document . getElementById ( "cookie-display" ) . textContent =
404+ `Current Balance: ${ userData . cookies ?? 0 } 🍪` ;
405+
365406 const fuse = new Fuse ( shopItemsNameArray , { includeScore : true } ) ;
366407
367408 // Get matching names once
@@ -426,19 +467,27 @@ <h3>price history</h3>
426467
427468 // filters display
428469 . filter ( ( item ) => {
470+ const price =
471+ item . ticket_cost ?. [ region ] ?? item . ticket_cost ?. base_cost ?? 0 ;
472+
429473 if ( display === "all" ) {
430474 return true ;
431475 }
432476
433- if (
434- display === "affordable" &&
435- item . ticket_cost ?. [ region ] <= ( userData . cookies ?? 0 )
436- ) {
437- return true ;
477+ if ( display === "affordable" ) {
478+ if ( price <= ( userData . cookies ?? 0 ) ) {
479+ return true ;
480+ } else {
481+ return false ;
482+ }
438483 }
439484
440- if ( display === "in-stock" && ( item . stock ?? 0 ) >= 1 ) {
441- return true ;
485+ if ( display === "in-stock" ) {
486+ if ( ( item . stock ?? 0 ) >= 1 || ! item . limited ) {
487+ return true ;
488+ } else {
489+ return false ;
490+ }
442491 }
443492
444493 if ( display === "sale" ) {
@@ -701,6 +750,18 @@ <h2>${item.name}</h2>
701750 populateShop ( ) ;
702751 }
703752
753+ function clearQuery ( ) {
754+ const input = document . getElementById ( "shop-query" ) ;
755+ if ( ! input ) {
756+ return ;
757+ }
758+
759+ input . value = "" ;
760+ shopQuery = "" ;
761+ populateShop ( ) ;
762+ input . focus ( ) ;
763+ }
764+
704765 function updateExtension ( circleId , containerId , price ) {
705766 const container = document . getElementById (
706767 `extension-container${ containerId } ` ,
@@ -752,7 +813,9 @@ <h2>${item.name}</h2>
752813 goalContainer . innerHTML = uniqueGoals
753814 . map ( ( goal ) => {
754815 if ( shopItems [ goal ] ) {
755- const amount = goals . filter ( ( item ) => Number ( item ) === goal ) . length ;
816+ const amount = goals . filter (
817+ ( item ) => Number ( item ) === goal ,
818+ ) . length ;
756819 goalAmounts [ goal ] = amount ;
757820 const item = shopItems [ goal ] ;
758821 const price =
@@ -779,11 +842,22 @@ <h2>${item.name}</h2>
779842 </div>
780843 <button class="goal-delete-button" onclick='deleteGoal(${ goal } )'><i class="codicon codicon-trash"></i></button>
781844 </div>` ;
845+
782846 }
783847 } )
784848 . join ( "" ) ;
785849 }
786850
851+ function toggleGoals ( ) {
852+ if ( goalsHidden ) {
853+ goalContainer . style . display = "" ;
854+ goalsHidden = ! goalsHidden ;
855+ } else {
856+ goalContainer . style . display = "none" ;
857+ goalsHidden = ! goalsHidden ;
858+ }
859+ }
860+
787861 function handleAddGoal ( id ) {
788862 const goalId = Number ( id ) ;
789863
@@ -792,19 +866,17 @@ <h2>${item.name}</h2>
792866 }
793867
794868 if ( goals . includes ( goalId ) ) {
795- goals = goals . filter ( ( goal ) => Number ( goal ) !== goalId ) ;
796869 document . getElementById ( `favourite-${ id } ` ) . className = "favourite" ;
797870 document . getElementById ( `favourite-icon-${ id } ` ) . className =
798871 "codicon codicon-star-empty" ;
799872 } else {
800- goals . push ( goalId ) ;
801873 document . getElementById ( `favourite-${ id } ` ) . className =
802874 "favourite-active favourite" ;
803875 document . getElementById ( `favourite-icon-${ id } ` ) . className =
804876 "codicon codicon-star-full" ;
805877 }
806878
807- vscode . postMessage ( { command : "put-goal" , value : goals } ) ;
879+ vscode . postMessage ( { command : "put-goal" , value : } ) ;
808880 populateGoals ( ) ;
809881 }
810882
@@ -919,6 +991,7 @@ <h2>${item.name}</h2>
919991 }
920992 case "user-data" : {
921993 userData = message . value ;
994+ handleShopLoad ( ) ;
922995 break ;
923996 }
924997 case "goals" : {
0 commit comments