Skip to content

Commit

Permalink
Merge pull request #395 from NDLANO/return-isMain
Browse files Browse the repository at this point in the history
Using mainPid from topic to return isMainPost if not present
  • Loading branch information
gunnarvelle authored Nov 22, 2023
2 parents 69910dd + 6d390bc commit f92f3a1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/api/arenaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ const toUser = (user: any): GQLArenaUser => ({
groupTitleArray: user.groupTitleArray,
});

const toArenaPost = (post: any): GQLArenaPost => ({
const toArenaPost = (post: any, mainPid?: any): GQLArenaPost => ({
id: post.pid,
topicId: post.tid,
content: post.content,
timestamp: post.timestampISO,
isMainPost: post.isMainPost,
isMainPost: post.isMainPost ?? post.pid === mainPid,
user: toUser(post.user),
});

Expand All @@ -51,7 +51,11 @@ const toTopic = (topic: any): GQLArenaTopic => {
postCount: topic.postcount,
timestamp: topic.timestampISO,
locked: topic.locked === 1,
posts: topic.posts ? topic.posts.map(toArenaPost) : [],
posts: topic.posts
? topic.posts.map((post: any) => toArenaPost(post, topic.mainPid))
: topic.mainPost
? [toArenaPost(topic.mainPost, topic.mainPid)]
: [],
breadcrumbs: crumbs,
};
};
Expand Down Expand Up @@ -190,5 +194,5 @@ export const replyToTopic = async (
}),
});
const resolved = await resolveJson(response);
return toArenaPost(resolved.response);
return toArenaPost(resolved.response, undefined);
};

0 comments on commit f92f3a1

Please sign in to comment.