@@ -5,7 +5,6 @@ import ConditionalWrap from 'conditional-wrap';
5
5
6
6
import { Box , Cover , Stack , Text , useForegroundColor } from '@/design-system' ;
7
7
import { ButtonPressAnimation } from '@/components/animations' ;
8
- import { useRemoteCardContext } from './RemoteCardProvider' ;
9
8
import { IS_ANDROID , IS_IOS } from '@/env' ;
10
9
import { useNavigation } from '@/navigation' ;
11
10
import { Language } from '@/languages' ;
@@ -20,6 +19,7 @@ import { FlashList } from '@shopify/flash-list';
20
19
import { ButtonPressAnimationTouchEvent } from '@/components/animations/ButtonPressAnimation/types' ;
21
20
import { TrimmedCard } from '@/resources/cards/cardCollectionQuery' ;
22
21
import RemoteSvg from '@/components/svg/RemoteSvg' ;
22
+ import { remoteCardsStore } from '@/state/remoteCards/remoteCards' ;
23
23
24
24
const ICON_SIZE = 40 ;
25
25
@@ -58,19 +58,17 @@ const getColorFromString = (color: string | undefined | null) => {
58
58
} ;
59
59
60
60
type RemoteCardProps = {
61
- card : TrimmedCard ;
62
- cards : TrimmedCard [ ] ;
61
+ id : string ;
63
62
gutterSize : number ;
64
- carouselRef : React . RefObject < FlashList < TrimmedCard > > | null ;
63
+ carouselRef : React . RefObject < FlashList < string > > | null ;
65
64
} ;
66
65
67
- export const RemoteCard : React . FC < RemoteCardProps > = ( { card = { } as TrimmedCard , cards , gutterSize, carouselRef } ) => {
66
+ export const RemoteCard : React . FC < RemoteCardProps > = ( { id , gutterSize, carouselRef } ) => {
68
67
const { isDarkMode } = useTheme ( ) ;
69
68
const { navigate } = useNavigation ( ) ;
70
69
const { language } = useAccountSettings ( ) ;
71
70
const { width } = useDimensions ( ) ;
72
- const { dismissCard } = useRemoteCardContext ( ) ;
73
-
71
+ const card = remoteCardsStore ( state => state . getCard ( id ) ) ?? ( { } as TrimmedCard ) ;
74
72
const { cardKey, accentColor, backgroundColor, primaryButton, imageIcon } = card ;
75
73
76
74
const accent = useForegroundColor ( getColorFromString ( accentColor ) ) ;
@@ -95,26 +93,25 @@ export const RemoteCard: React.FC<RemoteCardProps> = ({ card = {} as TrimmedCard
95
93
e . stopPropagation ( ) ;
96
94
}
97
95
analyticsV2 . track ( analyticsV2 . event . remoteCardDismissed , {
98
- cardKey : cardKey ?? 'unknown-backend-driven-card' ,
96
+ cardKey : cardKey ?? card . sys . id ?? 'unknown-backend-driven-card' ,
99
97
} ) ;
100
98
101
- const isLastCard = cards . length === 1 ;
99
+ const { cards } = remoteCardsStore . getState ( ) ;
102
100
103
- dismissCard ( card . sys . id ) ;
104
- if ( carouselRef ?. current ) {
105
- const currentCardIdx = cards . findIndex ( c => c . cardKey === cardKey ) ;
106
- if ( currentCardIdx === - 1 ) return ;
101
+ const isLastCard = cards . size === 1 ;
107
102
103
+ remoteCardsStore . getState ( ) . dismissCard ( card . sys . id ) ;
104
+ if ( carouselRef ?. current ) {
108
105
// check if this is the last card and don't scroll if so
109
106
if ( isLastCard ) return ;
110
107
111
108
carouselRef . current . scrollToIndex ( {
112
- index : currentCardIdx ,
109
+ index : Array . from ( cards . values ( ) ) . findIndex ( c => c . sys . id === card . sys . id ) ,
113
110
animated : true ,
114
111
} ) ;
115
112
}
116
113
} ,
117
- [ carouselRef , dismissCard , cards , cardKey , card . sys . id ]
114
+ [ carouselRef , cardKey , card . sys . id ]
118
115
) ;
119
116
120
117
const imageForPlatform = ( ) => {
@@ -143,7 +140,7 @@ export const RemoteCard: React.FC<RemoteCardProps> = ({ card = {} as TrimmedCard
143
140
}
144
141
} ;
145
142
146
- if ( ! card ) {
143
+ if ( ! card || card . dismissed ) {
147
144
return null ;
148
145
}
149
146
0 commit comments