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

Feature small changes #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions SkillzNews/Data/SkillzNewsDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,30 @@ class SkillzNewsController {
this.skillzMessages = SkillzNewsMessage.make(skillzMesagesData);
completion(true);
}).catch((error: *) => {
this.skillzMessages = [ new SkillzMessage(this.fakemesageForError()) ];
completion(true);
});
}

getSkillzMessages(): Array<SkillzNewsMessage> {
return this.skillzMessages;
}

fakemesageForError(): SkillzNewsMessage {
Comment on lines +30 to +31
Copy link
Owner Author

@hle-skillz hle-skillz Feb 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hobbs: I would not have put this function here.

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();
1 change: 1 addition & 0 deletions SkillzNews/Data/SkillzNewsMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class SkillzNewsMessageInterface {
id: number;
message: string;
title: string;
game_specific: boolean;
start_date: string;
image_url: string;
}
Expand Down
17 changes: 17 additions & 0 deletions SkillzNews/Data/__tests__/SkillzNewsMessage-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
Comment on lines +26 to +29
Copy link
Owner Author

@hle-skillz hle-skillz Feb 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hobbs: You should use real life data in your tests.


const newsMessage = new SkillzNewsMessage(data);

it('returns deep link values', () => {
expect(newsMessage.deep_link.toEqual(data.deep_link));
});
});
46 changes: 45 additions & 1 deletion SkillzNews/Message Cell/SkillzNewsMessageCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Owner Author

@hle-skillz hle-skillz Feb 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hobbs: This isn't in alphabetical order, fix it.

import PushButton from 'PushButton';

import {
Image,
Expand All @@ -20,7 +23,22 @@ export default class SkillzNewsMessageCell extends React.PureComponent {
newsArticle: PropTypes.object.isRequired,
}

constructor(props: any) {
Copy link
Owner Author

@hle-skillz hle-skillz Feb 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hobbs: This should obviously be a stateless component, do you have any real need for state here, why are you using it?

super(props);

this.state = {
newsArticle: this.props.newsArticle,
};
}


_renderMessageHeaderIcon(): React.Element<*> {
if (this.props.newsArticle.game_specific) {
return (
<AppIcon style={styles.headerAppIcon}/>
);
}

return (
<SkillzImage source={'skillz_app_icon.png'}
style={styles.headerIcon}/>
Expand All @@ -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 (
<View style={styles.bodyContainer}>
Expand All @@ -58,7 +86,23 @@ export default class SkillzNewsMessageCell extends React.PureComponent {
<View style={styles.containerView}>
{this._renderHeader()}
{this._renderBody()}
</View>
{() => {
if (!this._shouldRenderPlayButton()) {
return null;
}

return (
<View style={styles.footerView}>
<PushButton onPress={this._footerButtonOnPress}
title={this.state.newsArticle.deep_link_text.toUpperCase()}
style={styles.playButton}
textStyle={styles.playButtonText}
colors={SkillzStyle.fullStyles.btnGradientOne}
cornerRadius={SkillzStyle.fullStyles.viewCornerRadiusSecondary.borderRadius}/>
</View>
)
}}
</View>
);
}
}