Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/pages/ProjectList.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,21 @@ class ProjectList extends Component {
let projectsLFH = [];
let projectIdeas = [];
let otherProjects = [];
let myProjects = [];
projects.forEach((p) => {
if (Object.keys(p.members || {}).includes(auth.uid)) myProjects.push(p);
if (p.isIdea) projectIdeas.push(p);
else if (p.needHelp) projectsLFH.push(p);
else otherProjects.push(p);

});

const showParam = this.props.location.query.show;
const showIdeas = !showParam || showParam === 'ideas';
const showProjects = showParam === 'projects';
const showMyProjects = showParam === 'my-projects';
const hasAnyProjects = projectsLFH.length > 0 || otherProjects.length > 0;
const hasAnyMyProjects = myProjects.length > 0;
const hasAnyIdeas = projectIdeas.length > 0;

let userVotes = year ? getAuthUserVotes(auth.uid, year.votes) : [];
Expand All @@ -402,6 +407,13 @@ class ProjectList extends Component {
</div>
);
}
if (showMyProjects && !hasAnyMyProjects) {
emptyState = (
<div className="alert alert-block alert-info">
Oops! You don't have any projects yet! Create, claim or join a project!
</div>
);
}

return (
<div className="Project-list-container">
Expand Down Expand Up @@ -450,6 +462,28 @@ class ProjectList extends Component {
</ul>
</div>
)}
{showMyProjects && myProjects.length > 0 && (
<div className="Project-list-section">
<ul className="Project-List Project">
{myProjects.map((project) => (
<ProjectListItem
key={project.key}
auth={auth}
userVote={userVotes.filter((v) => v.project === project.key)}
firebase={firebase}
project={project}
awardCategoryOptions={awardCategoryOptions}
awardList={awardList}
userList={userList}
group={{id: project.group, ...groupsList[project.group]}}
submissionsClosed={submissionsClosed}
Comment on lines +478 to +479

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential bug: Spreading `groupsList[project.group]` can cause a TypeError if a project has no group, as `...undefined` is not allowed. This will crash the component.
  • Description: When rendering the project list, if a project's group property is undefined, null, or an empty string, the expression groupsList[project.group] will evaluate to undefined. The code then attempts to spread this undefined value inside an object literal ({...groupsList[project.group]}). This operation throws a TypeError: undefined is not iterable, which will cause the React component to crash and prevent the project list from rendering for the user. Evidence from NewProject.js and EditProject.js confirms that projects can exist without an assigned group.
  • Suggested fix: Provide a fallback empty object to prevent the spread operator from receiving undefined. Change ...groupsList[project.group] to ...(groupsList[project.group] || {}). This ensures that if the lookup fails, an empty object is spread, which is a safe no-op.
    severity: 0.7, confidence: 0.95

Did we get this right? 👍 / 👎 to inform future reviews.

isOlderYear={isOlderYear}
/>
))}
</ul>
</div>
)}

<div className="Project-list-tabs">
<ul className="tabs">
<li style={{fontWeight: showIdeas ? 'bold' : null}}>
Expand Down Expand Up @@ -496,6 +530,27 @@ class ProjectList extends Component {
</span>
</Link>
</li>
<li style={{fontWeight: showMyProjects ? 'bold' : null}}>
<Link
to={{
pathname: this.props.location.pathname,
query: {
show: 'my-projects',
},
}}
>
My Projects{' '}
<span
className={
showMyProjects
? 'Project-list-count-active'
: 'Project-list-count-inactive'
}
>
{myProjects.length === 0 ? '0' : myProjects.length}
</span>
</Link>
</li>
</ul>
</div>
</div>
Expand Down