Skip to content

Commit

Permalink
Merge pull request #22 from Osedea/feature/add-eslint-config-and-fix-…
Browse files Browse the repository at this point in the history
…tests

Feature/add eslint config and fix tests
  • Loading branch information
adrienthiery authored May 24, 2018
2 parents 7cd5c2b + 6a2ee65 commit 81caf30
Show file tree
Hide file tree
Showing 9 changed files with 1,869 additions and 270 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extends:
- osedea/react-native

globals:
__DEV__: true

env:
jest: true

rules:
operator-linebreak:
- error
- before
no-use-before-define: off
no-continue: off

# Temporary
react/jsx-curly-brace-presence: off
71 changes: 28 additions & 43 deletions OpenGraphAwareInput.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import React, { Component } from 'react';
import {
StyleSheet,
TextInput,
View,
ViewPropTypes,
} from 'react-native';
import { StyleSheet, TextInput, View, ViewPropTypes } from 'react-native';
import PropTypes from 'proptypes';
import debounce from 'lodash.debounce';

import OpenGraphDisplay from './OpenGraphDisplay';
import OpenGraphParser from './OpenGraphParser';

const styles = StyleSheet.create({
container: {
},
container: {},
input: {
height: 50,
marginBottom: 5,
Expand Down Expand Up @@ -51,29 +45,23 @@ export default class OpenGraphAwareInput extends Component {
this.setState({
openGraphData: [],
});
}
};

extractMetaAndSetState = debounce(
(text) => {
OpenGraphParser.extractMeta(text)
.then(
(data) => {
const customEvent = {};
extractMetaAndSetState = debounce((text) => {
OpenGraphParser.extractMeta(text).then((data) => {
const customEvent = {};

this.setState({ openGraphData: data || [] });
this.setState({ openGraphData: data || [] });

if (this.props.onChange) {
customEvent.event = event;
customEvent.opengraphData = data || [];
customEvent.text = text;
if (this.props.onChange) {
customEvent.event = event;
customEvent.opengraphData = data || [];
customEvent.text = text;

this.props.onChange(customEvent);
}
}
);
},
this.props.debounceDelay
);
this.props.onChange(customEvent);
}
});
}, this.props.debounceDelay);

handleTextInputChange = (event) => {
const text = event.nativeEvent.text;
Expand All @@ -82,33 +70,30 @@ export default class OpenGraphAwareInput extends Component {
};

render() {
const ogDataToDisplay = this.state.openGraphData.slice(0, this.props.resultLimit);
const ogDataToDisplay = this.state.openGraphData.slice(
0,
this.props.resultLimit
);
return (
<View
style={[
styles.container,
this.props.containerStyle,
]}
>
<View style={[styles.container, this.props.containerStyle]}>
<TextInput
onChange={this.handleTextInputChange}
style={[
styles.input,
this.props.textInputStyle,
]}
style={[styles.input, this.props.textInputStyle]}
/>
{ogDataToDisplay.map((meta, i) =>
{ogDataToDisplay.map((meta, i) => (
<OpenGraphDisplay
key={i}
data={meta}
onIconPress={this.props.showIcon
? this.props.onIconPress || this.handleDismissOpengraph
: null
onIconPress={
this.props.showIcon
? this.props.onIconPress
|| this.handleDismissOpengraph
: null
}
iconSource={this.props.iconSource}
iconStyle={this.props.iconStyle}
/>
)}
))}
</View>
);
}
Expand Down
92 changes: 32 additions & 60 deletions OpenGraphDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ export default class OpenGraphDisplay extends Component {
};

handleLinkPress = () => {
Linking.canOpenURL(this.props.data.url).then((supported) => {
if (!supported) {
console.log(`Can\'t handle url: ${this.props.data.url}`);
Linking.canOpenURL(this.props.data.url)
.then((supported) => {
if (!supported) {
console.log(`Can't handle url: ${this.props.data.url}`);

return null;
} else {
return Linking.openURL(this.props.data.url);
}
}).catch(
(err) => console.error('An error occurred', err)
);
return null;
} else {
return Linking.openURL(this.props.data.url);
}
})
.catch((err) => console.error('An error occurred', err));
};

render() {
Expand All @@ -126,41 +126,32 @@ export default class OpenGraphDisplay extends Component {
return opengraph;
}

if (this.props.data.title
if (
this.props.data.title
|| this.props.data.description
|| this.props.data.image
) {
opengraph = (
<TouchableWithoutFeedback
onPress={this.handleLinkPress}
>
<TouchableWithoutFeedback onPress={this.handleLinkPress}>
<View
style={[
styles.container,
this.props.touchContainerStyle,
]}
>
{this.props.data.image ?
{this.props.data.image ? (
<Image
style={[
styles.image,
this.props.imageStyle,
]}
style={[styles.image, this.props.imageStyle]}
source={{ uri: this.props.data.image }}
/> : null
}
/>
) : null}
<View
style={[
styles.textContent,
this.props.textContainerStyle,
]}
>
<Text
style={[
styles.title,
this.props.titleStyle,
]}
>
<Text style={[styles.title, this.props.titleStyle]}>
{this.props.data.title || ''}
</Text>
<Text
Expand All @@ -171,64 +162,45 @@ export default class OpenGraphDisplay extends Component {
>
{this.props.data.description || ''}
</Text>
<Text
style={[
styles.url,
this.props.urlStyle,
]}
>
{this.props.data.url ? this.props.data.url.toLowerCase() : ''}
<Text style={[styles.url, this.props.urlStyle]}>
{this.props.data.url
? this.props.data.url.toLowerCase()
: ''}
</Text>
</View>
</View>
</TouchableWithoutFeedback>
);
} else {
opengraph = (
<TouchableWithoutFeedback
onPress={this.handleLinkPress}
>
<TouchableWithoutFeedback onPress={this.handleLinkPress}>
<View
style={[
styles.smallContainer,
this.props.urlOnlyTouchContainerStyle,
]}
>
<Text
style={[
styles.url,
this.props.urlStyle,
]}
>
{this.props.data.url ? this.props.data.url.toLowerCase() : ''}
<Text style={[styles.url, this.props.urlStyle]}>
{this.props.data.url
? this.props.data.url.toLowerCase()
: ''}
</Text>
</View>
</TouchableWithoutFeedback>
);
}

return (
<View
style={[
styles.opengraphWithIcon,
this.props.containerStyle,
]}
>
<View style={[styles.opengraphWithIcon, this.props.containerStyle]}>
{opengraph}
{this.props.onIconPress
? <TouchableWithoutFeedback
onPress={this.props.onIconPress}
>
{this.props.onIconPress ? (
<TouchableWithoutFeedback onPress={this.props.onIconPress}>
<Image
source={this.props.iconSource}
style={[
styles.iconStyle,
this.props.iconStyle,
]}
style={[styles.iconStyle, this.props.iconStyle]}
/>
</TouchableWithoutFeedback>
: null
}
) : null}
</View>
);
}
Expand Down
Loading

0 comments on commit 81caf30

Please sign in to comment.