@@ -20,7 +20,6 @@ import { InferenceFiltersForm } from "./FilterSidebarComponents";
2020import { getFingerprint } from "@thumbmarkjs/thumbmarkjs" ;
2121import { createPortal } from "react-dom" ;
2222
23-
2423const SearchPage = ( ) => {
2524 const { props } = useModalState ( ) ;
2625 if ( ! props . searchPageProps ?. display ) return null ;
@@ -44,16 +43,22 @@ const SearchPage = () => {
4443} ;
4544
4645function findCartChanges ( oldCart : any , newCart : any ) {
47- if ( ! oldCart . items ) return { added : newCart . items . map ( ( item : any ) => item . variant_id ) , removed : [ ] } ;
48- const onlyInLeft = ( l : any , r : any ) => l . filter ( ( li : any ) => ! r . some ( ( ri : any ) => li . key == ri . key ) ) ;
46+ if ( ! oldCart . items )
47+ return {
48+ added : newCart . items . map ( ( item : any ) => item . variant_id ) ,
49+ removed : [ ] ,
50+ } ;
51+ const onlyInLeft = ( l : any , r : any ) =>
52+ l . filter ( ( li : any ) => ! r . some ( ( ri : any ) => li . key == ri . key ) ) ;
4953 const result = {
5054 added : onlyInLeft ( newCart . items , oldCart . items ) ,
5155 removed : onlyInLeft ( oldCart . items , newCart . items ) ,
5256 } ;
5357
54-
5558 oldCart . items . forEach ( ( oi : any ) => {
56- const ni = newCart . items . find ( ( i : any ) => i . key == oi . key && i . quantity != oi . quantity ) ;
59+ const ni = newCart . items . find (
60+ ( i : any ) => i . key == oi . key && i . quantity != oi . quantity ,
61+ ) ;
5762 if ( ! ni ) return ;
5863 const quantity = ni . quantity - oi . quantity ;
5964 const item = { ...ni } ;
@@ -65,7 +70,6 @@ function findCartChanges(oldCart: any, newCart: any) {
6570 }
6671 } ) ;
6772
68-
6973 return result ;
7074}
7175
@@ -131,29 +135,41 @@ const Modal = () => {
131135
132136 const cartObserver = new PerformanceObserver ( ( list ) => {
133137 list . getEntries ( ) . forEach ( ( entry ) => {
134- const isValidRequestType = [ 'xmlhttprequest' , 'fetch' ] . includes ( ( entry as any ) . initiatorType ) ;
138+ const isValidRequestType = [ "xmlhttprequest" , "fetch" ] . includes (
139+ ( entry as any ) . initiatorType ,
140+ ) ;
135141 const isCartChangeRequest = / \/ c a r t \/ a d d \. j s / . test ( entry . name ) ;
136142 if ( isValidRequestType && isCartChangeRequest ) {
137143 ( async function ( ) {
138- const oldCart = JSON . parse ( localStorage . getItem ( 'trieve-cart' ) ?? '{}' ) ;
139- const newCart = await fetch ( ( window as any ) . Shopify . routes . root + 'cart.js' )
140- . then ( response => response . json ( ) )
141- . then ( data => {
142- localStorage . setItem ( 'trieve-cart' , JSON . stringify ( data ) ) ;
144+ const oldCart = JSON . parse (
145+ localStorage . getItem ( "trieve-cart" ) ?? "{}" ,
146+ ) ;
147+ const newCart = await fetch (
148+ ( window as any ) . Shopify . routes . root + "cart.js" ,
149+ )
150+ . then ( ( response ) => response . json ( ) )
151+ . then ( ( data ) => {
152+ localStorage . setItem ( "trieve-cart" , JSON . stringify ( data ) ) ;
143153 return data ;
144154 } ) ;
145155
146156 const cartChanges = findCartChanges ( oldCart , newCart ) ;
147157
148- const items = cartChanges . added . map ( ( item : any ) => item . toString ( ) ) ;
158+ const items = cartChanges . added . map ( ( item : any ) =>
159+ item . toString ( ) ,
160+ ) ;
149161 console . log ( "cartItems" , items ) ;
150162
151163 if ( items . length > 0 ) {
152- const lastMessage = JSON . parse ( window . localStorage . getItem ( "lastMessage" ) ?? "{}" ) ;
164+ const lastMessage = JSON . parse (
165+ window . localStorage . getItem ( "lastMessage" ) ?? "{}" ,
166+ ) ;
153167 let requestId = "00000000-0000-0000-0000-000000000000" ;
154168 for ( const id in lastMessage ) {
155169 const storedItems = lastMessage [ id ] ;
156- if ( storedItems . some ( ( item : any ) => items . includes ( item ) ) ) {
170+ if (
171+ storedItems . some ( ( item : any ) => items . includes ( item ) )
172+ ) {
157173 requestId = id ;
158174 break ;
159175 }
@@ -197,28 +213,35 @@ const Modal = () => {
197213
198214 checkout . addEventListener ( "click" , ( ) => {
199215 ( async function ( ) {
200- const checkoutItems = await fetch ( ( window as any ) . Shopify . routes . root + 'cart.js' )
201- . then ( response => response . json ( ) )
202- . then ( data => {
216+ const checkoutItems = await fetch (
217+ ( window as any ) . Shopify . routes . root + "cart.js" ,
218+ )
219+ . then ( ( response ) => response . json ( ) )
220+ . then ( ( data ) => {
203221 return data ;
204222 } ) ;
205223
224+ const items = checkoutItems . items . map ( ( item : any ) => {
225+ const price = item . final_line_price . toString ( ) ;
226+ return {
227+ tracking_id : item . variant_id . toString ( ) ,
228+ revenue : parseFloat (
229+ price . slice ( 0 , - 2 ) + "." + price . slice ( - 2 ) ,
230+ ) ,
231+ } ;
232+ } ) ;
206233
207- const items = checkoutItems
208- . items
209- . map ( ( item : any ) => {
210- const price = item . final_line_price . toString ( ) ;
211- return {
212- tracking_id : item . variant_id . toString ( ) ,
213- revenue : parseFloat ( price . slice ( 0 , - 2 ) + "." + price . slice ( - 2 ) ) ,
214- } ;
215- } ) ;
216-
217- const lastMessage = JSON . parse ( window . localStorage . getItem ( "lastMessage" ) ?? "{}" ) ;
234+ const lastMessage = JSON . parse (
235+ window . localStorage . getItem ( "lastMessage" ) ?? "{}" ,
236+ ) ;
218237 let requestId = "00000000-0000-0000-0000-000000000000" ;
219238 for ( const id in lastMessage ) {
220239 const storedItems = lastMessage [ id ] ;
221- if ( storedItems . some ( ( item : any ) => items . map ( ( i : any ) => i . tracking_id ) . includes ( item ) ) ) {
240+ if (
241+ storedItems . some ( ( item : any ) =>
242+ items . map ( ( i : any ) => i . tracking_id ) . includes ( item ) ,
243+ )
244+ ) {
222245 requestId = id ;
223246 break ;
224247 }
@@ -482,7 +505,7 @@ export const TrieveModalSearch = (props: ModalProps) => {
482505 document . documentElement . style . setProperty (
483506 "--tv-prop-brand-font-family" ,
484507 props . brandFontFamily ??
485- `Maven Pro, ui-sans-serif, system-ui, sans-serif,
508+ `Maven Pro, ui-sans-serif, system-ui, sans-serif,
486509 "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"` ,
487510 ) ;
488511 } , [ props . brandColor , props . brandFontFamily ] ) ;
0 commit comments