Skip to content

Commit

Permalink
feat: Add BETA tag on weekly/monthly cigarettes (#234)
Browse files Browse the repository at this point in the history
* Rework a lot of padding and margins

* Fix warning sign alignment

* Add tag

* Fix react-native-maps version

* Remove margin when no additional text
  • Loading branch information
amaury1093 authored Oct 1, 2019
1 parent 99cd5d3 commit 5a6d9b5
Show file tree
Hide file tree
Showing 19 changed files with 337 additions and 235 deletions.
25 changes: 13 additions & 12 deletions App/Screens/About/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const scrollViewOptions = {
};

export const aboutSections = {
about_how_results: 'about_how_results',
about_why_is_the_station_so_far_title: 'about_why_is_the_station_so_far_title'
aboutBetaInaccurate: 'aboutBetaInaccurate',
aboutWhyIsTheStationSoFarTitle: 'aboutWhyIsTheStationSoFarTitle'
};

const handleOpenAmaury = () =>
Expand Down Expand Up @@ -115,6 +115,16 @@ export function About (props: AboutProps) {
</Text>
</View>

<ScrollIntoView
onMount={navigation.getParam('scrollInto') === 'aboutBetaInaccurate'}
style={styles.section}
>
<Text style={styles.h2}>{i18n.t('about_beta_inaccurate_title')}</Text>
<Text style={theme.text}>
{i18n.t('about_beta_inaccurate_message')}
</Text>
</ScrollIntoView>

<View style={styles.section}>
<Text style={styles.h2}>
{i18n.t('about_where_does_data_come_from_title')}
Expand All @@ -130,8 +140,7 @@ export function About (props: AboutProps) {

<ScrollIntoView
onMount={
navigation.getParam('scrollInto') ===
'about_why_is_the_station_so_far_title'
navigation.getParam('scrollInto') === 'aboutWhyIsTheStationSoFarTitle'
}
style={styles.section}
>
Expand All @@ -154,14 +163,6 @@ export function About (props: AboutProps) {
</Text>
</View>

<ScrollIntoView
onMount={navigation.getParam('scrollInto') === 'about_how_results'}
style={styles.section}
>
<Text style={styles.h2}>HELLO</Text>
<Text style={theme.text}>TODO</Text>
</ScrollIntoView>

<View style={styles.credits}>
<Text style={styles.h2}>{i18n.t('about_credits_title')}</Text>
<Text style={theme.text}>
Expand Down
3 changes: 2 additions & 1 deletion App/Screens/About/Box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import React from 'react';
import { Image, Platform, StyleSheet, Text, View } from 'react-native';
import { scale } from 'react-native-size-matters';

import cigarette from '../../../../assets/images/cigarette.png';
import { i18n } from '../../../localization';
Expand Down Expand Up @@ -83,7 +84,7 @@ const styles = StyleSheet.create({
color: theme.secondaryTextColor,
fontSize: 12,
fontWeight: '900',
letterSpacing: 0.5
letterSpacing: scale(0.5)
},
micro: {
...Platform.select({
Expand Down
102 changes: 102 additions & 0 deletions App/Screens/Home/AdditionalInfo/AdditionalInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2019 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <http://www.gnu.org/licenses/>.

import React, { useContext } from 'react';
import {
StyleSheet,
Text,
TouchableOpacity,
View,
ViewProps
} from 'react-native';
import { scale } from 'react-native-size-matters';
import { NavigationInjectedProps } from 'react-navigation';

import { aboutSections } from '../../About';
import { i18n } from '../../../localization';
import { Frequency } from '../SelectFrequency';
import { ApiContext, CurrentLocationContext } from '../../../stores';
import { track } from '../../../util/amplitude';
import { isStationTooFar } from '../../../util/station';
import * as theme from '../../../util/theme';

interface AdditionalInfoProps extends NavigationInjectedProps, ViewProps {
frequency: Frequency;
}

export function AdditionalInfo (props: AdditionalInfoProps) {
const { api } = useContext(ApiContext)!;
const { currentLocation } = useContext(CurrentLocationContext);
const { frequency, navigation, style, ...rest } = props;

const isTooFar = isStationTooFar(currentLocation!, api!);

function renderBeta () {
return (
<TouchableOpacity
onPress={() => {
track('HOME_SCREEN_BETA_INACCURATE_CLICK');
navigation.navigate('About', {
scrollInto: aboutSections.aboutBetaInaccurate
});
}}
style={styles.linkToAbout}
>
<View style={styles.tag}>
<Text style={styles.tagLabel}>BETA</Text>
</View>
<Text style={theme.text}>{i18n.t('home_beta_not_accurate')}</Text>
</TouchableOpacity>
);
}

if (frequency === 'daily' && !isTooFar) {
return null;
}

return (
<View style={[theme.withPadding, style]} {...rest}>
{frequency !== 'daily'
? renderBeta()
: isTooFar && (
<Text style={theme.text}>
{i18n.t('home_station_too_far_message')}
</Text>
)}
</View>
);
}

const styles = StyleSheet.create({
linkToAbout: {
alignItems: 'center',
flexDirection: 'row'
},
tag: {
backgroundColor: '#C4C4C4',
borderRadius: scale(10),
marginRight: theme.spacing.mini,
paddingHorizontal: scale(6),
paddingVertical: scale(3)
},
tagLabel: {
color: 'white',
fontSize: scale(10),
letterSpacing: scale(1),
marginLeft: scale(2),
textAlign: 'center'
}
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2019 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
Expand All @@ -14,27 +13,4 @@
// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <http://www.gnu.org/licenses/>.

import React from 'react';
import { Image, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
import { scale } from 'react-native-size-matters';

import wait from '../../../../assets/images/wait.png';
import { CIGARETTES_HEIGHT } from '../../../components/Cigarettes';

interface WaitProps {
style?: StyleProp<ViewStyle>;
}

export function Wait ({ style }: WaitProps) {
return (
<View style={[styles.container, style]}>
<Image resizeMode="contain" source={wait} />
</View>
);
}

const styles = StyleSheet.create({
container: {
height: scale(CIGARETTES_HEIGHT)
}
});
export * from './AdditionalInfo';
89 changes: 89 additions & 0 deletions App/Screens/Home/CigaretteBlock/CigaretteBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2019 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <http://www.gnu.org/licenses/>.

import React, { useContext } from 'react';
import { StyleSheet, Text, View, ViewProps } from 'react-native';

import { Cigarettes } from '../../../components';
import { i18n } from '../../../localization';
import { Frequency } from '../SelectFrequency';
import { CurrentLocationContext } from '../../../stores';
import swearWords from './swearWords';
import * as theme from '../../../util/theme';

interface CigaretteBlockProps extends ViewProps {
cigaretteCount: number;
frequency: Frequency;
}

function getSwearWord (cigaretteCount: number) {
if (cigaretteCount <= 1) return i18n.t('home_common_oh');

// Return a random swear word
return swearWords[Math.floor(Math.random() * swearWords.length)];
}

export function CigaretteBlock (props: CigaretteBlockProps) {
const { isGps } = useContext(CurrentLocationContext)!;
const { cigaretteCount, frequency, style, ...rest } = props;

const renderCigarettesText = () => {
// Round to 1 decimal
const cigarettes = Math.round(cigaretteCount * 10) / 10;

const text = i18n.t('home_smoked_cigarette_title', {
swearWord: getSwearWord(cigaretteCount),
presentPast:
isGps && frequency === 'daily'
? i18n.t('home_common_you_smoke')
: i18n.t('home_common_you_d_smoke'),
singularPlural:
cigarettes === 1
? i18n.t('home_common_cigarette').toLowerCase()
: i18n.t('home_common_cigarettes').toLowerCase(),
cigarettes
});

const [firstPartText, secondPartText] = text.split('<');

return (
<Text style={styles.shit}>
{firstPartText}
<Text style={styles.cigarettesCount}>
{secondPartText.split('>')[0]}
</Text>
{secondPartText.split('>')[1]}
</Text>
);
};

return (
<View style={[theme.withPadding, style]} {...rest}>
<Cigarettes cigarettes={cigaretteCount} />
{renderCigarettesText()}
</View>
);
}

const styles = StyleSheet.create({
cigarettesCount: {
color: theme.primaryColor
},
shit: {
...theme.shitText,
marginTop: theme.spacing.normal
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <http://www.gnu.org/licenses/>.

export * from './Wait';
export * from './CigaretteBlock';
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <http://www.gnu.org/licenses/>.

import { i18n } from '../../localization';
import { i18n } from '../../../localization';

export default [
i18n.t('home_swear_word_shoot'),
Expand Down
32 changes: 10 additions & 22 deletions App/Screens/Home/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Sh**t! I Smoke. If not, see <http://www.gnu.org/licenses/>.

import React, { useContext } from 'react';
import { Share, StyleSheet, Text, View } from 'react-native';
import { Share, StyleSheet, View, ViewProps } from 'react-native';
import { NavigationInjectedProps } from 'react-navigation';

import { aboutSections } from '../../About';
Expand All @@ -26,29 +26,31 @@ import { track } from '../../../util/amplitude';
import { isStationTooFar } from '../../../util/station';
import * as theme from '../../../util/theme';

interface FooterProps extends NavigationInjectedProps {}
interface FooterProps extends NavigationInjectedProps, ViewProps {}

export function Footer (props: FooterProps) {
const { api } = useContext(ApiContext)!;
const { currentLocation } = useContext(CurrentLocationContext);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { navigation, style, ...rest } = props;

const isTooFar = isStationTooFar(currentLocation!, api!);

function goToAbout () {
track('HOME_SCREEN_ABOUT_CLICK');
props.navigation.navigate('About');
navigation.navigate('About');
}

function goToAboutWhySoFar () {
track('HOME_SCREEN_ABOUT_WHY_SO_FAR_CLICK');
props.navigation.navigate('About', {
scrollInto: aboutSections.about_why_is_the_station_so_far_title
navigation.navigate('About', {
scrollInto: aboutSections.aboutWhyIsTheStationSoFarTitle
});
}

function goToDetails () {
track('HOME_SCREEN_DETAILS_CLICK');
props.navigation.navigate('Details');
navigation.navigate('Details');
}

function handleShare () {
Expand Down Expand Up @@ -93,31 +95,17 @@ export function Footer (props: FooterProps) {
};

return (
<View style={styles.container}>
{isTooFar && (
<Text style={styles.isStationTooFar}>
{i18n.t('home_station_too_far_message')}
</Text>
)}
<View style={[theme.withPadding, style]} {...rest}>
{renderBigButton()}
{renderSmallButtons()}
</View>
);
}

const styles = StyleSheet.create({
container: {
...theme.withPadding,
marginBottom: theme.spacing.normal,
marginTop: theme.spacing.mini
},
isStationTooFar: {
...theme.text,
marginBottom: theme.spacing.normal
},
smallButtons: {
flexDirection: 'row',
justifyContent: 'space-around',
marginTop: theme.spacing.small
marginTop: theme.spacing.mini
}
});
Loading

0 comments on commit 5a6d9b5

Please sign in to comment.