@times-components/ts-components 1.36.3 → 1.37.0
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/CHANGELOG.md +11 -0
- package/dist/components/recommended-articles/RecommendedArticles.d.ts +4 -5
- package/dist/components/recommended-articles/RecommendedArticles.js +15 -26
- package/dist/components/recommended-articles/RecommendedArticles.stories.d.ts +5 -1
- package/dist/components/recommended-articles/RecommendedArticles.stories.js +26 -52
- package/dist/components/recommended-articles/RecommendedFetch.d.ts +6 -0
- package/dist/components/recommended-articles/RecommendedFetch.js +12 -0
- package/dist/components/recommended-articles/__tests__/RecommendedArticles.test.js +26 -60
- package/dist/components/recommended-articles/__tests__/RecommendedFetch.test.d.ts +1 -0
- package/dist/components/recommended-articles/__tests__/RecommendedFetch.test.js +14 -0
- package/dist/components/recommended-articles/formatters.d.ts +41 -0
- package/dist/components/recommended-articles/formatters.js +57 -0
- package/dist/fixtures/preview-data/recommended-articles.d.ts +84 -0
- package/dist/fixtures/preview-data/recommended-articles.js +351 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +6 -6
- package/rnw.js +1 -1
- package/src/components/recommended-articles/RecommendedArticles.stories.tsx +41 -58
- package/src/components/recommended-articles/RecommendedArticles.tsx +26 -55
- package/src/components/recommended-articles/RecommendedFetch.tsx +25 -0
- package/src/components/recommended-articles/__tests__/RecommendedArticles.test.tsx +45 -75
- package/src/components/recommended-articles/__tests__/RecommendedFetch.test.tsx +23 -0
- package/src/components/recommended-articles/__tests__/__snapshots__/RecommendedArticles.test.tsx.snap +10 -55
- package/src/components/recommended-articles/__tests__/__snapshots__/RecommendedFetch.test.tsx.snap +9 -0
- package/src/components/recommended-articles/formatters.ts +100 -0
- package/src/fixtures/preview-data/recommended-articles.ts +385 -0
- package/src/index.ts +2 -2
- package/src/types/externs.d.ts +0 -7
|
@@ -1,77 +1,60 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import { showcaseConverter } from '@times-components/storybook';
|
|
4
|
-
import { MockedProvider } from '@times-components/provider-test-tools';
|
|
5
|
-
import { recommendations } from '@times-components/provider-queries';
|
|
6
4
|
|
|
5
|
+
import { FetchProvider } from '../../helpers/fetch/FetchProvider';
|
|
6
|
+
import previewData from '../../fixtures/preview-data/recommended-articles';
|
|
7
7
|
import analyticsStream from '../../fixtures/analytics-actions/analytics-actions';
|
|
8
|
+
|
|
8
9
|
import { RecommendedArticles } from './RecommendedArticles';
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
request: {
|
|
14
|
-
query: recommendations,
|
|
15
|
-
variables: {
|
|
16
|
-
publisher: 'TIMES',
|
|
17
|
-
recomArgs: {
|
|
18
|
-
userId: '1234',
|
|
19
|
-
articleId: '94a01926-719a-11ec-aacf-0736e08b15cd'
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
result: {
|
|
24
|
-
data: {
|
|
25
|
-
recommendations: {
|
|
26
|
-
__typename: 'Recommendations',
|
|
27
|
-
leadAsset: 'null',
|
|
28
|
-
articles: [
|
|
29
|
-
{
|
|
30
|
-
__typename: 'UniversalArticle',
|
|
31
|
-
headline:
|
|
32
|
-
'Whole world is against us, says top Russian strategist',
|
|
33
|
-
id: 'a9ffb7cc-d5d1-11ec-bb99-1bcd45646516',
|
|
34
|
-
media: {
|
|
35
|
-
__typename: 'Image'
|
|
36
|
-
},
|
|
37
|
-
slug:
|
|
38
|
-
'were-no-match-for-ukrainian-grit-and-firepower-says-retired-russian-colonel',
|
|
39
|
-
url:
|
|
40
|
-
'https://www.staging-thetimes.co.uk/article/were-no-match-for-ukrainian-grit-and-firepower-says-retired-russian-colonel-lhnvsfj33'
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
__typename: 'UniversalArticle',
|
|
44
|
-
headline: 'Vardys leave court with swipe at Wayne Rooney',
|
|
45
|
-
id: 'f3d730a0-d5c2-11ec-8585-951ab3afb4d2',
|
|
46
|
-
media: {
|
|
47
|
-
__typename: 'Image'
|
|
48
|
-
},
|
|
49
|
-
slug:
|
|
50
|
-
'wayne-rooney-to-give-evidence-in-wagatha-christie-trial-as-jamie-vardy-attends-court-for-first-time',
|
|
51
|
-
url:
|
|
52
|
-
'https://www.staging-thetimes.co.uk/article/wayne-rooney-to-give-evidence-in-wagatha-christie-trial-as-jamie-vardy-attends-court-for-first-time-wlzvxklc6'
|
|
53
|
-
}
|
|
54
|
-
]
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
11
|
+
export const getArticles = (data: any, numOfArticles: number) => ({
|
|
12
|
+
recommendations: {
|
|
13
|
+
articles: data.recommendations.articles.slice(0, numOfArticles)
|
|
58
14
|
}
|
|
59
|
-
|
|
15
|
+
});
|
|
60
16
|
|
|
61
|
-
const
|
|
17
|
+
const recommArticles = {
|
|
62
18
|
children: [
|
|
63
19
|
{
|
|
64
20
|
component: () => (
|
|
65
|
-
<
|
|
21
|
+
<FetchProvider previewData={getArticles(previewData, 1)}>
|
|
66
22
|
<RecommendedArticles
|
|
67
|
-
articleId="94a01926-719a-11ec-aacf-0736e08b15cd"
|
|
68
23
|
section="News"
|
|
24
|
+
isVisible
|
|
69
25
|
analyticsStream={analyticsStream}
|
|
70
26
|
/>
|
|
71
|
-
</
|
|
27
|
+
</FetchProvider>
|
|
72
28
|
),
|
|
73
|
-
|
|
74
|
-
|
|
29
|
+
name: 'Recommended Articles - 1 Article',
|
|
30
|
+
platform: 'web',
|
|
31
|
+
type: 'story'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
component: () => (
|
|
35
|
+
<FetchProvider previewData={getArticles(previewData, 2)}>
|
|
36
|
+
<RecommendedArticles
|
|
37
|
+
section="Business"
|
|
38
|
+
isVisible
|
|
39
|
+
analyticsStream={analyticsStream}
|
|
40
|
+
/>
|
|
41
|
+
</FetchProvider>
|
|
42
|
+
),
|
|
43
|
+
name: 'Recommended Articles - 2 Article',
|
|
44
|
+
platform: 'web',
|
|
45
|
+
type: 'story'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
component: () => (
|
|
49
|
+
<FetchProvider previewData={previewData}>
|
|
50
|
+
<RecommendedArticles
|
|
51
|
+
section="Sport"
|
|
52
|
+
isVisible
|
|
53
|
+
analyticsStream={analyticsStream}
|
|
54
|
+
/>
|
|
55
|
+
</FetchProvider>
|
|
56
|
+
),
|
|
57
|
+
name: 'Recommended Articles - 3 Article',
|
|
75
58
|
platform: 'web',
|
|
76
59
|
type: 'story'
|
|
77
60
|
}
|
|
@@ -79,4 +62,4 @@ const recarticles = {
|
|
|
79
62
|
name: 'Typescript Component/Recommended Articles'
|
|
80
63
|
};
|
|
81
64
|
|
|
82
|
-
showcaseConverter(module,
|
|
65
|
+
showcaseConverter(module, recommArticles);
|
|
@@ -1,69 +1,40 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
+
import { Placeholder } from '@times-components/image';
|
|
3
4
|
import RelatedArticles from '@times-components/related-articles';
|
|
4
|
-
import { GetRecommendedArticles } from '@times-components/provider';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { useFetch } from '../../helpers/fetch/FetchProvider';
|
|
7
|
+
import { getRelatedArticlesSlice } from './formatters';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
+
import { PlaceholderContainer } from '../common-styles';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
articleId: string;
|
|
11
|
+
export const RecommendedArticles: React.FC<{
|
|
12
12
|
section: string;
|
|
13
|
+
isVisible?: boolean;
|
|
13
14
|
analyticsStream?: (evt: any) => void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
setIsReady(true);
|
|
25
|
-
}, []);
|
|
15
|
+
}> = ({ section, isVisible, analyticsStream }) => {
|
|
16
|
+
const { loading, error, data } = useFetch<any>();
|
|
17
|
+
|
|
18
|
+
if (loading && isVisible) {
|
|
19
|
+
return (
|
|
20
|
+
<PlaceholderContainer>
|
|
21
|
+
<Placeholder />
|
|
22
|
+
</PlaceholderContainer>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
26
25
|
|
|
27
|
-
if (
|
|
26
|
+
if (error || data === undefined) {
|
|
28
27
|
return null;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
return (
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (isLoading || !recommendations) {
|
|
44
|
-
return (
|
|
45
|
-
<div className="placeholder">
|
|
46
|
-
<Placeholder />
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const slice: RelatedArticleSliceType = {
|
|
52
|
-
sliceName: 'StandardSlice',
|
|
53
|
-
items: recommendations
|
|
54
|
-
? recommendations.articles.map((article: any) => ({ article }))
|
|
55
|
-
: []
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<RelatedArticles
|
|
60
|
-
heading={`Today's ${section}`}
|
|
61
|
-
slice={slice}
|
|
62
|
-
isVisible
|
|
63
|
-
analyticsStream={analyticsStream}
|
|
64
|
-
/>
|
|
65
|
-
);
|
|
66
|
-
}}
|
|
67
|
-
</GetRecommendedArticles>
|
|
31
|
+
<div style={{ display: isVisible ? 'block' : 'none' }}>
|
|
32
|
+
<RelatedArticles
|
|
33
|
+
heading={`Today's ${section}`}
|
|
34
|
+
slice={getRelatedArticlesSlice(data.recommendations)}
|
|
35
|
+
isVisible
|
|
36
|
+
analyticsStream={analyticsStream}
|
|
37
|
+
/>
|
|
38
|
+
</div>
|
|
68
39
|
);
|
|
69
40
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { FetchProvider } from '../../helpers/fetch/FetchProvider';
|
|
4
|
+
import { RecommendedArticles } from './RecommendedArticles';
|
|
5
|
+
|
|
6
|
+
export const RecommendedFetch: React.FC<{
|
|
7
|
+
articleId: string;
|
|
8
|
+
section: string;
|
|
9
|
+
analyticsStream?: (evt: any) => void;
|
|
10
|
+
}> = ({ articleId, section, analyticsStream }) => {
|
|
11
|
+
const [isClientSide, setIsClientSide] = useState<boolean>(false);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
setIsClientSide(true);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return isClientSide ? (
|
|
18
|
+
<FetchProvider url={`/api/recommended-articles/${articleId}`}>
|
|
19
|
+
<RecommendedArticles
|
|
20
|
+
section={section}
|
|
21
|
+
analyticsStream={analyticsStream}
|
|
22
|
+
/>
|
|
23
|
+
</FetchProvider>
|
|
24
|
+
) : null;
|
|
25
|
+
};
|
|
@@ -1,91 +1,61 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { useFetch } from '../../../helpers/fetch/FetchProvider';
|
|
5
|
+
import previewData from '../../../fixtures/preview-data/recommended-articles';
|
|
3
6
|
|
|
4
7
|
import { RecommendedArticles } from '../RecommendedArticles';
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
jest.mock('@times-components/image', () => ({
|
|
10
|
+
Placeholder: () => <div>Placeholder</div>
|
|
11
|
+
}));
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
{
|
|
11
|
-
delay: 1000,
|
|
12
|
-
request: {
|
|
13
|
-
query: recommendations,
|
|
14
|
-
variables: {
|
|
15
|
-
publisher: 'TIMES',
|
|
16
|
-
recomArgs: {
|
|
17
|
-
userId: '1234',
|
|
18
|
-
articleId: '94a01926-719a-11ec-aacf-0736e08b15cd'
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
result: {
|
|
23
|
-
data: {
|
|
24
|
-
recommendations: {
|
|
25
|
-
__typename: 'Recommendations',
|
|
26
|
-
leadAsset: 'null',
|
|
27
|
-
articles: [
|
|
28
|
-
{
|
|
29
|
-
__typename: 'UniversalArticle',
|
|
30
|
-
headline:
|
|
31
|
-
'Whole world is against us, says top Russian strategist',
|
|
32
|
-
id: 'a9ffb7cc-d5d1-11ec-bb99-1bcd45646516',
|
|
33
|
-
media: {
|
|
34
|
-
__typename: 'Image'
|
|
35
|
-
},
|
|
36
|
-
slug:
|
|
37
|
-
'were-no-match-for-ukrainian-grit-and-firepower-says-retired-russian-colonel',
|
|
38
|
-
url:
|
|
39
|
-
'https://www.staging-thetimes.co.uk/article/were-no-match-for-ukrainian-grit-and-firepower-says-retired-russian-colonel-lhnvsfj33'
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
__typename: 'UniversalArticle',
|
|
43
|
-
headline: 'Vardys leave court with swipe at Wayne Rooney',
|
|
44
|
-
id: 'f3d730a0-d5c2-11ec-8585-951ab3afb4d2',
|
|
45
|
-
media: {
|
|
46
|
-
__typename: 'Image'
|
|
47
|
-
},
|
|
48
|
-
slug:
|
|
49
|
-
'wayne-rooney-to-give-evidence-in-wagatha-christie-trial-as-jamie-vardy-attends-court-for-first-time',
|
|
50
|
-
url:
|
|
51
|
-
'https://www.staging-thetimes.co.uk/article/wayne-rooney-to-give-evidence-in-wagatha-christie-trial-as-jamie-vardy-attends-court-for-first-time-wlzvxklc6'
|
|
52
|
-
}
|
|
53
|
-
]
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
];
|
|
13
|
+
jest.mock('@times-components/related-articles', () => 'RelatedArticles');
|
|
59
14
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
cleanup();
|
|
64
|
-
});
|
|
15
|
+
jest.mock('../../../helpers/fetch/FetchProvider', () => ({
|
|
16
|
+
useFetch: jest.fn()
|
|
17
|
+
}));
|
|
65
18
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
19
|
+
describe('<RecommendedArticles>', () => {
|
|
20
|
+
it('should render the initial loading state correctly', () => {
|
|
21
|
+
(useFetch as jest.Mock).mockReturnValue({ loading: true });
|
|
22
|
+
|
|
23
|
+
const { asFragment, getByText } = render(
|
|
24
|
+
<RecommendedArticles
|
|
25
|
+
section="News"
|
|
26
|
+
isVisible
|
|
27
|
+
analyticsStream={() => ({})}
|
|
28
|
+
/>
|
|
75
29
|
);
|
|
30
|
+
|
|
31
|
+
expect(getByText('Placeholder'));
|
|
76
32
|
expect(asFragment()).toMatchSnapshot();
|
|
77
33
|
});
|
|
78
34
|
|
|
79
|
-
it('
|
|
35
|
+
it('should render the error state correctly', () => {
|
|
36
|
+
(useFetch as jest.Mock).mockReturnValue({ error: 'Some error occurred' });
|
|
37
|
+
|
|
80
38
|
const { asFragment } = render(
|
|
81
|
-
<
|
|
82
|
-
<RecommendedArticles
|
|
83
|
-
articleId=""
|
|
84
|
-
section="News"
|
|
85
|
-
analyticsStream={jest.fn()}
|
|
86
|
-
/>
|
|
87
|
-
</MockedProvider>
|
|
39
|
+
<RecommendedArticles section="News" analyticsStream={() => ({})} />
|
|
88
40
|
);
|
|
41
|
+
|
|
42
|
+
expect(asFragment().firstChild).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should render RelatedArticles correctly', () => {
|
|
46
|
+
(useFetch as jest.Mock).mockReturnValue({ data: previewData });
|
|
47
|
+
|
|
48
|
+
const { container, asFragment } = render(
|
|
49
|
+
<RecommendedArticles
|
|
50
|
+
section="News"
|
|
51
|
+
isVisible
|
|
52
|
+
analyticsStream={() => ({})}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const related = container.querySelector('relatedarticles') as HTMLElement;
|
|
57
|
+
expect(related.getAttribute('heading')).toEqual("Today's News");
|
|
58
|
+
|
|
89
59
|
expect(asFragment()).toMatchSnapshot();
|
|
90
60
|
});
|
|
91
61
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { RecommendedFetch } from '../RecommendedFetch';
|
|
5
|
+
|
|
6
|
+
jest.mock('../../../helpers/fetch/FetchProvider', () => ({
|
|
7
|
+
FetchProvider: () => <div>FetchProvider</div>
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
describe('<RecommendedFetch>', () => {
|
|
11
|
+
it('should render correctly', () => {
|
|
12
|
+
const { asFragment, getByText } = render(
|
|
13
|
+
<RecommendedFetch
|
|
14
|
+
articleId="1234"
|
|
15
|
+
section="News"
|
|
16
|
+
analyticsStream={() => ({})}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
expect(getByText('FetchProvider'));
|
|
21
|
+
expect(asFragment()).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -1,70 +1,25 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[
|
|
3
|
+
exports[`<RecommendedArticles> should render RelatedArticles correctly 1`] = `
|
|
4
4
|
<DocumentFragment>
|
|
5
5
|
<div
|
|
6
|
-
|
|
6
|
+
style="display: block;"
|
|
7
7
|
>
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
width="100%"
|
|
13
|
-
>
|
|
14
|
-
<svg
|
|
15
|
-
height="auto"
|
|
16
|
-
style="max-width: 25%; max-height: 50%;"
|
|
17
|
-
version="1.1"
|
|
18
|
-
viewBox="145 50 108 120"
|
|
19
|
-
width="100%"
|
|
20
|
-
>
|
|
21
|
-
<g
|
|
22
|
-
fill="none"
|
|
23
|
-
fill-rule="evenodd"
|
|
24
|
-
stroke="none"
|
|
25
|
-
stroke-width="1"
|
|
26
|
-
>
|
|
27
|
-
<path
|
|
28
|
-
d="M211.26076,54 L211.231367,54 L147.67512,54 L145,85.7081465 L146.922096,86.4489102 C146.922096,86.4489102 164.867589,68.1355181 168.301115,65.0001546 C171.728017,61.8689133 174.237132,61.0885763 176.436179,60.3527593 C180.998206,59.169681 185.977937,59.2150255 185.977937,59.2150255 L186.109581,59.2150255 L186.109581,156.560932 L169.259886,164.473953 L169.259886,166 L228.735147,166 L228.735147,164.473953 L211.889177,156.560932 L211.889177,59.2150255 L212.01751,59.2150255 C212.01751,59.2150255 216.992272,59.169681 221.558854,60.3527593 C223.757072,61.0885763 226.266601,61.8689133 229.691848,65.0001546 C233.130341,68.1355181 251.071695,86.4489102 251.071695,86.4489102 L253,85.7081465 L250.317842,54 L211.270695,54 L211.242545,54"
|
|
29
|
-
fill="#FFFFFF"
|
|
30
|
-
/>
|
|
31
|
-
</g>
|
|
32
|
-
</svg>
|
|
33
|
-
</div>
|
|
8
|
+
<relatedarticles
|
|
9
|
+
heading="Today's News"
|
|
10
|
+
slice="[object Object]"
|
|
11
|
+
/>
|
|
34
12
|
</div>
|
|
35
13
|
</DocumentFragment>
|
|
36
14
|
`;
|
|
37
15
|
|
|
38
|
-
exports[
|
|
16
|
+
exports[`<RecommendedArticles> should render the initial loading state correctly 1`] = `
|
|
39
17
|
<DocumentFragment>
|
|
40
18
|
<div
|
|
41
|
-
class="
|
|
19
|
+
class="sc-bdVaJa dwiMsX"
|
|
42
20
|
>
|
|
43
|
-
<div
|
|
44
|
-
|
|
45
|
-
height="100%"
|
|
46
|
-
style="align-items: center; background-color: rgb(237, 237, 237); bottom: 0px; justify-content: center; left: 0px; position: absolute; right: 0px; top: 0px; z-index: 0; border-radius: 0;"
|
|
47
|
-
width="100%"
|
|
48
|
-
>
|
|
49
|
-
<svg
|
|
50
|
-
height="auto"
|
|
51
|
-
style="max-width: 25%; max-height: 50%;"
|
|
52
|
-
version="1.1"
|
|
53
|
-
viewBox="145 50 108 120"
|
|
54
|
-
width="100%"
|
|
55
|
-
>
|
|
56
|
-
<g
|
|
57
|
-
fill="none"
|
|
58
|
-
fill-rule="evenodd"
|
|
59
|
-
stroke="none"
|
|
60
|
-
stroke-width="1"
|
|
61
|
-
>
|
|
62
|
-
<path
|
|
63
|
-
d="M211.26076,54 L211.231367,54 L147.67512,54 L145,85.7081465 L146.922096,86.4489102 C146.922096,86.4489102 164.867589,68.1355181 168.301115,65.0001546 C171.728017,61.8689133 174.237132,61.0885763 176.436179,60.3527593 C180.998206,59.169681 185.977937,59.2150255 185.977937,59.2150255 L186.109581,59.2150255 L186.109581,156.560932 L169.259886,164.473953 L169.259886,166 L228.735147,166 L228.735147,164.473953 L211.889177,156.560932 L211.889177,59.2150255 L212.01751,59.2150255 C212.01751,59.2150255 216.992272,59.169681 221.558854,60.3527593 C223.757072,61.0885763 226.266601,61.8689133 229.691848,65.0001546 C233.130341,68.1355181 251.071695,86.4489102 251.071695,86.4489102 L253,85.7081465 L250.317842,54 L211.270695,54 L211.242545,54"
|
|
64
|
-
fill="#FFFFFF"
|
|
65
|
-
/>
|
|
66
|
-
</g>
|
|
67
|
-
</svg>
|
|
21
|
+
<div>
|
|
22
|
+
Placeholder
|
|
68
23
|
</div>
|
|
69
24
|
</div>
|
|
70
25
|
</DocumentFragment>
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { RelatedArticleSliceType } from '../../types/related-article-slice';
|
|
2
|
+
|
|
3
|
+
// TYPES
|
|
4
|
+
|
|
5
|
+
export type Byline =
|
|
6
|
+
| { __typename: string; type: 'author'; name: string }
|
|
7
|
+
| { __typename: string; type: 'inline'; value: string };
|
|
8
|
+
|
|
9
|
+
type MediaCrop = {
|
|
10
|
+
__typename: string;
|
|
11
|
+
url: string;
|
|
12
|
+
alt?: string;
|
|
13
|
+
aspectRatio: string;
|
|
14
|
+
};
|
|
15
|
+
type Media = { __typename: string; crops: MediaCrop[] };
|
|
16
|
+
|
|
17
|
+
export type SummaryText = { __typename: string; text: string };
|
|
18
|
+
type Summary = { __typename: string; children: SummaryText[] };
|
|
19
|
+
|
|
20
|
+
export type Article = {
|
|
21
|
+
__typename: string;
|
|
22
|
+
url: string;
|
|
23
|
+
slug: string;
|
|
24
|
+
label: string;
|
|
25
|
+
headline: string;
|
|
26
|
+
publishedDateTime: string;
|
|
27
|
+
bylines?: Byline[];
|
|
28
|
+
summary?: Summary;
|
|
29
|
+
media?: Media;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// HELPERS
|
|
33
|
+
|
|
34
|
+
const getBylineAttr = (byline: Byline) => ({
|
|
35
|
+
value: byline.type === 'author' ? byline.name : byline.value
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const getByline = (byline: Byline) => ({
|
|
39
|
+
name: byline.type,
|
|
40
|
+
children: [{ name: 'text', attributes: getBylineAttr(byline), children: [] }]
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const getBylines = (bylines?: Byline[]) => {
|
|
44
|
+
if (bylines) {
|
|
45
|
+
return bylines.map((byline: Byline) => ({ byline: [getByline(byline)] }));
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const getSummaryText = (summary: Summary) => {
|
|
51
|
+
const text = summary.children
|
|
52
|
+
.map((child: SummaryText) => child.text)
|
|
53
|
+
.join('');
|
|
54
|
+
return { value: text.slice(0, text.slice(0, 125).lastIndexOf(' ')) };
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const getSummaryParagraph = (summary: Summary) => [
|
|
58
|
+
{ name: 'text', attributes: getSummaryText(summary), children: [] }
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
const getSummary = (summary?: Summary) => {
|
|
62
|
+
if (summary && summary.children) {
|
|
63
|
+
return [{ name: 'paragraph', children: getSummaryParagraph(summary) }];
|
|
64
|
+
}
|
|
65
|
+
return [];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const getImage = (media?: Media) => {
|
|
69
|
+
if (media && media.crops) {
|
|
70
|
+
const image = media.crops.find(
|
|
71
|
+
(crop: MediaCrop) => crop.aspectRatio === '16:9'
|
|
72
|
+
);
|
|
73
|
+
return image ? { crop169: { url: image.url }, title: image.alt } : null;
|
|
74
|
+
}
|
|
75
|
+
return {};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// MAIN
|
|
79
|
+
|
|
80
|
+
export const getRelatedArticlesSlice = (
|
|
81
|
+
recommendations: any
|
|
82
|
+
): RelatedArticleSliceType => ({
|
|
83
|
+
sliceName: 'StandardSlice',
|
|
84
|
+
items: recommendations
|
|
85
|
+
? recommendations.articles
|
|
86
|
+
.map((article: Article) => ({
|
|
87
|
+
article: {
|
|
88
|
+
slug: article.slug,
|
|
89
|
+
shortIdentifier: article.url.slice(-9),
|
|
90
|
+
label: article.label,
|
|
91
|
+
headline: article.headline,
|
|
92
|
+
publishedTime: article.publishedDateTime,
|
|
93
|
+
bylines: getBylines(article.bylines),
|
|
94
|
+
summary125: getSummary(article.summary),
|
|
95
|
+
leadAsset: getImage(article.media)
|
|
96
|
+
}
|
|
97
|
+
}))
|
|
98
|
+
.slice(0, 3)
|
|
99
|
+
: []
|
|
100
|
+
});
|