Skip to content

Commit

Permalink
components/* : Modify Class Components to Functional components
Browse files Browse the repository at this point in the history
  • Loading branch information
devRD committed Sep 25, 2020
1 parent 2286d4c commit 70e9935
Show file tree
Hide file tree
Showing 28 changed files with 572 additions and 458 deletions.
23 changes: 10 additions & 13 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { Platform, StatusBar, StyleSheet, View } from 'react-native'
import { AppLoading } from 'expo'
import { Asset } from 'expo-asset'
Expand All @@ -16,21 +16,18 @@ export default function App(props) {
fonticons: require('./assets/fonts/fonticons.ttf'),
})

console.log()

if (!fontsLoaded) {
console.log('got here')
return <AppLoading />
} else {
return (
<ContextProvider>
<View style={styles.container}>
{Platform.OS === 'ios' && <StatusBar barStyle="dark-content" />}
<AppNavigator />
</View>
</ContextProvider>
)
}

return (
<ContextProvider>
<View style={styles.container}>
{Platform.OS === 'ios' && <StatusBar barStyle="dark-content" />}
<AppNavigator />
</View>
</ContextProvider>
)
}

const styles = StyleSheet.create({
Expand Down
54 changes: 32 additions & 22 deletions components/BlockCard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { PureComponent } from 'react'
import React, { useState } from 'react'
import { LayoutAnimation, View } from 'react-native'
import Card from './basic/Card'
import BlockButton from './BlockCardFractions/BlockButton'
Expand All @@ -14,22 +14,32 @@ import Warning from './BlockCardFractions/Warning'
import Text from '../components/basic/Text'
import FontIcon from './basic/FontIcon'

export default class BlockCard extends PureComponent {
export default function BlockCard(props){
/***
constructor(props) {
super(props)
this.state = {
showBlockInfo: null,
}
}
**/
const [ showBlockInfo, setBlockInfo ] = useState(null);

onButtonPress = buttonTitle => {
const onButtonPress = buttonTitle => {
/**
this.setState({
showBlockInfo:
this.state.showBlockInfo == buttonTitle ? null : buttonTitle,
})
**/
if(showBlockInfo == buttonTitle){
setBlockInfo(null);
} else {
setBlockInfo(buttonTitle);
}
}

render() {
//render() {
const {
index,
blockHash,
Expand All @@ -41,21 +51,21 @@ export default class BlockCard extends PureComponent {
hashAlgorithmName,
multipleCheckOUT,
neverCheckedIN,
} = this.props
} = props

BlockInfo = () => {
const BlockInfo = () => {
LayoutAnimation.configureNext(LayoutAnimation.Presets.spring)

const { showBlockInfo } = this.state
// const { showBlockInfo } = this.state
switch (showBlockInfo) {
case 'PREVIOUS HASH':
return (
<ChainingInfo
timestamp={this.props.previousBlockInfo.timestamp}
previousBlockHash={this.props.previousBlockInfo.previousBlockHash}
productDataHash={this.props.previousBlockInfo.productDataHash}
hash={this.props.previousBlockHash}
hashAlgorithmName={this.props.hashAlgorithmName}
timestamp={props.previousBlockInfo.timestamp}
previousBlockHash={props.previousBlockInfo.previousBlockHash}
productDataHash={props.previousBlockInfo.productDataHash}
hash={props.previousBlockHash}
hashAlgorithmName={props.hashAlgorithmName}
/>
)

Expand All @@ -80,11 +90,11 @@ export default class BlockCard extends PureComponent {
case 'BLOCK HASH':
return (
<ChainingInfo
timestamp={this.props.timestamp}
previousBlockHash={this.props.previousBlockHash}
productDataHash={this.props.productDataHash}
hash={this.props.blockHash}
hashAlgorithmName={this.props.hashAlgorithmName}
timestamp={props.timestamp}
previousBlockHash={props.previousBlockHash}
productDataHash={props.productDataHash}
hash={props.blockHash}
hashAlgorithmName={props.hashAlgorithmName}
/>
)

Expand Down Expand Up @@ -127,23 +137,23 @@ export default class BlockCard extends PureComponent {
>
<View style={{ flex: 4, justifyContent: 'space-between' }}>
<BlockButton
onPress={this.onButtonPress}
onPress={onButtonPress}
style={{ marginBottom: 5 }}
title="TIMESTAMP"
value={timestamp}
valueIsHash={false}
/>

<BlockButton
onPress={this.onButtonPress}
onPress={onButtonPress}
style={{ marginBottom: 5 }}
title="PRODUCT DATA"
value={productDataHash}
colorize={index != 0}
/>

<BlockButton
onPress={this.onButtonPress}
onPress={onButtonPress}
style={{ marginBottom: 5 }}
title="PREVIOUS HASH"
value={previousBlockHash}
Expand All @@ -160,7 +170,7 @@ export default class BlockCard extends PureComponent {
}}
>
<BlockButton
onPress={this.onButtonPress}
onPress={onButtonPress}
title="BLOCK HASH"
value={blockHash}
colorize={false}
Expand Down Expand Up @@ -195,5 +205,5 @@ export default class BlockCard extends PureComponent {
)}
</View>
)
}
// }
}
8 changes: 3 additions & 5 deletions components/DoseAdjuster.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import debounce from 'lodash/debounce'
import React, { PureComponent } from 'react'
import React from 'react'
import { View } from 'react-native'
import Slider from 'react-native-slider'
import Slider from '@react-native-community/slider'
import Colors from '../constants/Colors'
import { ContextConsumer } from '../Context'
import Text from './basic/Text'

export default class DoseAdjuster extends PureComponent {
render() {
export default function DoseAdjuster(props) {
return (
<ContextConsumer>
{({ getDose, getDoseRange, setDose, prescriptionDose }) => {
Expand Down Expand Up @@ -64,5 +63,4 @@ export default class DoseAdjuster extends PureComponent {
}}
</ContextConsumer>
)
}
}
8 changes: 3 additions & 5 deletions components/DosePrescription.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { PureComponent } from 'react'
import React from 'react'
import { View, LayoutAnimation, Platform } from 'react-native'
import Colors from '../constants/Colors'
import FontIcon from './basic/FontIcon'
import Text from './basic/Text'
import { ContextConsumer } from '../Context'

export default class DosePrescription extends PureComponent {
render() {
const { style } = this.props
export default function DosePrescription(props) {
const { style } = props

return (
<ContextConsumer>
Expand Down Expand Up @@ -104,5 +103,4 @@ export default class DosePrescription extends PureComponent {
}}
</ContextConsumer>
)
}
}
6 changes: 2 additions & 4 deletions components/DrugHistory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//import liraries
import map from 'lodash/map'
import React, { PureComponent } from 'react'
import React from 'react'
import { View } from 'react-native'
import { ContextConsumer } from '../Context'
import Card from './basic/Card'
Expand All @@ -12,8 +12,7 @@ import Colors from '../constants/Colors'
import Warning from './BlockCardFractions/Warning'

// create a component
export default class DrugHistory extends PureComponent {
render() {
export default function DrugHistory(props) {
return (
<ContextConsumer>
{({ patientDrugHistory, blockchain: { falsifiedMedicine } }) => {
Expand Down Expand Up @@ -54,5 +53,4 @@ export default class DrugHistory extends PureComponent {
}}
</ContextConsumer>
)
}
}
6 changes: 2 additions & 4 deletions components/FalsifiedDrugs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { PureComponent } from 'react'
import React from 'react'
import { View, TouchableOpacity, Alert, Platform } from 'react-native'
import Layout from '../constants/Layout'
import { ContextConsumer } from '../Context'
import FontIcon from './basic/FontIcon'
import Text from './basic/Text'

export default class FalsifiedDrugs extends PureComponent {
render() {
export default function FalsifiedDrugs(props){
const {
window: { width },
} = Layout
Expand Down Expand Up @@ -89,5 +88,4 @@ export default class FalsifiedDrugs extends PureComponent {
}}
</ContextConsumer>
)
}
}
8 changes: 3 additions & 5 deletions components/GenuineDrugs.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import map from 'lodash/map'
import React, { PureComponent } from 'react'
import React from 'react'
import { Alert, Platform, TouchableOpacity, View } from 'react-native'
import { getHashOfproductData } from '../cloudComputing/Block'
import { getHashColors } from '../constants/Colors'
import Layout from '../constants/Layout'
import { ContextConsumer } from '../Context'
import FontIcon from './basic/FontIcon'

export default class GenuineDrugs extends PureComponent {
render() {
export default function GenuineDrugs(props) {
const {
window: { width },
} = Layout
return (
<ContextConsumer>
{({ genuineDrugs, checkOUT }) => {
return (
<View style={this.props.style}>
<View style={props.style}>
{map(genuineDrugs, (drug, index) => {
return (
<TouchableOpacity
Expand Down Expand Up @@ -79,5 +78,4 @@ export default class GenuineDrugs extends PureComponent {
}}
</ContextConsumer>
)
}
}
10 changes: 5 additions & 5 deletions components/ListData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react'
import React, { useState } from 'react'
import { View } from 'react-native'

import reduce from 'lodash/reduce'
Expand All @@ -7,9 +7,9 @@ import capitalize from 'lodash/capitalize'

import InfoRow from './basic/InfoRow'

export default class ListData extends Component {
render() {
const { data } = this.props
export default function ListData(props) {
// render() {
const { data } = props;
return (
<View>
{reduce(
Expand All @@ -32,5 +32,5 @@ export default class ListData extends Component {
)}
</View>
)
}
// }
}
12 changes: 4 additions & 8 deletions components/ManufactureHistory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import map from 'lodash/map'
import React, { PureComponent } from 'react'
import React from 'react'
import { Alert, Platform, TouchableOpacity, View } from 'react-native'
import { QRCode } from 'react-native-custom-qr-codes-expo'
import { getHashOfproductData } from '../cloudComputing/Block'
Expand All @@ -9,9 +9,8 @@ import { ContextConsumer } from '../Context'
import FontIcon from './basic/FontIcon'
import HashBlock from './basic/HashBlock'

class DrugQR extends PureComponent {
render() {
const { value, borderColor } = this.props
function DrugQR(props) {
const { value, borderColor } = props
const {
window: { width },
isSmallDevice,
Expand Down Expand Up @@ -40,11 +39,9 @@ class DrugQR extends PureComponent {
</View>
</View>
)
}
}

export default class ManufactureHistory extends PureComponent {
render() {
export default function ManufactureHistory(props){
const {
window: { width },
isSmallDevice,
Expand Down Expand Up @@ -110,5 +107,4 @@ export default class ManufactureHistory extends PureComponent {
}
</ContextConsumer>
)
}
}
Loading

0 comments on commit 70e9935

Please sign in to comment.