66 fetchAppstream ,
77 fetchAppStats ,
88 fetchSummary ,
9+ fetchDeveloperApps ,
910} from '../../../src/fetchers'
1011import { APPSTREAM_URL } from '../../../src/env'
1112import { NextSeo } from 'next-seo'
@@ -16,20 +17,20 @@ import {
1617} from '../../../src/types/Appstream'
1718import { Summary } from '../../../src/types/Summary'
1819import { AppStats } from '../../../src/types/AppStats'
19- import { useEffect , useState } from 'react'
2020import { StringParam , useQueryParam , withDefault } from 'next-query-params'
21+ import { BranchedType } from '../../../src/types/BranchedType'
2122
2223export 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