Skip to content
This repository was archived by the owner on Apr 25, 2022. It is now read-only.

Commit 2017019

Browse files
committed
Add listing by developers
1 parent 616aab5 commit 2017019

File tree

5 files changed

+2127
-1396
lines changed

5 files changed

+2127
-1396
lines changed

pages/apps/details/[appDetails].tsx

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,20 @@ import {
1717
} from '../../../src/types/Appstream'
1818
import { Summary } from '../../../src/types/Summary'
1919
import { AppStats } from '../../../src/types/AppStats'
20-
import { useEffect, useState } from 'react'
2120
import { StringParam, useQueryParam, withDefault } from 'next-query-params'
21+
import { BranchedType } from '../../../src/types/BranchedType'
2222

2323
export default function Details({
2424
app,
2525
summary,
2626
stats,
2727
developerApps,
2828
}: {
29-
app: Appstream
30-
summary: Summary
29+
app: BranchedType<Appstream>
30+
summary: BranchedType<Summary>
3131
stats: AppStats
3232
developerApps: Appstream[]
3333
}) {
34-
const [branchParam, setBranchParam] = useQueryParam(
35-
'branch',
36-
withDefault(StringParam, undefined)
37-
)
38-
3934
function branchChange(event) {
4035
if (event.value === 'stable') {
4136
setBranchParam(undefined)
@@ -48,31 +43,35 @@ export default function Details({
4843
return branch === 'beta' ? 'beta' : 'stable'
4944
}
5045

51-
const options: { value: string; label: string }[] = []
52-
if (app['stable'] && summary['stable'] && app['beta'] && summary['beta']) {
53-
options.push({ value: 'stable', label: 'Stable' })
54-
options.push({ value: 'beta', label: 'Beta' })
55-
} else if (app['stable'] && summary['stable']) {
56-
options.push({ value: 'stable', label: 'Stable' })
57-
} else if (app['beta'] && summary['beta']) {
58-
options.push({ value: 'beta', label: 'Beta' })
46+
const [branchParam, setBranchParam] = useQueryParam('branch', withDefault(StringParam, undefined));
47+
48+
const options: { value: string, label: string }[] = []
49+
if (app["stable"] && summary["stable"] && app["beta"] && summary["beta"]) {
50+
options.push({ value: 'stable', label: 'Stable' },)
51+
options.push({ value: 'beta', label: 'Beta' },)
52+
}
53+
else if (app["stable"] && summary["stable"]) {
54+
options.push({ value: 'stable', label: 'Stable' },)
55+
}
56+
else if (app["beta"] && summary["beta"]) {
57+
options.push({ value: 'beta', label: 'Beta' },)
5958
}
6059

61-
const screenshots = app.screenshots
62-
? app.screenshots.filter(pickScreenshot).map((screenshot: Screenshot) => ({
63-
url: pickScreenshot(screenshot).url,
64-
}))
60+
const screenshots = app[getBranch(branchParam)]?.screenshots
61+
? app[getBranch(branchParam)].screenshots.filter(pickScreenshot).map((screenshot: Screenshot) => ({
62+
url: pickScreenshot(screenshot).url,
63+
}))
6564
: []
6665

6766
return (
6867
<Main>
6968
<NextSeo
70-
title={app?.name}
71-
description={app?.summary}
69+
title={app[getBranch(branchParam)]?.name}
70+
description={app[getBranch(branchParam)]?.summary}
7271
openGraph={{
7372
images: [
7473
{
75-
url: app?.icon,
74+
url: app[getBranch(branchParam)]?.icon,
7675
},
7776
...screenshots,
7877
],
@@ -82,12 +81,11 @@ export default function Details({
8281
app={app[getBranch(branchParam)]}
8382
summary={summary[getBranch(branchParam)]}
8483
stats={stats}
84+
developerApps={developerApps.filter(devApp => devApp.id !== app[getBranch(branchParam)].id)}
8585
branch={getBranch(branchParam)}
8686
setBranch={branchChange}
87-
options={options}
88-
developerApps={developerApps.filter((devApp) => devApp.id !== app.id)}
89-
/>
90-
</Main>
87+
options={options} />
88+
</Main >
9189
)
9290
}
9391

@@ -98,7 +96,7 @@ export const getStaticProps: GetStaticProps = async ({
9896
const app = await fetchAppstream(appId as string)
9997
const summary = await fetchSummary(appId as string)
10098
const stats = await fetchAppStats(appId as string)
101-
const developerApps = await fetchDeveloperApps(app?.developer_name)
99+
const developerApps = await (await fetchDeveloperApps(app["stable"]?.developer_name))
102100

103101
return {
104102
props: {

0 commit comments

Comments
 (0)