Skip to content

Commit

Permalink
correct the ordering in RecentProjectsContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
goplayoutside3 committed Oct 21, 2024
1 parent 9571912 commit 74ec2fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Anchor, Box, ResponsiveContext, Text } from 'grommet'
import { arrayOf, bool, shape, string } from 'prop-types'
import { arrayOf, bool, number, shape, string } from 'prop-types'
import { useContext } from 'react'
import { Loader, ProjectCard, SpacedText } from '@zooniverse/react-components'

Expand Down Expand Up @@ -44,14 +44,14 @@ export default function RecentProjects({
style={{ listStyle: 'none' }}
margin='0'
>
{recentProjectsStats.map(project => (
<li key={project?.id}>
{recentProjectsStats.map(stat => (
<li key={stat.project_id}>
<ProjectCard
badge={project?.userContributions}
description={project?.description}
displayName={project?.display_name}
href={`https://www.zooniverse.org/projects/${project?.slug}`}
imageSrc={project?.avatar_src}
badge={stat.count}
description={stat.projectInfo?.description}
displayName={stat.projectInfo?.display_name}
href={`https://www.zooniverse.org/projects/${stat.projectInfo?.slug}`}
imageSrc={stat.projectInfo?.avatar_src}
size={size}
/>
</li>
Expand All @@ -66,7 +66,15 @@ RecentProjects.propTypes = {
isLoading: bool,
recentProjectsStats: arrayOf(
shape({
id: string
count: number,
project_id: number,
projectInfo: shape({
avatar_src: string,
description: string,
display_name: string,
id: string,
slug: string
})
})
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,35 @@ function RecentProjectsContainer({ authUser }) {
error: statsError
} = useStats({ sourceId: authUser?.id, query: recentProjectsQuery })

// Get more info about each project
const projectIds = stats?.project_contributions?.map(
project => project.project_id
)
// limit to 20 projects fetched from panoptes
const contributionStats = stats?.project_contributions.slice(0, 20)
const projectIds = contributionStats?.map(project => project.project_id)

// Get more info about each project
const {
data: projects,
isLoading: projectsLoading,
error: projectsError
} = usePanoptesProjects({
cards: true,
id: projectIds?.join(','),
page_size: 20
id: projectIds?.join(',')
})

// Attach contributions to each project
if (projects?.length && stats.project_contributions.length) {
projects.forEach(project => {
const projectStat = stats.project_contributions.find(
stat => stat.project_id === parseInt(project.id)
// Attach project info to each contribution stat
if (projects?.length && contributionStats?.length) {
contributionStats.forEach(stat => {
const projectObj = projects.find(
project => parseInt(project.id) === stat.project_id
)
project.userContributions = projectStat.count
stat.projectInfo = projectObj
})
}

return (
<RecentProjects
error={statsError || projectsError}
isLoading={statsLoading || projectsLoading}
recentProjectsStats={projects}
recentProjectsStats={contributionStats}
/>
)
}
Expand Down

0 comments on commit 74ec2fa

Please sign in to comment.