Skip to content

Commit d409eb1

Browse files
committed
Refactor news
1 parent 69d5359 commit d409eb1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

web/pages/news.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {CustomLink} from "web/components/links";
88
import {isNativeMobile} from "web/lib/util/webview";
99
import {useEffect, useState} from "react";
1010
import {CompassLoadingIndicator} from "web/components/widgets/loading-indicator";
11+
import {getPageData} from "web/lib/util/page-data";
1112

1213
async function fetchReleases() {
1314
const releases = await fetch(`https://api.github.com/repos/${githubRepoSlug}/releases`)
@@ -43,24 +44,31 @@ type Release = {
4344

4445
export default function WhatsNew(props: { releases?: Release[] }) {
4546
const nativeMobile = isNativeMobile()
46-
const [releases, setReleases] = useState(props.releases || [])
47+
const [fetchedProps, setFetchedProps] = useState(props)
4748
const [loading, setLoading] = useState(nativeMobile)
49+
const releases = fetchedProps.releases || []
4850

4951
useEffect(() => {
5052
if (nativeMobile) {
51-
// Mobile/WebView scenario: fetch profile dynamically
53+
// Mobile/WebView scenario: fetch data dynamically from the remote web server (to benefit from SSR and ISR)
5254
async function load() {
5355
setLoading(true)
54-
const fetchedReleases = await fetchReleases()
55-
setReleases(fetchedReleases)
56-
console.debug('fetched releases for native mobile')
56+
try {
57+
const _props = await getPageData('news')
58+
setFetchedProps(_props)
59+
} catch (e) {
60+
console.error('Failed to fetch data for native mobile', e)
61+
setFetchedProps({releases: []})
62+
}
5763
setLoading(false)
5864
}
5965

6066
load()
67+
} else {
68+
setFetchedProps(props)
6169
}
62-
// On web, initialProfile from SSR/ISR is already loaded
63-
}, [nativeMobile]);
70+
// On web, props from SSR/ISR is already loaded
71+
}, [nativeMobile])
6472

6573
return (
6674
<PageBase trackPageView={'news'} className={'mx-4'}>

0 commit comments

Comments
 (0)