Skip to content

Commit

Permalink
eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruiseki committed Feb 28, 2024
1 parent f98c9ed commit 0df3f85
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { Imager } from './screens/imager/Imager';
import {Imager} from './screens/imager/Imager';

const Tab = createBottomTabNavigator();

Expand Down
61 changes: 36 additions & 25 deletions src/screens/imager/Imager.jsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,68 @@
import { StyleSheet, Text } from 'react-native'
import { SafeAreaView } from 'react-native-safe-area-context';
import { Camera, useCameraDevice, useCameraFormat, useCodeScanner, useCameraPermission } from 'react-native-vision-camera'
import { getProduct } from '../../service/apiCall';
import {StyleSheet, Text} from 'react-native';
import {SafeAreaView} from 'react-native-safe-area-context';
import {
Camera,
useCameraDevice,
useCameraFormat,
useCodeScanner,
useCameraPermission,
} from 'react-native-vision-camera';
import {getProduct} from '../../service/apiCall';

export const Imager = () => {
const {hasPermission, requestPermission} = useCameraPermission();

requestPermission();

const codeScanner = useCodeScanner({
codeTypes: ['qr', 'ean-13'],
onCodeScanned: (codes) => {
onCodeScanned: codes => {
codes.forEach(code => {
if(code.type == 'ean-13') getProduct(code.value).then(result => console.log(`Product found : ${result.name}`)/* call another page */);
if (code.type == 'ean-13')

Check warning

Code scanning / ESLint

require the use of `===` and `!==` Warning

Expected '===' and instead saw '=='.
getProduct(code.value).then(
result =>
console.log(
`Product found : ${result.name}`,
) /* call another page */,
);
});
}
},
});

const device = useCameraDevice('back', {
physicalDevices: [
'ultra-wide-angle-camera',
'wide-angle-camera',
'telephoto-camera'
]
'telephoto-camera',
],
});

if(!device) return <NoCameraDeviceError />
else
{
if (!device) return <NoCameraDeviceError />;

Check warning

Code scanning / ESLint

Disallow missing React when using JSX Warning

'React' must be in scope when using JSX

Check failure

Code scanning / ESLint

Disallow undeclared variables in JSX Error

'NoCameraDeviceError' is not defined.
else {
const format = useCameraFormat(device, [

Check failure

Code scanning / ESLint

enforces the Rules of Hooks Error

React Hook "useCameraFormat" is called conditionally. React Hooks must be called in the exact same order in every component render.
{ videoAspectRatio: 3/4 },
{ fps: 120 },
{ videoStabilizationMode: 'cinematic-extended'}
{videoAspectRatio: 3 / 4},
{fps: 120},
{videoStabilizationMode: 'cinematic-extended'},
]);

if(hasPermission)
{
if (hasPermission) {
return (
<Camera
style={StyleSheet.absoluteFill}
device={device}
format={format}
codeScanner={codeScanner}
isActive={true} />
isActive={true}
/>

Check warning

Code scanning / ESLint

Disallow missing React when using JSX Warning

'React' must be in scope when using JSX
);
}
else
{
return(
} else {
return (
<SafeAreaView>

Check warning

Code scanning / ESLint

Disallow missing React when using JSX Warning

'React' must be in scope when using JSX
<Text style={{color: 'black'}}>No permission granted for the Camera</Text>
<Text style={{color: 'black'}}>

Check warning

Code scanning / ESLint

Disallow missing React when using JSX Warning

'React' must be in scope when using JSX
No permission granted for the Camera
</Text>
</SafeAreaView>
);
}
}
};
};
8 changes: 3 additions & 5 deletions src/service/apiCall.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import {logger} from 'react-native-logs';

const apiUrl = 'https://world.openfoodfacts.org/api/v2/product/';
const log = logger.createLogger();

export async function getProduct(barcode: string) {

const response = await fetch(apiUrl + barcode);
const json = await response.json();

let data = {};
data.code = json.code;
data.name = json.product.product_name;
data.nutriscore = json.product.nutriscore_grade;
data.categories = json.product.categories;
data.nutriments = json.product.nutriments;
data.energy = json.product.nutriments.energy;
data.energy100g = json.product.nutriments["energy-kcal_100g"];
data.energy100g = json.product.nutriments['energy-kcal_100g'];

return data;
}

0 comments on commit 0df3f85

Please sign in to comment.