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

Commit e242741

Browse files
committed
Add listing by developers
1 parent 4518dfa commit e242741

File tree

6 files changed

+2211
-1410
lines changed

6 files changed

+2211
-1410
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { GetStaticPaths, GetStaticProps } from 'next'
2+
3+
import { fetchDeveloperApps, fetchDevelopers } from '../../../../src/fetchers'
4+
import ApplicationCollection from '../../../../src/components/application/Collection'
5+
import { Appstream } from '../../../../src/types/Appstream'
6+
import { NextSeo } from 'next-seo'
7+
8+
export default function Developer({
9+
developerApps,
10+
developer,
11+
}: {
12+
developerApps: Appstream[]
13+
developer: string
14+
}) {
15+
return (
16+
<>
17+
<NextSeo title={`Applications by ${developer}`} />
18+
<ApplicationCollection
19+
title={`Applications by ${developer}`}
20+
applications={developerApps}
21+
/>
22+
</>
23+
)
24+
}
25+
26+
export const getStaticProps: GetStaticProps = async ({
27+
params: { developer },
28+
}) => {
29+
const developerApps = await fetchDeveloperApps(developer as string)
30+
return {
31+
props: {
32+
developerApps: developerApps ?? [],
33+
developer
34+
},
35+
}
36+
}
37+
38+
export const getStaticPaths: GetStaticPaths = async () => {
39+
const apps = await fetchDevelopers()
40+
const paths = apps.map((developer) => ({
41+
params: { developer },
42+
}))
43+
44+
return {
45+
paths,
46+
fallback: false,
47+
}
48+
}

pages/apps/details/[appDetails].tsx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
fetchAppstream,
77
fetchAppStats,
88
fetchSummary,
9+
fetchDeveloperApps,
910
} from '../../../src/fetchers'
1011
import { APPSTREAM_URL } from '../../../src/env'
1112
import { NextSeo } from 'next-seo'
@@ -16,20 +17,20 @@ import {
1617
} from '../../../src/types/Appstream'
1718
import { Summary } from '../../../src/types/Summary'
1819
import { AppStats } from '../../../src/types/AppStats'
19-
import { useEffect, useState } from 'react'
2020
import { StringParam, useQueryParam, withDefault } from 'next-query-params'
21+
import { BranchedType } from '../../../src/types/BranchedType'
2122

2223
export default function Details({
23-
data,
24+
app,
2425
summary,
2526
stats,
27+
developerApps,
2628
}: {
27-
data: Appstream
28-
summary: Summary
29+
app: BranchedType<Appstream>
30+
summary: BranchedType<Summary>
2931
stats: AppStats
32+
developerApps: Appstream[]
3033
}) {
31-
const [branchParam, setBranchParam] = useQueryParam('branch', withDefault(StringParam, undefined));
32-
3334
function branchChange(event) {
3435
if (event.value === "stable") {
3536
setBranchParam(undefined)
@@ -44,39 +45,48 @@ export default function Details({
4445
"stable"
4546
}
4647

48+
const [branchParam, setBranchParam] = useQueryParam('branch', withDefault(StringParam, undefined));
49+
4750
const options: { value: string, label: string }[] = []
48-
if (data["stable"] && summary["stable"] && data["beta"] && summary["beta"]) {
51+
if (app["stable"] && summary["stable"] && app["beta"] && summary["beta"]) {
4952
options.push({ value: 'stable', label: 'Stable' },)
5053
options.push({ value: 'beta', label: 'Beta' },)
5154
}
52-
else if (data["stable"] && summary["stable"]) {
55+
else if (app["stable"] && summary["stable"]) {
5356
options.push({ value: 'stable', label: 'Stable' },)
5457
}
55-
else if (data["beta"] && summary["beta"]) {
58+
else if (app["beta"] && summary["beta"]) {
5659
options.push({ value: 'beta', label: 'Beta' },)
5760
}
5861

59-
const screenshots = data.screenshots
60-
? data.screenshots.filter(pickScreenshot).map((screenshot: Screenshot) => ({
62+
const screenshots = app[getBranch(branchParam)]?.screenshots
63+
? app[getBranch(branchParam)].screenshots.filter(pickScreenshot).map((screenshot: Screenshot) => ({
6164
url: pickScreenshot(screenshot).url,
6265
}))
6366
: []
6467

6568
return (
6669
<Main>
6770
<NextSeo
68-
title={data.name}
69-
description={data.summary}
71+
title={app[getBranch(branchParam)]?.name}
72+
description={app[getBranch(branchParam)]?.summary}
7073
openGraph={{
7174
images: [
7275
{
73-
url: data.icon,
76+
url: app[getBranch(branchParam)]?.icon,
7477
},
7578
...screenshots,
7679
],
7780
}}
7881
/>
79-
<ApplicationDetails data={data[getBranch(branchParam)]} summary={summary[getBranch(branchParam)]} stats={stats} branch={getBranch(branchParam)} setBranch={branchChange} options={options} />
82+
<ApplicationDetails
83+
app={app[getBranch(branchParam)]}
84+
summary={summary[getBranch(branchParam)]}
85+
stats={stats}
86+
developerApps={developerApps.filter(devApp => devApp.id !== app[getBranch(branchParam)].id)}
87+
branch={getBranch(branchParam)}
88+
setBranch={branchChange}
89+
options={options} />
8090
</Main >
8191
)
8292
}
@@ -85,15 +95,17 @@ export const getStaticProps: GetStaticProps = async ({
8595
params: { appDetails: appId },
8696
}) => {
8797
console.log('Fetching data for app details: ', appId)
88-
const data = await fetchAppstream(appId as string)
98+
const app = await fetchAppstream(appId as string)
8999
const summary = await fetchSummary(appId as string)
90100
const stats = await fetchAppStats(appId as string)
101+
const developerApps = await (await fetchDeveloperApps(app["stable"]?.developer_name))
91102

92103
return {
93104
props: {
94-
data,
105+
app,
95106
summary,
96107
stats,
108+
developerApps: developerApps ?? [],
97109
},
98110
}
99111
}

0 commit comments

Comments
 (0)