@@ -10,7 +10,7 @@ const spaceFields = `
1010 type
1111 page {
1212 name
13- relationsList(filter: {
13+ avatarRelations: relationsList(filter: {
1414 typeId: { is: "${ ContentIds . AVATAR_PROPERTY } "}
1515 }) {
1616 toEntity {
@@ -22,6 +22,18 @@ const spaceFields = `
2222 }
2323 }
2424 }
25+ coverRelations: relationsList(filter: {
26+ typeId: { is: "${ SystemIds . COVER_PROPERTY } "}
27+ }) {
28+ toEntity {
29+ valuesList(filter: {
30+ propertyId: { is: "${ SystemIds . IMAGE_URL_PROPERTY } "}
31+ }) {
32+ propertyId
33+ text
34+ }
35+ }
36+ }
2537 }
2638 editorsList {
2739 memberSpaceId
@@ -40,26 +52,30 @@ export const PublicSpaceSchema = EffectSchema.Struct({
4052 type : SpaceTypeSchema ,
4153 name : EffectSchema . String ,
4254 avatar : EffectSchema . optional ( EffectSchema . String ) ,
55+ cover : EffectSchema . optional ( EffectSchema . String ) ,
4356 editorIds : EffectSchema . Array ( EffectSchema . String ) ,
4457 memberIds : EffectSchema . Array ( EffectSchema . String ) ,
4558} ) ;
4659
4760export type PublicSpace = typeof PublicSpaceSchema . Type ;
4861
62+ type RelationEntry = {
63+ toEntity ?: {
64+ valuesList ?: {
65+ propertyId : string ;
66+ text : string | null ;
67+ } [ ] ;
68+ } | null ;
69+ } ;
70+
4971type SpacesQueryResult = {
5072 spaces ?: {
5173 id : string ;
5274 type : 'PERSONAL' | 'DAO' ;
5375 page : {
5476 name ?: string | null ;
55- relationsList ?: {
56- toEntity ?: {
57- valuesList ?: {
58- propertyId : string ;
59- text : string | null ;
60- } [ ] ;
61- } | null ;
62- } [ ] ;
77+ avatarRelations ?: RelationEntry [ ] ;
78+ coverRelations ?: RelationEntry [ ] ;
6379 } | null ;
6480 editorsList ?: {
6581 memberSpaceId : string ;
@@ -74,16 +90,24 @@ type SpaceQueryEntry = NonNullable<SpacesQueryResult['spaces']>[number];
7490
7591const decodeSpace = EffectSchema . decodeUnknownEither ( PublicSpaceSchema ) ;
7692
77- const getAvatarFromSpace = ( space : SpaceQueryEntry ) => {
78- const firstRelation = space . page ?. relationsList ?. [ 0 ] ;
93+ const getImageFromRelations = ( relations ?: RelationEntry [ ] ) => {
94+ const firstRelation = relations ?. [ 0 ] ;
7995 const firstValue = firstRelation ?. toEntity ?. valuesList ?. [ 0 ] ;
80- const avatar = firstValue ?. text ;
81- if ( typeof avatar === 'string' ) {
82- return avatar ;
96+ const url = firstValue ?. text ;
97+ if ( typeof url === 'string' ) {
98+ return url ;
8399 }
84100 return undefined ;
85101} ;
86102
103+ const getAvatarFromSpace = ( space : SpaceQueryEntry ) => {
104+ return getImageFromRelations ( space . page ?. avatarRelations ) ;
105+ } ;
106+
107+ const getCoverFromSpace = ( space : SpaceQueryEntry ) => {
108+ return getImageFromRelations ( space . page ?. coverRelations ) ;
109+ } ;
110+
87111const getEditorIdsFromSpace = ( space : SpaceQueryEntry ) : string [ ] => {
88112 return ( space . editorsList ?? [ ] ) . map ( ( e ) => e . memberSpaceId ) . filter ( ( id ) : id is string => typeof id === 'string' ) ;
89113} ;
@@ -103,6 +127,7 @@ export const parseSpacesQueryResult = (queryResult: SpacesQueryResult) => {
103127 type : space . type ,
104128 name : space . page ?. name ?? undefined ,
105129 avatar : getAvatarFromSpace ( space ) ,
130+ cover : getCoverFromSpace ( space ) ,
106131 editorIds : getEditorIdsFromSpace ( space ) ,
107132 memberIds : getMemberIdsFromSpace ( space ) ,
108133 } ;
0 commit comments