Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #20

Merged
merged 28 commits into from
Dec 5, 2018
Merged

Dev #20

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Preload tabs
  • Loading branch information
krestaino committed Nov 24, 2018
commit 9113c3ab5c87e49320661eaa2f6767bf33aaa892
3 changes: 2 additions & 1 deletion components/Crypto/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { getCrypto } from '../../store/actions/'
import { preLoad } from '../../helpers/preLoad'

import List from '../List'

Expand All @@ -11,7 +12,7 @@ class Crypto extends Component {
const { crypto, tabs } = this.props

if (tabs.index !== prevProps.tabs.index) {
if (crypto.loading === null && tabs.index === 6) {
if (crypto.loading === null && preLoad(6)) {
this.props.getCrypto()
}
}
Expand Down
3 changes: 2 additions & 1 deletion components/Gainers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { getGainers } from '../../store/actions/'
import { preLoad } from '../../helpers/preLoad'

import List from '../List'

Expand All @@ -11,7 +12,7 @@ class Gainers extends Component {
const { gainers, tabs } = this.props

if (tabs.index !== prevProps.tabs.index) {
if (gainers.loading === null && tabs.index === 3) {
if (gainers.loading === null && preLoad(3)) {
this.props.getGainers()
}
}
Expand Down
4 changes: 0 additions & 4 deletions components/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ class Home extends Component {
/>
)

componentDidUpdate() {
console.log(this.props.tab.index)
}

render = () => (
<View style={styles.container}>
<TabView
Expand Down
3 changes: 2 additions & 1 deletion components/Losers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { getLosers } from '../../store/actions/'
import { preLoad } from '../../helpers/preLoad'

import List from '../List'

Expand All @@ -11,7 +12,7 @@ class Losers extends Component {
const { losers, tabs } = this.props

if (tabs.index !== prevProps.tabs.index) {
if (losers.loading === null && tabs.index === 4) {
if (losers.loading === null && preLoad(4)) {
this.props.getLosers()
}
}
Expand Down
3 changes: 2 additions & 1 deletion components/MostActive/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { getMostActive } from '../../store/actions/'
import { preLoad } from '../../helpers/preLoad'

import List from '../List'

Expand All @@ -11,7 +12,7 @@ class MostActive extends Component {
const { mostActive, tabs } = this.props

if (tabs.index !== prevProps.tabs.index) {
if (mostActive.loading === null && tabs.index === 5) {
if (mostActive.loading === null && preLoad(5)) {
this.props.getMostActive()
}
}
Expand Down
3 changes: 2 additions & 1 deletion components/Sectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { connect } from 'react-redux'
import { Colors } from '../../constants'
import { getSectors } from '../../store/actions/'
import { upOrDownSymbol, formatPercentage, positiveOrNegative } from '../../helpers/priceFormat'
import { preLoad } from '../../helpers/preLoad'
import { sectorIcons } from '../../helpers/sectorIcons'
import { globalStyles } from '../../styles'

Expand All @@ -16,7 +17,7 @@ class Sectors extends Component {
const { sectors, tabs } = this.props

if (tabs.index !== prevProps.tabs.index) {
if (sectors.loading === null && tabs.index === 2) {
if (sectors.loading === null && preLoad(2)) {
this.props.getSectors()
}
}
Expand Down
15 changes: 12 additions & 3 deletions components/Stock/Chart/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import { Dimensions, StyleSheet } from 'react-native'
import { Text, View } from 'native-base'
import { Spinner, Text, View } from 'native-base'
import { connect } from 'react-redux'
import { LineSegment, VictoryChart, VictoryAxis, VictoryLabel, VictoryLine, VictoryTheme } from 'victory-native'
import Touchable from 'react-native-platform-touchable'
Expand Down Expand Up @@ -52,7 +52,12 @@ class Chart extends Component {
const { chart, quote } = this.props.stock.data
const { width } = Dimensions.get('window')

if (chart.length === 0) return null
if (chart.length === 0 || this.props.stock.loading)
return (
<View style={styles.spinner}>
<Spinner color={Colors.TEXT_DARK} />
</View>
)

const _chart = chart
.filter(interval => interval.close || interval.marketClose)
Expand All @@ -66,7 +71,7 @@ class Chart extends Component {
const lineSegment = <LineSegment style={svgStyles.chartGrid} type={'grid'} />

return (
<View>
<View style={{ height: 250 }}>
<View style={styles.rangesContainer}>
{this.state.ranges.map((range, index) => (
<Touchable
Expand Down Expand Up @@ -114,6 +119,10 @@ class Chart extends Component {
}

const styles = StyleSheet.create({
spinner: {
height: 250,
justifyContent: 'center'
},
chart: {
marginBottom: -10,
marginTop: -36
Expand Down
11 changes: 2 additions & 9 deletions components/Stock/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { Component } from 'react'
import { Platform, RefreshControl, StyleSheet } from 'react-native'
import { Content, Text, Spinner, View } from 'native-base'
import { Content, Text, View } from 'native-base'
import { connect } from 'react-redux'

import { Colors } from '../../constants'
import { getStock } from '../../store/actions/'

import Search from '../Search'
Expand All @@ -21,8 +20,7 @@ class Stock extends Component {
const { chart, quote } = this.props.stock.data
const { error, loading } = this.props.stock

const isLoading = !error && loading
const isSucess = !error && !loading && chart && quote
const isSucess = !error && chart && quote
const isError = error && !loading

return (
Expand Down Expand Up @@ -50,11 +48,6 @@ class Stock extends Component {
<Text>{error}</Text>
</View>
)}
{isLoading && (
<View style={[styles.container, styles.center]}>
<Spinner color={Colors.TEXT_DARK} />
</View>
)}
</View>
)
}
Expand Down
1 change: 1 addition & 0 deletions helpers/preLoad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const preLoad = index => (index === index - 1 || index === index || index === index + 1 ? true : false)