Skip to content

Commit

Permalink
feat(example): add Device Information search
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuayoes committed Mar 12, 2024
1 parent 3fbaafb commit fe212e1
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import * as React from 'react';
import { StyleSheet, View, Text, SectionList } from 'react-native';
import {
StyleSheet,
View,
Text,
SectionList,
TextInput,
FlatList,
} from 'react-native';
import {
useBarcodeScanner,
useCashDrawer,
Expand All @@ -23,9 +30,49 @@ const Section = ({ data, error, loading }: SectionProps) => {
);
};

const DeviceInformation = () => {
const { data, loading, error } = useDeviceInformation();
const [search, setSearch] = React.useState('');
const filteredData = React.useMemo(
() =>
data?.filter((item) =>
JSON.stringify(item).toLowerCase().includes(search.toLowerCase())
),
[data, search]
);

return (
<View style={{ height: '50%' }}>

Check warning on line 45 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Inline style: { height: '50%' }
<Text style={[styles.header, { marginBottom: 20 }]}>

Check warning on line 46 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Inline style: { marginBottom: 20 }
Device Information
</Text>
<TextInput
style={{

Check warning on line 50 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Inline style: { height: 40, borderColor: 'gray', borderWidth: 1 }
height: 40,
borderColor: 'gray',
borderWidth: 1,
}}
onChangeText={setSearch}
value={search}
placeholder="Search"
/>
<View style={styles.section}>
{loading && <Text>Loading...</Text>}
{error && <Text>Error: {error.message}</Text>}
<FlatList
data={filteredData}
renderItem={({ item }) => (
<Text>{JSON.stringify(item, null, 2)}</Text>
)}
keyExtractor={(item) => item.Id}
/>
</View>
</View>
);
};

export default function App() {
const posPrinter = usePosPrinter();
const deviceInformation = useDeviceInformation();
const barcodeScanner = useBarcodeScanner();
const cashDrawer = useCashDrawer();

Expand All @@ -36,22 +83,20 @@ export default function App() {
{ title: 'POS Printer', data: [posPrinter] },
{ title: 'Barcode Scanner', data: [barcodeScanner] },
{ title: 'Cash Drawer', data: [cashDrawer] },
{ title: 'Device Information', data: [deviceInformation] },
]}
renderItem={({ item }) => <Section {...item} />}
renderSectionHeader={({ section: { title } }) => (
<Text style={styles.header}>{title}</Text>
)}
/>
<DeviceInformation />
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
margin: 16,
},
section: {
Expand Down

0 comments on commit fe212e1

Please sign in to comment.