diff --git a/SkillzNews/Data/SkillzNewsDataStore.js b/SkillzNews/Data/SkillzNewsDataStore.js index 398a4be..c747bb0 100644 --- a/SkillzNews/Data/SkillzNewsDataStore.js +++ b/SkillzNews/Data/SkillzNewsDataStore.js @@ -19,6 +19,7 @@ class SkillzNewsController { this.skillzMessages = SkillzNewsMessage.make(skillzMesagesData); completion(true); }).catch((error: *) => { + this.skillzMessages = [ new SkillzMessage(this.fakemesageForError()) ]; completion(true); }); } @@ -26,6 +27,22 @@ class SkillzNewsController { getSkillzMessages(): Array { return this.skillzMessages; } + + fakemesageForError(): SkillzNewsMessage { + const currentDate = new Date(); + const month = currentDate.getMonth() + 1; + const formattedDate = currentDate.getFullYear() + '-' + month + '-' + currentDate.getDate(); + + const skillzMessage = [{ + id: -1, + message: "Please refresh and try again later.", + title: "Skillz News is currently unavailable", + game_specific: false, + start_date: formattedDate, + }]; + + return skillzMessage; + } } export default new SkillzNewsController(); diff --git a/SkillzNews/Data/SkillzNewsMessage.js b/SkillzNews/Data/SkillzNewsMessage.js index 5a4cc44..688d6ff 100644 --- a/SkillzNews/Data/SkillzNewsMessage.js +++ b/SkillzNews/Data/SkillzNewsMessage.js @@ -9,6 +9,7 @@ export class SkillzNewsMessageInterface { id: number; message: string; title: string; + game_specific: boolean; start_date: string; image_url: string; } diff --git a/SkillzNews/Data/__tests__/SkillzNewsMessage-spec.js b/SkillzNews/Data/__tests__/SkillzNewsMessage-spec.js index 5e9cf3e..3cc8f6c 100644 --- a/SkillzNews/Data/__tests__/SkillzNewsMessage-spec.js +++ b/SkillzNews/Data/__tests__/SkillzNewsMessage-spec.js @@ -17,3 +17,20 @@ describe('make', () => { }); }); +describe('deep_linking_variables', () => { + const data = { + id: 10, + message: "Saying hello to the world", + title: "Hello World", + start_date: "string", + image_url: "string", + deep_link: "string", + deep_link_text: "string", + }; + + const newsMessage = new SkillzNewsMessage(data); + + it('returns deep link values', () => { + expect(newsMessage.deep_link.toEqual(data.deep_link)); + }); +}); diff --git a/SkillzNews/Message Cell/SkillzNewsMessageCell.js b/SkillzNews/Message Cell/SkillzNewsMessageCell.js index d8333db..4492cd3 100644 --- a/SkillzNews/Message Cell/SkillzNewsMessageCell.js +++ b/SkillzNews/Message Cell/SkillzNewsMessageCell.js @@ -5,10 +5,13 @@ import React from 'react'; import _ from 'lodash'; +import AppIcon from 'AppIcon'; import Label from 'Label'; import Markdown from 'react-native-markdown-renderer'; import PropTypes from 'prop-types'; import styles from 'SkillzNewsMessageCellStyles'; +import DeepLinkUtils from 'DeepLinkUtils'; +import PushButton from 'PushButton'; import { Image, @@ -20,7 +23,22 @@ export default class SkillzNewsMessageCell extends React.PureComponent { newsArticle: PropTypes.object.isRequired, } + constructor(props: any) { + super(props); + + this.state = { + newsArticle: this.props.newsArticle, + }; + } + + _renderMessageHeaderIcon(): React.Element<*> { + if (this.props.newsArticle.game_specific) { + return ( + + ); + } + return ( @@ -38,6 +56,16 @@ export default class SkillzNewsMessageCell extends React.PureComponent { ); } + _shouldRenderPlayButton(): boolean { + return this.state.newsArticle.deep_link.length> 0; + } + + _footerButtonOnPress = () => { + console.log('It works!'); + const deepLink = this.state.newsArticle.deep_link; + DeepLinkUtils.handleDeeplink(deepLink); + } + _renderBody(): React.Element<*> { return ( @@ -58,7 +86,23 @@ export default class SkillzNewsMessageCell extends React.PureComponent { {this._renderHeader()} {this._renderBody()} - + {() => { + if (!this._shouldRenderPlayButton()) { + return null; + } + + return ( + + + + ) + }} + ); } }