1
1
import DirectusImage from "@/components/DirectusImage" ;
2
+ import SocialsList from "@/components/SocialsList" ;
2
3
import { directus , populateLayoutProps } from "@/directus" ;
3
4
import { getTranslation , locale , queryTranslations } from "@/locales" ;
4
- import { Commission } from "@/types/aliases" ;
5
+ import { Commission , SocialLink } from "@/types/aliases" ;
5
6
import { readItems } from "@directus/sdk" ;
6
7
import { GetServerSideProps , InferGetServerSidePropsType } from "next" ;
7
8
import { useRouter } from "next/router" ;
@@ -21,29 +22,48 @@ export default function Page(
21
22
< h4 > { translation . small_description } </ h4 >
22
23
23
24
< Markdown className = "text" > { translation . description } </ Markdown >
25
+
26
+ < SocialsList socials = { props . socialLinks } />
24
27
</ div >
25
28
</ div >
26
29
) ;
27
30
}
28
31
29
32
export const getServerSideProps : GetServerSideProps < {
30
33
commission : Commission ;
34
+ socialLinks : SocialLink [ ] ;
31
35
} > = populateLayoutProps ( async ( context ) => {
32
36
if ( typeof context . params ?. slug !== "string" ) {
33
37
console . log ( typeof context . params ?. slug ) ;
34
38
return { notFound : true } ;
35
39
}
36
40
37
- let commission = await directus ( ) . request (
41
+ let commissions = await directus ( ) . request (
38
42
readItems ( "commissions" , {
39
43
filter : { slug : { _eq : context . params . slug } } ,
40
44
...queryTranslations ,
41
45
} )
42
46
) ;
43
47
44
- if ( commission . length != 1 ) {
48
+ if ( commissions . length != 1 ) {
45
49
return { notFound : true } ;
46
50
}
47
51
48
- return { props : { commission : commission [ 0 ] } } ;
52
+ let commission = commissions [ 0 ] ;
53
+
54
+ let socialLinks = ( await directus ( )
55
+ . request (
56
+ readItems ( "commissions_social_links" , {
57
+ fields : [ { social_links_id : [ "*" ] } ] ,
58
+ filter : { commissions_id : { _eq : commission . id } } ,
59
+ } )
60
+ )
61
+ . then ( ( result ) => result . map ( ( s ) => s . social_links_id ) ) ) as SocialLink [ ] ;
62
+
63
+ return {
64
+ props : {
65
+ commission : commission ,
66
+ socialLinks : socialLinks ,
67
+ } ,
68
+ } ;
49
69
} ) ;
0 commit comments