Skip to content

Commit

Permalink
filter out private or deleted projects
Browse files Browse the repository at this point in the history
  • Loading branch information
goplayoutside3 committed Oct 21, 2024
1 parent 74ec2fa commit ccf090c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { ContentBox } from '@components/shared'

export default function RecentProjects({
isLoading = false,
recentProjectsStats = [],
recentProjects = [],
error = undefined
}) {
const size = useContext(ResponsiveContext)

return (
<ContentBox title='Continue Classifying' screenSize={size}>
{isLoading ? (
Expand All @@ -23,7 +24,7 @@ export default function RecentProjects({
There was an error fetching your recent projects
</SpacedText>
</Box>
) : !recentProjectsStats.length ? (
) : !recentProjects.length ? (
<Box fill justify='center' align='center' pad='medium'>
<SpacedText>No Recent Projects found</SpacedText>
<Text>
Expand All @@ -44,14 +45,14 @@ export default function RecentProjects({
style={{ listStyle: 'none' }}
margin='0'
>
{recentProjectsStats.map(stat => (
<li key={stat.project_id}>
{recentProjects.map(project => (
<li key={project.id}>
<ProjectCard
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}
badge={project.count}
description={project?.description}
displayName={project?.display_name}
href={`https://www.zooniverse.org/projects/${project?.slug}`}
imageSrc={project?.avatar_src}
size={size}
/>
</li>
Expand All @@ -64,17 +65,14 @@ export default function RecentProjects({

RecentProjects.propTypes = {
isLoading: bool,
recentProjectsStats: arrayOf(
recentProjects: arrayOf(
shape({
avatar_src: string,
count: number,
project_id: number,
projectInfo: shape({
avatar_src: string,
description: string,
display_name: string,
id: string,
slug: string
})
description: string,
display_name: string,
id: string,
slug: string
})
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function RecentProjectsContainer({ authUser }) {
} = useStats({ sourceId: authUser?.id, query: recentProjectsQuery })

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

// Get more info about each project
const {
Expand All @@ -29,21 +29,28 @@ function RecentProjectsContainer({ authUser }) {
id: projectIds?.join(',')
})

// 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
)
stat.projectInfo = projectObj
})
// Attach project info to each contribution stat (see similar behavior in TopProjects)
let recentProjects = []

if (projects?.length && contributions?.length) {
recentProjects = contributions
.map(projectContribution => {
const projectData = projects?.find(
project => project.id === projectContribution.project_id.toString()
)
return {
count: projectContribution.count,
...projectData
}
})
.filter(project => project?.id) // exclude private or deleted projects
}

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

0 comments on commit ccf090c

Please sign in to comment.