Skip to content

Commit

Permalink
fixed store and photos screen crash
Browse files Browse the repository at this point in the history
  • Loading branch information
tortuvshin committed Feb 20, 2024
1 parent 4352212 commit 2f215f9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/features/Network/screens/StoreScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ const StoreScreen = ({ navigation, route }) => {
/>
)}
{isInfoWidgetEnabled && <StoreInfoWidget wrapperStyle={tailwind('my-2')} info={info} store={store} storeLocation={storeLocation} />}
{isPhotosWidgetEnabled && store.getAttribute('media', []).length > 0 && (
{isPhotosWidgetEnabled && store.getAttribute('media', [])?.length > 0 && (
<StorePhotosWidget
wrapperStyle={tailwind('my-2')}
info={info}
Expand Down
4 changes: 2 additions & 2 deletions src/features/Shared/StorePhotosScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const StorePhotosScreen = ({ navigation, route }) => {

const isModalVisible = viewingPhoto !== null && viewingPhoto !== undefined;
const medias = store.getAttribute('media', []);
const currentIndex = medias.indexOf(viewingPhoto);
const currentIndex = medias?.indexOf(viewingPhoto);

return (
<View style={[tailwind('bg-black'), { paddingTop: insets.top }]}>
Expand All @@ -54,7 +54,7 @@ const StorePhotosScreen = ({ navigation, route }) => {
</View>
<ScrollView style={tailwind('w-full h-full pb-12')}>
<View style={tailwind('flex flex-row flex-wrap')}>
{medias.map((media, index) => (
{medias?.map((media, index) => (
<TouchableOpacity
key={index}
onPress={() => setViewingPhoto(media)}
Expand Down
14 changes: 9 additions & 5 deletions src/hooks/use-storefront.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import Storefront from '@fleetbase/storefront';
import config from 'config';

import { get } from 'utils/Storage';
const { STOREFRONT_KEY, FLEETBASE_HOST } = config;
let storefront, adapter;

let { STOREFRONT_KEY, FLEETBASE_HOST } = config;
try {
storefront = new Storefront('network_f7c72f15ff4be9fd3f6fa25ed30271af', { host: FLEETBASE_HOST });
adapter = storefront.getAdapter();
} catch (error) {
storefront = error;
}

const useStorefront = () => {
const storefront = new Storefront(STOREFRONT_KEY || 'store_726cc5fe346591e99edfa2aed2102148', { host: 'https://460a-202-131-229-106.ngrok-free.app' });
const adapter = storefront.getAdapter();

return storefront;
};

export default useStorefront;
export { adapter };

0 comments on commit 2f215f9

Please sign in to comment.