@quintype/native-components 2.28.0 → 2.28.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin-dev-scripts/standard-version-release.sh +11 -11
- package/package.json +1 -1
- package/src/components/AlsoRead/index.js +4 -4
- package/src/components/AuthorRow/index.js +3 -3
- package/src/components/BackNavigator/index.js +6 -6
- package/src/components/Button/index.js +1 -1
- package/src/components/CollectionCard/index.js +20 -10
- package/src/components/CollectionTitle/index.js +20 -38
- package/src/components/CollectionTitle/styles.js +11 -13
- package/src/components/CustomSwitch/index.js +4 -4
- package/src/components/DailyMotionPlayer/index.js +2 -2
- package/src/components/Header/index.js +2 -2
- package/src/components/Html/index.js +4 -4
- package/src/components/IconText/index.js +4 -4
- package/src/components/JSEmbedElement/index.js +3 -3
- package/src/components/LightBoxImage/index.js +2 -2
- package/src/components/PDFReader/index.js +7 -8
- package/src/components/PDFReader/styles.js +1 -0
- package/src/components/PrimaryStoryCard/index.js +47 -92
- package/src/components/PrimaryStoryCard/styles.js +30 -49
- package/src/components/RadioButton/index.js +3 -3
- package/src/components/Rating/index.js +1 -1
- package/src/components/RelatedStoriesCard/index.js +2 -12
- package/src/components/ResponsiveImage/index.js +35 -18
- package/src/components/SecondaryStoryCard/index.js +59 -108
- package/src/components/SecondaryStoryCard/styles.js +35 -55
- package/src/components/ShareButton/index.js +1 -1
- package/src/components/Story/index.js +12 -13
- package/src/components/StoryGallery/index.js +1 -1
- package/src/components/StoryGallery/styles.js +3 -0
- package/src/components/StoryHeader/index.js +8 -8
- package/src/components/StoryTemplateIcon/index.js +1 -1
- package/src/components/StoryTemplateIcon/styles.js +1 -1
- package/src/components/StoryText/index.js +5 -2
- package/src/components/TextA/index.js +4 -4
- package/src/components/TextBigFact/index.js +4 -4
- package/src/components/TextBlockQuote/index.js +5 -5
- package/src/components/TextBlurb/index.js +3 -3
- package/src/components/TextQandA/index.js +2 -3
- package/src/components/index.js +1 -5
- package/src/components/CollectionCardNew/index.js +0 -84
- package/src/components/CollectionTitle/CollectionTitle.test.js +0 -12
- package/src/components/CollectionTitle/__snapshots__/CollectionTitle.test.js.snap +0 -3
- package/src/components/CollectionTitleNew/index.js +0 -44
- package/src/components/CollectionTitleNew/styles.js +0 -20
- package/src/components/PrimaryStoryCard/PrimaryStoryCard.test.js +0 -43
- package/src/components/PrimaryStoryCardNew/index.js +0 -106
- package/src/components/PrimaryStoryCardNew/styles.js +0 -47
- package/src/components/SecondaryStoryCard/SecondaryStoryCard.test.js +0 -51
- package/src/components/SecondaryStoryCardNew/index.js +0 -113
- package/src/components/SecondaryStoryCardNew/styles.js +0 -59
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import React, { useContext } from 'react';
|
|
4
|
-
import { TouchableOpacity, View
|
|
4
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
5
|
+
import { COMP_CONTENT_CONSTANTS } from '../../constants/component-constants/content-constants/constants';
|
|
5
6
|
import {
|
|
7
|
+
AppTheme,
|
|
6
8
|
getImageMetadata,
|
|
7
9
|
getScreenPercentageWidth,
|
|
8
|
-
getTimeInFormat
|
|
9
|
-
AppTheme,
|
|
10
|
-
stripHTML,
|
|
10
|
+
getTimeInFormat
|
|
11
11
|
} from '../../utils';
|
|
12
12
|
import { STORY_TYPES } from '../../utils/story-types';
|
|
13
|
+
import { YouTubePlayer } from '../YouTubePlayer';
|
|
13
14
|
import {
|
|
14
|
-
AuthorRow, ResponsiveImage,
|
|
15
|
+
AuthorRow, ResponsiveImage,
|
|
16
|
+
StoryTitle, Text
|
|
15
17
|
} from '../index';
|
|
16
|
-
import { YouTubePlayer } from '../YouTubePlayer';
|
|
17
18
|
import { storyHeaderStyles } from './styles';
|
|
18
|
-
import { COMP_CONTENT_CONSTANTS } from '../../constants/component-constants/content-constants/constants';
|
|
19
19
|
|
|
20
20
|
import { DailyMotionPlayer } from '../DailyMotionPlayer';
|
|
21
21
|
import { RatingLayout } from '../Rating';
|
|
22
|
-
import
|
|
22
|
+
import CustomHtmlParser from './../Html/index';
|
|
23
23
|
|
|
24
24
|
const getHeroImage = (cdn, story) => {
|
|
25
25
|
const imageSlug = story['hero-image-s3-key'];
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
import React, { useContext } from 'react';
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
I18nManager,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
Text,
|
|
7
|
+
View
|
|
5
8
|
} from 'react-native';
|
|
6
9
|
import HTML from 'react-native-render-html';
|
|
7
|
-
import { AppTheme } from '../../utils/context';
|
|
8
10
|
import { customHTMLStyles } from '../../constants/renderHTML';
|
|
11
|
+
import { AppTheme } from '../../utils/context';
|
|
9
12
|
|
|
10
13
|
import { storyTextStyles } from './styles';
|
|
11
14
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React, { useContext } from 'react';
|
|
3
|
-
import { View, StyleSheet, Linking,I18nManager } from 'react-native';
|
|
4
|
-
import { StoryText, Text } from '@quintype/native-components/src/components';
|
|
1
|
+
import { Text } from '@quintype/native-components/src/components';
|
|
5
2
|
import { textAnswerStyles } from '@quintype/native-components/src/components/TextA/styles';
|
|
6
3
|
import { AppTheme } from '@quintype/native-components/src/utils/context';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import React, { useContext } from 'react';
|
|
6
|
+
import { I18nManager, Linking, StyleSheet, View } from 'react-native';
|
|
7
7
|
import HTML from 'react-native-render-html';
|
|
8
8
|
import { customHTMLStyles } from '../../constants/renderHTML';
|
|
9
9
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
import React, { useContext } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { StyleSheet, View } from 'react-native';
|
|
4
4
|
import HTML from 'react-native-render-html';
|
|
5
|
-
import { Text } from '../index';
|
|
6
|
-
import { bigTextStyles } from './styles';
|
|
7
|
-
import { AppTheme } from '../../utils/context';
|
|
8
5
|
import { customHTMLStyles } from '../../constants/renderHTML';
|
|
9
6
|
import { alterQuoteData } from '../../utils';
|
|
7
|
+
import { AppTheme } from '../../utils/context';
|
|
8
|
+
import { Text } from '../index';
|
|
9
|
+
import { bigTextStyles } from './styles';
|
|
10
10
|
|
|
11
11
|
export const TextBigFact = ({ text, attribution, id }) => {
|
|
12
12
|
const { theme, useDeeplinkHandler } = useContext(AppTheme);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
import React, { useContext } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import Icon from 'react-native-vector-icons/FontAwesome';
|
|
3
|
+
import { StyleSheet, View } from 'react-native';
|
|
5
4
|
import HTML from 'react-native-render-html';
|
|
6
|
-
import
|
|
5
|
+
import Icon from 'react-native-vector-icons/FontAwesome';
|
|
7
6
|
import { customHTMLStyles } from '../../constants/renderHTML';
|
|
8
|
-
import { blockQuoteTextStyles } from './styles';
|
|
9
|
-
import { AppTheme } from '../../utils/context';
|
|
10
7
|
import { alterQuoteData } from '../../utils';
|
|
8
|
+
import { AppTheme } from '../../utils/context';
|
|
9
|
+
import { Text } from '../index';
|
|
10
|
+
import { blockQuoteTextStyles } from './styles';
|
|
11
11
|
|
|
12
12
|
export const TextBlockQuote = ({ text, attribution }) => {
|
|
13
13
|
const { theme, useDeeplinkHandler } = useContext(AppTheme);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
import React, { useContext } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { StyleSheet, View } from 'react-native';
|
|
4
4
|
import HTML from 'react-native-render-html';
|
|
5
|
-
import { textBlurbStyles } from './styles';
|
|
6
|
-
import { AppTheme } from '../../utils/context';
|
|
7
5
|
import { customHTMLStyles } from '../../constants/renderHTML';
|
|
6
|
+
import { AppTheme } from '../../utils/context';
|
|
7
|
+
import { textBlurbStyles } from './styles';
|
|
8
8
|
|
|
9
9
|
export const TextBlurb = ({ text }) => {
|
|
10
10
|
const { theme, useDeeplinkHandler } = useContext(AppTheme);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
import React, { useContext } from 'react';
|
|
3
3
|
import { View } from 'react-native';
|
|
4
|
-
import { Text } from '../index';
|
|
5
|
-
import { textQandAStyles } from './styles';
|
|
6
4
|
import { AppTheme } from '../../utils/context';
|
|
7
|
-
import { TextQ } from '../TextQ/index';
|
|
8
5
|
import { TextA } from '../TextA/index';
|
|
6
|
+
import { TextQ } from '../TextQ/index';
|
|
7
|
+
import { textQandAStyles } from './styles';
|
|
9
8
|
|
|
10
9
|
export const TextQandA = ({ question, answer }) => {
|
|
11
10
|
const { theme } = useContext(AppTheme);
|
package/src/components/index.js
CHANGED
|
@@ -3,21 +3,17 @@ export { AuthorRow } from './AuthorRow';
|
|
|
3
3
|
export { BackNavigator } from './BackNavigator';
|
|
4
4
|
export { Button } from './Button';
|
|
5
5
|
export { CollectionCard } from './CollectionCard';
|
|
6
|
-
export { CollectionCardNew } from './CollectionCardNew';
|
|
7
6
|
export { CollectionTitle } from './CollectionTitle';
|
|
8
|
-
export { CollectionTitleNew } from './CollectionTitleNew';
|
|
9
7
|
export { CustomLoader } from './CustomLoader';
|
|
10
8
|
export { FBCommentsRow } from './FBCommentsRow';
|
|
11
9
|
export { Header } from './Header';
|
|
12
10
|
export { JSEmbedElement } from './JSEmbedElement';
|
|
13
11
|
export { PDFReader } from './PDFReader';
|
|
14
12
|
export { PrimaryStoryCard } from './PrimaryStoryCard';
|
|
15
|
-
export { PrimaryStoryCardNew } from './PrimaryStoryCardNew';
|
|
16
13
|
export { RadioButton } from './RadioButton';
|
|
17
14
|
export { ResponsiveImage } from './ResponsiveImage';
|
|
18
15
|
export { Search } from './Search';
|
|
19
16
|
export { SecondaryStoryCard } from './SecondaryStoryCard';
|
|
20
|
-
export { SecondaryStoryCardNew } from './SecondaryStoryCardNew';
|
|
21
17
|
export { ShareButton } from './ShareButton';
|
|
22
18
|
export { Story } from './Story';
|
|
23
19
|
export { StoryContent } from './StoryContent';
|
|
@@ -44,7 +40,7 @@ export { IconText } from './IconText';
|
|
|
44
40
|
export { CustomSwitch } from './CustomSwitch';
|
|
45
41
|
export { RelatedStoriesCard } from './RelatedStoriesCard';
|
|
46
42
|
export { References } from './References';
|
|
47
|
-
export { StoryTemplateIcon } from './StoryTemplateIcon'
|
|
48
43
|
export { StoryCardDetailsRow } from './StoryCardDetailsRow';
|
|
49
44
|
export { TextA } from './TextA'
|
|
50
45
|
export { TextQ } from './TextQ'
|
|
46
|
+
export { StoryTemplateIcon } from './StoryTemplateIcon'
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import get from 'lodash/get';
|
|
2
|
-
import isEmpty from 'lodash/isEmpty';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import React, { memo } from 'react';
|
|
5
|
-
import { getScreenPercentageWidth } from '../../utils/index';
|
|
6
|
-
import {
|
|
7
|
-
CollectionTitleNew,
|
|
8
|
-
PrimaryStoryCardNew,
|
|
9
|
-
SecondaryStoryCardNew,
|
|
10
|
-
ShareButton,
|
|
11
|
-
} from '../index';
|
|
12
|
-
|
|
13
|
-
const CollectionCardNewBase = ({
|
|
14
|
-
cdn,
|
|
15
|
-
collectionName,
|
|
16
|
-
stories,
|
|
17
|
-
onCollectionPress,
|
|
18
|
-
onStoryPress,
|
|
19
|
-
collectionTestID,
|
|
20
|
-
offset,
|
|
21
|
-
horizontalPadding,
|
|
22
|
-
initialOffset, /* Number of items to load on first load */
|
|
23
|
-
hideCollectionTitle,
|
|
24
|
-
}) => {
|
|
25
|
-
const sliceLimit = offset || initialOffset || 5;
|
|
26
|
-
const primaryStory = !isEmpty(stories) && get(stories, [0, 'story'], stories[0]);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<>
|
|
30
|
-
{!hideCollectionTitle && (
|
|
31
|
-
<CollectionTitleNew
|
|
32
|
-
title={collectionName}
|
|
33
|
-
onPress={onCollectionPress}
|
|
34
|
-
horizontalPadding={horizontalPadding}
|
|
35
|
-
/>
|
|
36
|
-
)}
|
|
37
|
-
<PrimaryStoryCardNew
|
|
38
|
-
collectionTestID={collectionTestID}
|
|
39
|
-
onPress={() => {
|
|
40
|
-
!isEmpty(stories) && onStoryPress(primaryStory);
|
|
41
|
-
}}
|
|
42
|
-
cdn={cdn}
|
|
43
|
-
story={!isEmpty(stories) ? primaryStory : {}}
|
|
44
|
-
iconComponent={<ShareButton story={primaryStory} inListingStoryCard />}
|
|
45
|
-
imageWidth={getScreenPercentageWidth(100) - 2 * horizontalPadding}
|
|
46
|
-
horizontalPadding={horizontalPadding}
|
|
47
|
-
/>
|
|
48
|
-
{stories.slice(1, sliceLimit).map((currentStory) => {
|
|
49
|
-
const secondaryStory = get(currentStory, ['story'], currentStory);
|
|
50
|
-
return (
|
|
51
|
-
<SecondaryStoryCardNew
|
|
52
|
-
collectionTestID={collectionTestID}
|
|
53
|
-
onPress={() => onStoryPress(secondaryStory)}
|
|
54
|
-
key={secondaryStory?.id}
|
|
55
|
-
cdn={cdn}
|
|
56
|
-
story={secondaryStory}
|
|
57
|
-
iconComponent={<ShareButton story={secondaryStory} inListingStoryCard />}
|
|
58
|
-
imageWidth={getScreenPercentageWidth(28)}
|
|
59
|
-
horizontalPadding={horizontalPadding}
|
|
60
|
-
/>
|
|
61
|
-
);
|
|
62
|
-
})}
|
|
63
|
-
</>
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
CollectionCardNewBase.propTypes = {
|
|
68
|
-
offset: PropTypes.number,
|
|
69
|
-
initialOffset: PropTypes.number,
|
|
70
|
-
cdn: PropTypes.string.isRequired,
|
|
71
|
-
collectionName: PropTypes.string,
|
|
72
|
-
stories: PropTypes.array.isRequired,
|
|
73
|
-
onCollectionPress: PropTypes.func,
|
|
74
|
-
onStoryPress: PropTypes.func,
|
|
75
|
-
collectionTestID: PropTypes.string,
|
|
76
|
-
horizontalPadding: PropTypes.number,
|
|
77
|
-
hideCollectionTitle: PropTypes.bool,
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
CollectionCardNewBase.defaultProps = {
|
|
81
|
-
horizontalPadding: 12,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export const CollectionCardNew = memo(CollectionCardNewBase);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import 'react-native';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import renderer from 'react-test-renderer';
|
|
4
|
-
|
|
5
|
-
import { CollectionTitle } from './index';
|
|
6
|
-
import { mockContext } from '../../utils';
|
|
7
|
-
|
|
8
|
-
test('renders correctly', () => {
|
|
9
|
-
const component = mockContext(<CollectionTitle />);
|
|
10
|
-
const tree = renderer.create(component).toJSON();
|
|
11
|
-
expect(tree).toMatchSnapshot();
|
|
12
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
|
-
import React, { useContext, memo } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
TextStyle,
|
|
5
|
-
TouchableOpacity,
|
|
6
|
-
TouchableOpacityProps,
|
|
7
|
-
StyleSheet,
|
|
8
|
-
} from 'react-native';
|
|
9
|
-
import { Text } from '../index';
|
|
10
|
-
import { collectionTitleStyles } from './styles';
|
|
11
|
-
import { AppTheme } from '../../utils';
|
|
12
|
-
|
|
13
|
-
const CollectionTitleNewBase = (props) => {
|
|
14
|
-
const { theme } = useContext(AppTheme);
|
|
15
|
-
const styles = collectionTitleStyles(theme);
|
|
16
|
-
const containerStyle = StyleSheet.flatten([
|
|
17
|
-
styles.container,
|
|
18
|
-
{ paddingHorizontal: props.horizontalPadding },
|
|
19
|
-
]);
|
|
20
|
-
const titleStyle = StyleSheet.flatten([styles.title, props.titleStyle]);
|
|
21
|
-
|
|
22
|
-
if (!props.title) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<TouchableOpacity style={containerStyle} onPress={props.onPress}>
|
|
28
|
-
<Text style={titleStyle}>{props.title}</Text>
|
|
29
|
-
</TouchableOpacity>
|
|
30
|
-
);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
CollectionTitleNewBase.propTypes = TouchableOpacityProps
|
|
34
|
-
&& {
|
|
35
|
-
title: PropTypes.string,
|
|
36
|
-
titleStyle: TextStyle,
|
|
37
|
-
horizontalPadding: PropTypes.number,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
CollectionTitleNewBase.defaultProps = {
|
|
41
|
-
horizontalPadding: 12,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const CollectionTitleNew = memo(CollectionTitleNewBase);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native';
|
|
2
|
-
|
|
3
|
-
export const collectionTitleStyles = (appThemeContext) => {
|
|
4
|
-
const { COLORS, FONT_SIZE, FONT_FAMILY } = appThemeContext;
|
|
5
|
-
|
|
6
|
-
return StyleSheet.create({
|
|
7
|
-
container: {
|
|
8
|
-
justifyContent: 'center',
|
|
9
|
-
backgroundColor: COLORS.BRAND_WHITE,
|
|
10
|
-
paddingHorizontal: 12,
|
|
11
|
-
paddingVertical: 8,
|
|
12
|
-
marginTop: 8,
|
|
13
|
-
},
|
|
14
|
-
title: {
|
|
15
|
-
fontSize: FONT_SIZE.h3,
|
|
16
|
-
fontFamily: FONT_FAMILY.secondaryBold,
|
|
17
|
-
color: COLORS.BRAND_5,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { cleanup, render, fireEvent } from '@testing-library/react-native';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import 'react-native';
|
|
4
|
-
import { mockContext } from '../../utils';
|
|
5
|
-
import { PrimaryStoryCard } from './index';
|
|
6
|
-
import { data } from '../../constants/test-data/story.json';
|
|
7
|
-
import { COMP_GENERAL_CONSTANTS } from '../../constants/component-constants/general-constants/constants';
|
|
8
|
-
|
|
9
|
-
const storyData = data.story;
|
|
10
|
-
const onPress = jest.fn();
|
|
11
|
-
|
|
12
|
-
describe('Test Primary Story Card :', () => {
|
|
13
|
-
afterEach(cleanup);
|
|
14
|
-
test('renders author name properly', () => {
|
|
15
|
-
const { getByTestId } = render(
|
|
16
|
-
mockContext(<PrimaryStoryCard story={storyData} />),
|
|
17
|
-
);
|
|
18
|
-
const element = getByTestId(COMP_GENERAL_CONSTANTS.primaryStoryAuthor);
|
|
19
|
-
expect(element.props.children).toBe('By Raghavendra Vaidya | ');
|
|
20
|
-
});
|
|
21
|
-
test('renders story headline properly', () => {
|
|
22
|
-
const { getByTestId } = render(
|
|
23
|
-
mockContext(<PrimaryStoryCard story={storyData} />),
|
|
24
|
-
);
|
|
25
|
-
const element = getByTestId(COMP_GENERAL_CONSTANTS.primaryStoryHeadline);
|
|
26
|
-
expect(element.props.children).toBe('Jack and jill');
|
|
27
|
-
});
|
|
28
|
-
test('renders story publish date properly', () => {
|
|
29
|
-
const { getByTestId } = render(
|
|
30
|
-
mockContext(<PrimaryStoryCard story={storyData} />),
|
|
31
|
-
);
|
|
32
|
-
const element = getByTestId(COMP_GENERAL_CONSTANTS.primaryStoryPubishedAt);
|
|
33
|
-
expect(element.props.children).toBe('1 Feb, 2021');
|
|
34
|
-
});
|
|
35
|
-
test('OnPress handler called properly', () => {
|
|
36
|
-
const { getByTestId } = render(
|
|
37
|
-
mockContext(<PrimaryStoryCard story={storyData} onPress={onPress} />),
|
|
38
|
-
);
|
|
39
|
-
const element = getByTestId(COMP_GENERAL_CONSTANTS.primaryStoryCard);
|
|
40
|
-
fireEvent(element, 'press');
|
|
41
|
-
expect(onPress).toHaveBeenCalled();
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { get, throttle } from 'lodash';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import React, { useContext, memo } from 'react';
|
|
4
|
-
import { StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
5
|
-
import {
|
|
6
|
-
AppTheme,
|
|
7
|
-
getImageMetadata,
|
|
8
|
-
getImageSlug,
|
|
9
|
-
} from '../../utils';
|
|
10
|
-
import { getStoryHeadline } from '../../utils/story';
|
|
11
|
-
import { ResponsiveImage, Text, StoryCardDetailsRow, StoryTemplateIcon } from '../index';
|
|
12
|
-
import { storyStyles } from './styles';
|
|
13
|
-
import {
|
|
14
|
-
COMP_GENERAL_CONSTANTS,
|
|
15
|
-
COMP_CONTENT_CONSTANTS,
|
|
16
|
-
} from '../../constants/component-constants';
|
|
17
|
-
import PremiumIcons from '../../Icons/PremiumIcons/index';
|
|
18
|
-
|
|
19
|
-
const PrimaryStoryCardNewBase = (props) => {
|
|
20
|
-
const { story = {} } = props;
|
|
21
|
-
const { theme } = useContext(AppTheme);
|
|
22
|
-
const {
|
|
23
|
-
COLORS,
|
|
24
|
-
FONT_SIZE,
|
|
25
|
-
premiumIcon,
|
|
26
|
-
storyCardOptions = {},
|
|
27
|
-
} = theme || {};
|
|
28
|
-
|
|
29
|
-
const styles = storyStyles(theme);
|
|
30
|
-
const containerStyle = StyleSheet.flatten([
|
|
31
|
-
styles.container,
|
|
32
|
-
{ paddingHorizontal: props.horizontalPadding },
|
|
33
|
-
]);
|
|
34
|
-
const headlineStyle = StyleSheet.flatten([
|
|
35
|
-
styles.headline,
|
|
36
|
-
props.headlineStyle,
|
|
37
|
-
]);
|
|
38
|
-
|
|
39
|
-
const isPremiumStory = story['access'] === 'subscription';
|
|
40
|
-
|
|
41
|
-
const throttledOnpress = throttle(props.onPress, 1000);
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<>
|
|
45
|
-
<TouchableOpacity
|
|
46
|
-
testID={COMP_GENERAL_CONSTANTS.primaryStoryCard}
|
|
47
|
-
onPress={throttledOnpress}
|
|
48
|
-
activeOpacity={0.8}
|
|
49
|
-
style={containerStyle}
|
|
50
|
-
>
|
|
51
|
-
<ResponsiveImage
|
|
52
|
-
metaData={getImageMetadata(story)}
|
|
53
|
-
slug={getImageSlug(story)}
|
|
54
|
-
cdn={props.cdn}
|
|
55
|
-
imageWidth={props.imageWidth}
|
|
56
|
-
>
|
|
57
|
-
<View style={styles.storyTypeContainer}>
|
|
58
|
-
<StoryTemplateIcon storyTemplate={story['story-template']} cardType="primary" theme={theme} />
|
|
59
|
-
</View>
|
|
60
|
-
</ResponsiveImage>
|
|
61
|
-
<View style={styles.contentContainer}>
|
|
62
|
-
<View style={styles.headlineAndTimestampContainer}>
|
|
63
|
-
{storyCardOptions.enableSectionName && <Text numberOfLines={1} ellipsizeMode="tail" style={styles.sectionName}>{get(story, ['sections', 0, 'display-name'], '')}</Text>}
|
|
64
|
-
<View style={{display:'flex', flexDirection:'row'}}>
|
|
65
|
-
<Text
|
|
66
|
-
primary
|
|
67
|
-
numberOfLines={storyCardOptions.numberOfLinesForTitle}
|
|
68
|
-
ellipsizeMode="tail"
|
|
69
|
-
style={headlineStyle}
|
|
70
|
-
testID={COMP_GENERAL_CONSTANTS.primaryStoryHeadline}
|
|
71
|
-
>
|
|
72
|
-
{isPremiumStory && premiumIcon !=='none' && <PremiumIcons style={styles.premiumIcon} name={premiumIcon} color={COLORS.primary} size={FONT_SIZE.h2} /> }
|
|
73
|
-
{isPremiumStory && premiumIcon !=='none' && ' '}
|
|
74
|
-
{getStoryHeadline(story)}
|
|
75
|
-
</Text>
|
|
76
|
-
</View>
|
|
77
|
-
<StoryCardDetailsRow
|
|
78
|
-
authorName={get(story.authors, [0, 'name'])}
|
|
79
|
-
publishedAt={story["published-at"]}
|
|
80
|
-
readTime={story['read-time']}
|
|
81
|
-
/>
|
|
82
|
-
</View>
|
|
83
|
-
<View style={styles.icon}>{props.iconComponent}</View>
|
|
84
|
-
</View>
|
|
85
|
-
</TouchableOpacity>
|
|
86
|
-
<View style={[styles.separatorLine, {marginHorizontal: props.horizontalPadding}]}/>
|
|
87
|
-
</>
|
|
88
|
-
);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
PrimaryStoryCardNewBase.propTypes = {
|
|
92
|
-
cdn: PropTypes.string,
|
|
93
|
-
imageWidth: PropTypes.number,
|
|
94
|
-
headlineStyle: PropTypes.func,
|
|
95
|
-
story: PropTypes.object.isRequired,
|
|
96
|
-
onPress: PropTypes.func,
|
|
97
|
-
horizontalPadding: PropTypes.number,
|
|
98
|
-
iconComponent: PropTypes.element,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
PrimaryStoryCardNewBase.defaultProps = {
|
|
102
|
-
cdn: '',
|
|
103
|
-
horizontalPadding: 12,
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export const PrimaryStoryCardNew = memo(PrimaryStoryCardNewBase);
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export const storyStyles = ({COLORS, FONT_SIZE, FONT_FAMILY, lineHeightMultiplier, storyCardOptions = {}}) => ({
|
|
2
|
-
container: {
|
|
3
|
-
backgroundColor: COLORS.BRAND_WHITE,
|
|
4
|
-
paddingVertical: 10,
|
|
5
|
-
gap: 10,
|
|
6
|
-
},
|
|
7
|
-
contentContainer: {
|
|
8
|
-
flexDirection: 'row',
|
|
9
|
-
justifyContent: 'space-between',
|
|
10
|
-
alignItems: 'flex-start',
|
|
11
|
-
gap: 10,
|
|
12
|
-
},
|
|
13
|
-
headlineAndTimestampContainer: {
|
|
14
|
-
flexShrink: 1,
|
|
15
|
-
gap: 4,
|
|
16
|
-
},
|
|
17
|
-
icon: {
|
|
18
|
-
marginBottom: 4,
|
|
19
|
-
marginTop: storyCardOptions.enableSectionName ? FONT_SIZE.h4 * lineHeightMultiplier + 8 : 4,
|
|
20
|
-
},
|
|
21
|
-
sectionName: {
|
|
22
|
-
color: COLORS.BRAND_1,
|
|
23
|
-
fontSize: FONT_SIZE.h4,
|
|
24
|
-
lineHeight: FONT_SIZE.h4 * lineHeightMultiplier,
|
|
25
|
-
},
|
|
26
|
-
headline: {
|
|
27
|
-
fontFamily: FONT_FAMILY.primaryBold,
|
|
28
|
-
fontSize: FONT_SIZE.title,
|
|
29
|
-
lineHeight: FONT_SIZE.title * lineHeightMultiplier,
|
|
30
|
-
color: COLORS.BRAND_BLACK,
|
|
31
|
-
marginBottom: 4,
|
|
32
|
-
},
|
|
33
|
-
storyTypeContainer: {
|
|
34
|
-
position: 'absolute',
|
|
35
|
-
bottom: 0,
|
|
36
|
-
left: 0,
|
|
37
|
-
},
|
|
38
|
-
premiumIcon: {
|
|
39
|
-
marginTop: FONT_SIZE.h3 * 0.92,
|
|
40
|
-
marginRight: 5,
|
|
41
|
-
},
|
|
42
|
-
separatorLine: {
|
|
43
|
-
height: 0.8,
|
|
44
|
-
opacity: 0.1,
|
|
45
|
-
backgroundColor: COLORS.BRAND_BLACK,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { cleanup, render, fireEvent } from '@testing-library/react-native';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import 'react-native';
|
|
4
|
-
import { mockContext } from '../../utils';
|
|
5
|
-
import { SecondaryStoryCard } from './index';
|
|
6
|
-
import { data } from '../../constants/test-data/story.json';
|
|
7
|
-
import { COMP_GENERAL_CONSTANTS } from '../../constants/component-constants/general-constants/constants';
|
|
8
|
-
|
|
9
|
-
const storyData = data.story;
|
|
10
|
-
const onPress = jest.fn();
|
|
11
|
-
|
|
12
|
-
describe('Test Secondary Story Card :', () => {
|
|
13
|
-
afterEach(cleanup);
|
|
14
|
-
test('renders author name properly', () => {
|
|
15
|
-
const { getByTestId } = render(
|
|
16
|
-
mockContext(<SecondaryStoryCard story={storyData} />),
|
|
17
|
-
);
|
|
18
|
-
const element = getByTestId(COMP_GENERAL_CONSTANTS.secondaryStoryAuthor);
|
|
19
|
-
expect(element.props.children).toBe('By Raghavendra Vaidya | ');
|
|
20
|
-
});
|
|
21
|
-
test('renders story headline properly', () => {
|
|
22
|
-
const { getByTestId } = render(
|
|
23
|
-
mockContext(<SecondaryStoryCard story={storyData} />),
|
|
24
|
-
);
|
|
25
|
-
const element = getByTestId(COMP_GENERAL_CONSTANTS.secondaryStoryHeadline);
|
|
26
|
-
expect(element.props.children).toBe('Jack and jill');
|
|
27
|
-
});
|
|
28
|
-
test('renders story date properly', () => {
|
|
29
|
-
const { getByTestId } = render(
|
|
30
|
-
mockContext(<SecondaryStoryCard story={storyData} />),
|
|
31
|
-
);
|
|
32
|
-
const element = getByTestId(
|
|
33
|
-
COMP_GENERAL_CONSTANTS.secondaryStoryPubishedAt,
|
|
34
|
-
);
|
|
35
|
-
expect(element.props.children).toBe('1 Feb, 2021');
|
|
36
|
-
});
|
|
37
|
-
test('OnPress handler called properly', () => {
|
|
38
|
-
const { getByTestId } = render(
|
|
39
|
-
mockContext(
|
|
40
|
-
<SecondaryStoryCard
|
|
41
|
-
story={storyData}
|
|
42
|
-
onPress={onPress}
|
|
43
|
-
collectionTestID="secondaryStoryCardView"
|
|
44
|
-
/>,
|
|
45
|
-
),
|
|
46
|
-
);
|
|
47
|
-
const element = getByTestId(COMP_GENERAL_CONSTANTS.secondaryStoryCard);
|
|
48
|
-
fireEvent(element, 'press');
|
|
49
|
-
expect(onPress).toHaveBeenCalled();
|
|
50
|
-
});
|
|
51
|
-
});
|