Merge pull request #1345 from hackclub/check-if-in-the-running

Add indicator of if project is in the running
This commit is contained in:
Max Wofford 2024-08-29 21:45:46 +00:00 committed by GitHub
commit bc89a733f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 21 deletions

View file

@ -14,7 +14,8 @@ const CohortCard = ({
imageLink = '',
personal = false,
color = '#09AFB4',
textColor = '#000000'
textColor = '#000000',
inRunning = null
}) => {
const [isHovered, setIsHovered] = useState(false)
const [isDeleted, setIsDeleted] = useState(false)
@ -61,7 +62,8 @@ const CohortCard = ({
<>
<div
sx={{
backgroundColor: color
backgroundColor: color,
filter: (inRunning === null || inRunning) ? 'grayscale(0%)' : 'grayscale(50%) contrast(0.5)',
}}
className={styles.card}
onMouseEnter={() => setIsHovered(true)}

View file

@ -14,7 +14,10 @@ export default async function handler(req, res) {
})
const projects = await airtable.read({
filterByFormula: `AND({User} = '${user.fields['Name']}', NOT({deleted}))`
filterByFormula: `AND(
{User} = '${user.fields['Name']}',
NOT({deleted})
)`
})
const results = projects.map(p => ({

View file

@ -42,18 +42,27 @@ export default async function handler(req, res) {
return res.status(401).json(user)
}
const results = projects.map(p => ({
id: p.id,
title: p.fields['Name'] || '',
desc: p.fields['Description'] || '',
slackLink: p.fields['Slack Link'] || '',
codeLink: p.fields['Code Link'] || '',
slackLink: p.fields['Slack Link'] || '',
playLink: p.fields['Play Link'] || '',
imageLink: p.fields['ScreenshotLink'] || '',
user: user.fields['Name'],
color: p.fields['color'] || '',
textColor: p.fields['textColor'] || ''
}))
const hasVoted = user.fields['Voted']
const results = projects.map(p => {
const result = {
id: p.id,
title: p.fields['Name'] || '',
desc: p.fields['Description'] || '',
slackLink: p.fields['Slack Link'] || '',
codeLink: p.fields['Code Link'] || '',
slackLink: p.fields['Slack Link'] || '',
playLink: p.fields['Play Link'] || '',
imageLink: p.fields['ScreenshotLink'] || '',
user: user.fields['Name'],
color: p.fields['color'] || '',
textColor: p.fields['textColor'] || '',
}
if (hasVoted) {
result.inRunning = !(Boolean(p.fields['Lost Cohorts']))
}
return result
})
return res.status(200).json({ projects: results, name: user.fields['Name'] })
}

View file

@ -54,21 +54,21 @@ export default async function handler(req, res) {
const project = overall[i]
const points = pointsDistribution[i]
votesToCreate.push(addVote(project, points, user.id, 'Overall'))
votesToCreate.push(addVote(project, points, user.id, user.fields?.['Cohorts']?.[0], 'Overall'))
}
for (let i = 0; i < technical.length; i++) {
const project = technical[i]
const points = pointsDistribution[i]
votesToCreate.push(addVote(project, points, user.id, 'Technical'))
votesToCreate.push(addVote(project, points, user.id, user.fields?.['Cohorts']?.[0], 'Technical'))
}
for (let i = 0; i < creative.length; i++) {
const project = creative[i]
const points = pointsDistribution[i]
votesToCreate.push(addVote(project, points, user.id, 'Creative'))
votesToCreate.push(addVote(project, points, user.id, user.fields?.['Cohorts']?.[0], 'Creative'))
}
await Promise.all([
@ -85,13 +85,14 @@ export default async function handler(req, res) {
}
}
const addVote = (projectId, points, userID, type) => {
const addVote = (projectId, points, userID, type, cohortID) => {
return {
fields: {
Points: parseInt(points, 10),
Voter: [userID],
Showcase: [projectId],
Type: type
Cohort: [cohortID],
Type: type,
}
}
}

View file

@ -108,6 +108,7 @@ const ProjectGallery = ({ projects, loadProjects, submissionClose }) => {
reload={loadProjects}
color={project.color}
textColor={project.textColor}
inRunning={project.inRunning}
/>
))}
</div>