@newskit-render/core 2.3.1 → 2.4.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 +16 -0
- package/package.json +6 -6
- package/pages/_app.tsx +10 -14
- package/pages/preview/[articleId]/version/[versionId]/index.tsx +70 -28
- package/temp/_app.tsx +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.4.0](https://github.com/newscorp-ghfb/ncu-newskit-render/compare/@newskit-render/core@2.4.0-alpha.0...@newskit-render/core@2.4.0) (2022-10-11)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @newskit-render/core
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.3.2](https://github.com/newscorp-ghfb/ncu-newskit-render/compare/@newskit-render/core@2.3.2-alpha.0...@newskit-render/core@2.3.2) (2022-10-07)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @newskit-render/core
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [2.3.1](https://github.com/newscorp-ghfb/ncu-newskit-render/compare/@newskit-render/core@2.3.1-alpha.0...@newskit-render/core@2.3.1) (2022-10-06)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @newskit-render/core
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newskit-render/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Newskit Render - Core package",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"@emotion/styled": "11.10.4",
|
|
41
41
|
"@newskit-render/api": "^1.1.0",
|
|
42
42
|
"@newskit-render/auth": "^1.0.1",
|
|
43
|
-
"@newskit-render/checkout": "^1.0.
|
|
43
|
+
"@newskit-render/checkout": "^1.0.6",
|
|
44
44
|
"@newskit-render/feature-flags": "^1.0.0",
|
|
45
45
|
"@newskit-render/feed": "^1.0.1",
|
|
46
|
-
"@newskit-render/my-account": "^3.
|
|
47
|
-
"@newskit-render/shared-components": "^1.
|
|
48
|
-
"@newskit-render/standalone-components": "^1.
|
|
49
|
-
"@newskit-render/validation": "^1.
|
|
46
|
+
"@newskit-render/my-account": "^3.4.1",
|
|
47
|
+
"@newskit-render/shared-components": "^1.3.0",
|
|
48
|
+
"@newskit-render/standalone-components": "^1.3.0",
|
|
49
|
+
"@newskit-render/validation": "^1.1.0",
|
|
50
50
|
"cross-fetch": "3.1.5",
|
|
51
51
|
"graphql": "15.6.0",
|
|
52
52
|
"lodash.get": "4.4.2",
|
package/pages/_app.tsx
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
1
|
import React from 'react'
|
|
3
2
|
import { AppContext as AppContextType, AppProps } from 'next/app'
|
|
4
3
|
import Head from 'next/head'
|
|
5
4
|
import { ThemeProvider, Global, styled } from 'newskit'
|
|
6
|
-
import { SessionProvider } from '@newskit-render/auth'
|
|
7
5
|
import {
|
|
8
6
|
getFeatureFlags,
|
|
9
7
|
FeatureFlagsContextProvider,
|
|
@@ -59,18 +57,16 @@ function MyApp({ Component, pageProps, featureFlags, tenant }: MyAppProps) {
|
|
|
59
57
|
</Head>
|
|
60
58
|
<InstrumentationContextProvider>
|
|
61
59
|
<FeatureFlagsContextProvider context={featureFlags}>
|
|
62
|
-
<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
</AppContext.Consumer>
|
|
73
|
-
</SessionProvider>
|
|
60
|
+
<AppContext.Consumer>
|
|
61
|
+
{({ theme }) => (
|
|
62
|
+
<ThemeProvider theme={theme}>
|
|
63
|
+
<Global styles={GlobalStyling} />
|
|
64
|
+
<PageContainer>
|
|
65
|
+
<Component {...pageProps} />
|
|
66
|
+
</PageContainer>
|
|
67
|
+
</ThemeProvider>
|
|
68
|
+
)}
|
|
69
|
+
</AppContext.Consumer>
|
|
74
70
|
</FeatureFlagsContextProvider>
|
|
75
71
|
</InstrumentationContextProvider>
|
|
76
72
|
</>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
+
import useSWR from 'swr'
|
|
2
3
|
import {
|
|
3
4
|
Block,
|
|
4
5
|
IndeterminateProgressIndicator,
|
|
@@ -8,26 +9,31 @@ import {
|
|
|
8
9
|
toNewsKitIcon,
|
|
9
10
|
} from 'newskit'
|
|
10
11
|
import {
|
|
12
|
+
SessionProvider,
|
|
11
13
|
PageWithAuth,
|
|
12
14
|
getSession,
|
|
13
15
|
signIn,
|
|
14
16
|
signOut,
|
|
15
17
|
CookieView,
|
|
16
18
|
} from '@newskit-render/auth'
|
|
17
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
createApolloClient,
|
|
21
|
+
ClientTypes,
|
|
22
|
+
getAcsCookie,
|
|
23
|
+
} from '@newskit-render/api'
|
|
24
|
+
import { Article } from '@newskit-render/standalone-components'
|
|
18
25
|
import { getHost } from '@newskit-render/shared-components'
|
|
19
26
|
import { Info } from '@emotion-icons/material/Info'
|
|
20
27
|
import { GET_UNIVERSAL_ARTICLE } from '../../../../../queries'
|
|
21
28
|
import ArticlePage from '../../../../../components/article'
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
relatedArticles,
|
|
25
|
-
} from '../../../../../helpers/mocks/articleMock'
|
|
29
|
+
import { fetchUser } from '../../../../../helpers/getUser'
|
|
30
|
+
import { getAccountQueryUrl } from '../../../../../constants'
|
|
26
31
|
import { addCacheHeaders } from '../../../../../helpers/addCacheHeaders'
|
|
27
32
|
import {
|
|
28
33
|
twitterUsername as configTwitterUsername,
|
|
29
34
|
gscId as configGscId,
|
|
30
35
|
} from '../../../../../config'
|
|
36
|
+
import { fetcher } from '../../../../../helpers/getRecommendations'
|
|
31
37
|
|
|
32
38
|
const IconFilledInfo = toNewsKitIcon(Info)
|
|
33
39
|
|
|
@@ -38,7 +44,26 @@ const PreviewArticle = ({
|
|
|
38
44
|
twitterUsername,
|
|
39
45
|
siteHost,
|
|
40
46
|
gscId,
|
|
47
|
+
user,
|
|
48
|
+
articleId,
|
|
49
|
+
...props
|
|
41
50
|
}) => {
|
|
51
|
+
let userId
|
|
52
|
+
if (typeof window !== 'undefined') {
|
|
53
|
+
userId = window?.utag?.data['cp.utag_main_v_id']
|
|
54
|
+
}
|
|
55
|
+
const highlitedArticles = []
|
|
56
|
+
const relatedArticles = []
|
|
57
|
+
const { data: recommendations } = useSWR<Article[]>(
|
|
58
|
+
`/api/recommendations/${articleId}/${userId}`,
|
|
59
|
+
fetcher
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
if (Array.isArray(recommendations)) {
|
|
63
|
+
highlitedArticles.push(...recommendations.slice(0, 4))
|
|
64
|
+
relatedArticles.push(...recommendations.slice(4, 12))
|
|
65
|
+
}
|
|
66
|
+
|
|
42
67
|
const accessDeniedPage = (
|
|
43
68
|
<Banner
|
|
44
69
|
overrides={{ stylePreset: 'bannerNotice' }}
|
|
@@ -68,31 +93,38 @@ const PreviewArticle = ({
|
|
|
68
93
|
)
|
|
69
94
|
|
|
70
95
|
return (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
+
<SessionProvider pageProps={(props as unknown) as any}>
|
|
98
|
+
<PageWithAuth onDenied={accessDeniedPage} isLoading={showOnLoading}>
|
|
99
|
+
<>
|
|
100
|
+
<CookieView>
|
|
101
|
+
<Button size="medium" onClick={() => signOut()}>
|
|
102
|
+
sign out
|
|
103
|
+
</Button>
|
|
104
|
+
</CookieView>
|
|
105
|
+
<ArticlePage
|
|
106
|
+
section={section}
|
|
107
|
+
articleURL={articleURL}
|
|
108
|
+
{...universalArticle}
|
|
109
|
+
siteHost={siteHost}
|
|
110
|
+
gscId={gscId}
|
|
111
|
+
twitterUsername={twitterUsername}
|
|
112
|
+
highlights={highlitedArticles}
|
|
113
|
+
relatedArticles={relatedArticles}
|
|
114
|
+
user={user}
|
|
115
|
+
/>
|
|
116
|
+
</>
|
|
117
|
+
</PageWithAuth>
|
|
118
|
+
</SessionProvider>
|
|
90
119
|
)
|
|
91
120
|
}
|
|
92
121
|
|
|
93
122
|
export async function getServerSideProps(context) {
|
|
94
123
|
const apolloClient = await createApolloClient(ClientTypes.nkapi)
|
|
95
124
|
const session = await getSession(context)
|
|
125
|
+
const acsCookie = context.req.headers.cookie
|
|
126
|
+
? getAcsCookie(ClientTypes.main, context.req.headers.cookie)
|
|
127
|
+
: ''
|
|
96
128
|
const siteHost = getHost(context.req)
|
|
97
129
|
if (!session) {
|
|
98
130
|
return {
|
|
@@ -103,10 +135,17 @@ export async function getServerSideProps(context) {
|
|
|
103
135
|
params: { articleId, versionId },
|
|
104
136
|
} = context
|
|
105
137
|
|
|
106
|
-
const { data } = await
|
|
107
|
-
query
|
|
108
|
-
|
|
109
|
-
|
|
138
|
+
const [{ data }, user] = await Promise.all([
|
|
139
|
+
apolloClient.query({
|
|
140
|
+
query: GET_UNIVERSAL_ARTICLE,
|
|
141
|
+
variables: {
|
|
142
|
+
publisher: 'DEMO',
|
|
143
|
+
id: articleId,
|
|
144
|
+
version: versionId,
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
await fetchUser(acsCookie, getAccountQueryUrl(siteHost)),
|
|
148
|
+
])
|
|
110
149
|
|
|
111
150
|
addCacheHeaders(context.res)
|
|
112
151
|
return {
|
|
@@ -117,6 +156,9 @@ export async function getServerSideProps(context) {
|
|
|
117
156
|
twitterUsername: configTwitterUsername || '',
|
|
118
157
|
siteHost,
|
|
119
158
|
gscId: configGscId || '',
|
|
159
|
+
showAds: true,
|
|
160
|
+
user,
|
|
161
|
+
articleId,
|
|
120
162
|
},
|
|
121
163
|
}
|
|
122
164
|
}
|