diff --git a/app/MnmComments.js b/app/MnmComments.js index e52264a..59cef65 100644 --- a/app/MnmComments.js +++ b/app/MnmComments.js @@ -1,94 +1,109 @@ /*jshint esnext: true*/ /*global require, module, fetch*/ -'use strict'; - -import React, { Component } from 'react' +import React from 'react' import { - StyleSheet, - Platform, - PixelRatio, - View, - Text, - ActivityIndicatorIOS, - ProgressBarAndroid, - ListView + StyleSheet, + Platform, + PixelRatio, + View, + Text, + ActivityIndicatorIOS, + ProgressBarAndroid, + ListView, + RefreshControl, + InteractionManager } from 'react-native' - import HTMLView from 'react-native-htmlview' +var moment = require('moment') +var Icon = require('react-native-vector-icons/EvilIcons') -var moment = require('moment'); -var Icon = require('react-native-vector-icons/EvilIcons'); +class MnmComments extends React.Component { + getComments: Function; - -class MnmComments extends Component { - constructor(props) { - super(props); - var dataSource = new ListView.DataSource({ - rowHasChanged: (r1, r2) => r1.id !== r2.id - }); - this.state = { - dataSource: dataSource.cloneWithRows([]), - rows: [] - }; - this._getComments(); + constructor (props) { + super(props) + const dataSource = new ListView.DataSource({ + rowHasChanged: (r1, r2) => r1.id !== r2.id + }) + this.state = { + dataSource: dataSource.cloneWithRows([]), + rows: [], + isFetching: false, } + this.getComments = this._getComments.bind(this) + } - _getComments() { - fetch('https://www.meneame.net/api/list?id=' + this.props.entryId) - .then(response => response.json()) - .then(response => { - var comments = []; - response.objects.forEach((comment) => { - comment.date = moment.unix(comment.date); - comment.fromNow = comment.date.fromNow(); - comments.push(comment); - }); - var sortedComments = comments.sort((c1, c2) => { - if (c1.order < c2.order) { - return -1; - } else { - return 1; - } - }); - this.setState({ - dataSource: this.state.dataSource.cloneWithRows(sortedComments), - rows: sortedComments - }); - }); - } + componentDidMount () { + this.getComments() + } - renderRow(rowData) { - return ( - - - {rowData.user} - - - {rowData.votes} - - {rowData.karma} - {rowData.fromNow} - - - - #{rowData.order} - - - + _getComments () { + InteractionManager.runAfterInteractions(() => { + this.setState({isFetching: true}) + fetch('https://www.meneame.net/api/list?id=' + this.props.entryId) + .then(response => response.json()) + .then(response => { + const comments = response.objects.map((comment) => { + comment.date = moment.unix(comment.date) + comment.fromNow = comment.date.fromNow() + return comment + }) + .sort((c1, c2) => { + if (c1.order < c2.order) { + return -1; + } else { + return 1; + } + }) + this.setState({ + dataSource: this.state.dataSource.cloneWithRows(comments), + rows: comments, + isFetching: false, + }) + }) + .catch(() => this.setState({isFetching: false})) + }) + } + + renderRow(rowData) { + return ( + + + {rowData.user} + + + {rowData.votes} + + {rowData.karma} + {rowData.fromNow} - ); - } + + #{rowData.order} + + + + + + ) + } - _renderList() { + _renderList () { if (this.state.rows.length > 0) { return ( - + } /> ) } else { @@ -109,92 +124,92 @@ class MnmComments extends Component { } } - render() { - return ( - - {this._renderList()} - - ); + render () { + return ( + + {this._renderList()} + + ) } } -var styles = StyleSheet.create({ - container: { - flex: 1, - backgroundColor: '#FAFAFA', - }, - navcomments: { - flex: 1, - backgroundColor: '#FAFAFA', - }, - cellContainer: { - flex: 1, - backgroundColor: '#FAFAFA', - marginLeft: 20, - marginRight: 20, - marginBottom: 10, - paddingBottom: 15, - paddingTop: 5, - borderBottomWidth: 1 / PixelRatio.get(), - borderBottomColor: '#CDCDCD', - }, - infoContainer: { - flexDirection: 'row', - flex: 1, - alignItems: 'stretch', - marginBottom: 10, - }, - username: { - flex: 1, - flexDirection: 'row', - fontWeight: 'bold', - fontSize: 14, - color: '#262626', - }, - commentData: { - flex: 2, - flexDirection: 'row', - justifyContent: 'flex-end', - }, - icon: { - width: 20, - color: '#95a5a6', - }, - counter: { - color: '#95a5a6', - marginRight: 10, - }, - date: { - fontSize: 14, - fontWeight: '300', - color: '#95a5a6', - }, - textContainer: { - flexDirection: 'row', - }, - commentNumber: { - color: '#d35400', - fontWeight: '300', - fontSize: 14, - }, - comment: { - marginLeft: 3, - flex: 1, - color: '#7f8c8d', - fontWeight: '300', - fontSize: 14, - }, - centering: { - flex: 1, - alignSelf: 'center', - justifyContent: 'center', - backgroundColor: '#FAFAFA', - }, - progressBar: { - width: 50, - height: 50, - }, -}); +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: '#FAFAFA', + }, + navcomments: { + flex: 1, + backgroundColor: '#FAFAFA', + }, + cellContainer: { + flex: 1, + backgroundColor: '#FAFAFA', + marginLeft: 20, + marginRight: 20, + marginBottom: 10, + paddingBottom: 15, + paddingTop: 5, + borderBottomWidth: 1 / PixelRatio.get(), + borderBottomColor: '#CDCDCD', + }, + infoContainer: { + flexDirection: 'row', + flex: 1, + alignItems: 'stretch', + marginBottom: 10, + }, + username: { + flex: 1, + flexDirection: 'row', + fontWeight: 'bold', + fontSize: 14, + color: '#262626', + }, + commentData: { + flex: 2, + flexDirection: 'row', + justifyContent: 'flex-end', + }, + icon: { + width: 20, + color: '#95a5a6', + }, + counter: { + color: '#95a5a6', + marginRight: 10, + }, + date: { + fontSize: 14, + fontWeight: '300', + color: '#95a5a6', + }, + textContainer: { + flexDirection: 'row', + }, + commentNumber: { + color: '#d35400', + fontWeight: '300', + fontSize: 14, + }, + comment: { + marginLeft: 3, + flex: 1, + color: '#7f8c8d', + fontWeight: '300', + fontSize: 14, + }, + centering: { + flex: 1, + alignSelf: 'center', + justifyContent: 'center', + backgroundColor: '#FAFAFA', + }, + progressBar: { + width: 50, + height: 50, + }, +}) const htmlStyles = StyleSheet.create({ b: { @@ -202,4 +217,4 @@ const htmlStyles = StyleSheet.create({ } }) -module.exports = MnmComments; +module.exports = MnmComments diff --git a/app/MnmEntrada.js b/app/MnmEntrada.js index e61ea3e..412c89a 100644 --- a/app/MnmEntrada.js +++ b/app/MnmEntrada.js @@ -1,124 +1,123 @@ -import React, { Component } from 'react' +import React from 'react' import { - StyleSheet, - View, - Text, - Navigator, - TouchableHighlight + StyleSheet, + View, + Text, + Navigator, + TouchableHighlight, + Dimensions } from 'react-native' - -var screen = require('Dimensions').get('window'); -var Button = require('react-native-button'); -var ParallaxView = require('react-native-parallax-view'); -var ThumborURLBuilder = require('thumbor-url-builder'); - +import Button from 'react-native-button' +import ParallaxView from 'react-native-parallax-view' +import ThumborURLBuilder from 'thumbor-url-builder' import { THUMBOR_KEY, THUMBOR_URL } from './ThumborConfig' import MnmEntryTextAndDetails from './MnmEntryTextAndDetails' -var MnmComments = require('./MnmComments'); -var MnmWebviewEntry = require('./MnmWebviewEntry'); +import MnmComments from './MnmComments' +import MnmWebviewEntry from './MnmWebviewEntry' import { BrowserButton } from './MnmRouteMapper' +const screen = Dimensions.get('window') -class NavButton extends Component { - render() { - return ( - - ); - } +class NavButton extends React.Component { + render() { + return ( + + ) + } } -class MnmEntrada extends Component { - constructor(props) { - super(props); - var thumborURL = new ThumborURLBuilder(THUMBOR_KEY, THUMBOR_URL); - if (this.props.entrada.thumb) { - var entry = this.props.entrada; - var imagePath = entry.thumb.substr(8, entry.thumb.length); - this.props.entrada.mediaHeader = thumborURL.setImagePath(imagePath).resize(screen.width * screen.scale, screen.height).smartCrop(true).buildUrl(); - } - this.state = { - value: 'Noticia' - }; +class MnmEntrada extends React.Component { + constructor(props) { + super(props); + const thumborURL = new ThumborURLBuilder(THUMBOR_KEY, THUMBOR_URL); + if (this.props.entrada.thumb) { + const entry = this.props.entrada; + const imagePath = escape(entry.thumb.substr(8, entry.thumb.length)) + this.props.entrada.mediaHeader = thumborURL.setImagePath(imagePath).resize(screen.width * screen.scale, screen.height).smartCrop(true).buildUrl(); } - - _titlePressed() { - const URL = this.props.entrada.go - this.props.navigator.push({ - title: this.props.entrada.from, - component: MnmWebviewEntry, - passProps: {uri: URL}, - rightElement: - }); + this.state = { + value: 'Noticia' } + } - render() { - const entrada = this.props.entrada - const backgroundSource = entrada.mediaHeader ? {uri: entrada.mediaHeader} : null - return ( - - - - - {entrada.title} - - {entrada.from} - - - { - this.props.navigator.push({ - title: 'Comentarios', - component: MnmComments, - sceneConfig: Navigator.SceneConfigs.FloatFromBottom, - passProps: {entryId: entrada.id} - }); - }} text={'Comentarios (' + entrada.comments + ')'} - style={styles.button}/> - - - ); - } + _titlePressed() { + const URL = this.props.entrada.go + this.props.navigator.push({ + title: this.props.entrada.from, + component: MnmWebviewEntry, + passProps: {uri: URL}, + rightElement: + }) + } + + render() { + const entrada = this.props.entrada + const backgroundSource = entrada.mediaHeader ? {uri: entrada.mediaHeader} : null + return ( + + + + + {entrada.title} + + {entrada.from} + + + { + this.props.navigator.push({ + title: 'Comentarios', + component: MnmComments, + sceneConfig: Navigator.SceneConfigs.FloatFromBottom, + passProps: {entryId: entrada.id} + }) + }} text={'Comentarios (' + entrada.comments + ')'} + style={styles.button}/> + + + ) + } } -var styles = StyleSheet.create({ - container: { - flex: 1, - backgroundColor: '#FAFAFA', - }, - info: { - marginLeft: 20, - marginRight: 20, - marginTop: 10, - marginBottom: 10, - paddingBottom: 10, - }, - title: { - fontWeight: '300', - color: '#262626', - fontSize: 20, - }, - from: { - fontWeight: '300', - color: '#7f8c8d', - fontSize: 12, - marginBottom: 5, - }, - button: { - color: '#d35400', - marginTop: 10, - fontSize: 22, - paddingTop: 15, - paddingBottom: 25, - paddingLeft: 20, - paddingRight: 20, - }, -}); +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: '#FAFAFA', + }, + info: { + marginLeft: 20, + marginRight: 20, + marginTop: 10, + marginBottom: 10, + paddingBottom: 10, + }, + title: { + fontWeight: '300', + color: '#262626', + fontSize: 20, + }, + from: { + fontWeight: '300', + color: '#7f8c8d', + fontSize: 12, + marginBottom: 5, + }, + button: { + color: '#d35400', + marginTop: 10, + fontSize: 22, + paddingTop: 15, + paddingBottom: 25, + paddingLeft: 20, + paddingRight: 20, + }, +}) -module.exports = MnmEntrada; +module.exports = MnmEntrada diff --git a/app/MnmNewsList.js b/app/MnmNewsList.js index 54b618b..df19d46 100644 --- a/app/MnmNewsList.js +++ b/app/MnmNewsList.js @@ -1,4 +1,4 @@ -import React, { Component } from 'react' +import React from 'react' import { Platform, StyleSheet, @@ -6,61 +6,70 @@ import { ListView, ActivityIndicatorIOS, ProgressBarAndroid, + InteractionManager, + RefreshControl, + Dimensions } from 'react-native' +import MnmNewsRow from './MnmNewsRow' +import ThumborURLBuilder from 'thumbor-url-builder' +import { THUMBOR_KEY, THUMBOR_URL} from './ThumborConfig' -var MnmNewsRow = require('./MnmNewsRow'); - -var screen = require('Dimensions').get('window'); - -var moment = require('moment'); -require('moment/locale/es'); -moment.locale('es'); +const screen = Dimensions.get('window') -var ThumborURLBuilder = require('thumbor-url-builder'); -import { THUMBOR_KEY, THUMBOR_URL} from './ThumborConfig' +var moment = require('moment') +require('moment/locale/es') +moment.locale('es') +class MnmPublicadas extends React.Component { + getPublicadas: Function; -class MnmPublicadas extends Component { - constructor(props) { - super(props); - var dataSource = new ListView.DataSource({ - rowHasChanged: (r1, r2) => r1.id !== r2.id - }); - this.state = { - dataSource: dataSource.cloneWithRows([]), - published: [] - }; + constructor(props) { + super(props) + const dataSource = new ListView.DataSource({ + rowHasChanged: (r1, r2) => r1.id !== r2.id + }) + this.state = { + dataSource: dataSource.cloneWithRows([]), + published: [], + isFetching: false, } + this.getPublicadas = this._getPublicadas.bind(this) + } - componentDidMount () { - this._getPublicadas(); - } + componentDidMount () { + this.getPublicadas() + } - _getPublicadas() { - fetch(this.props.url) - .then(response => response.json()) - .then(response => { - var thumborURL = new ThumborURLBuilder(THUMBOR_KEY, THUMBOR_URL); - var entries = response.objects.map((entry) => { - entry.dateFromNow = moment.unix(entry.date).fromNow(); - if (entry.thumb) { - var imagePath = entry.thumb.substr(8, entry.thumb.length); - entry.mediaPublished = thumborURL.setImagePath(imagePath).resize(screen.width * screen.scale, 310).smartCrop(true).buildUrl(); - } - return entry; - }); - this.setState({ - dataSource: this.state.dataSource.cloneWithRows(entries), - published: entries - }); + _getPublicadas() { + InteractionManager.runAfterInteractions(() => { + this.setState({isFetching: true}) + fetch(this.props.url) + .then(response => response.json()) + .then(response => { + var thumborURL = new ThumborURLBuilder(THUMBOR_KEY, THUMBOR_URL) + var entries = response.objects.map((entry) => { + entry.dateFromNow = moment.unix(entry.date).fromNow() + if (entry.thumb) { + const imagePath = escape(entry.thumb.substr(8, entry.thumb.length)) + entry.mediaPublished = thumborURL.setImagePath(imagePath).resize(screen.width * screen.scale, 310).smartCrop(true).buildUrl() + } + return entry }); - } + this.setState({ + dataSource: this.state.dataSource.cloneWithRows(entries), + published: entries, + isFetching: false, + }) + }) + .catch(() => this.setState({isFetching: false})) + }) + } - renderRow(rowData, sectionID, rowID, highlightRow) { - return ( - - ); - } + renderRow (rowData, sectionID, rowID, highlightRow) { + return ( + + ) + } _renderList() { if (this.state.published.length > 0) { @@ -70,6 +79,12 @@ class MnmPublicadas extends Component { dataSource={this.state.dataSource} renderRow={this.renderRow.bind(this)} automaticallyAdjustContentInsets={false} + refreshControl={ + + } /> ) } else { @@ -79,27 +94,28 @@ class MnmPublicadas extends Component { style={styles.centering} animating={true} color="#262626" - size="large" /> + size="large" + /> ) } return ( - - - + + + ) } } render() { return ( - - {this._renderList()} - - ); + + {this._renderList()} + + ) } } -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ progressBar: { width: 50, height: 50, @@ -117,6 +133,6 @@ var styles = StyleSheet.create({ flex: 1, backgroundColor: '#FAFAFA', } -}); +}) -module.exports = MnmPublicadas; +module.exports = MnmPublicadas