From 1d94ca63c787e8f876a08b0d47e9cb0adec77efd Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Sat, 17 Aug 2024 11:01:54 -0400 Subject: [PATCH 1/3] Add random image generation --- components/arcade/showcase/cohort-card.js | 5 +++-- components/arcade/showcase/project-view.js | 6 +++++- components/arcade/showcase/random-not-found-img.js | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 components/arcade/showcase/random-not-found-img.js diff --git a/components/arcade/showcase/cohort-card.js b/components/arcade/showcase/cohort-card.js index 5d70c5e6..ee7d0468 100644 --- a/components/arcade/showcase/cohort-card.js +++ b/components/arcade/showcase/cohort-card.js @@ -4,6 +4,7 @@ import styles from './cohort-card.module.css' import { useState } from 'react' import { Button } from 'theme-ui' import Icon from '@hackclub/icons' +import randomNotFoundImg from './random-not-found-img' /** @jsxImportSource theme-ui */ const CohortCard = ({ @@ -56,7 +57,7 @@ const CohortCard = ({ reload() } - const firstImage = images[0] || 'https://picsum.photos/200' + const firstImage = images[0] || randomNotFoundImg(id) function red() { window.location.href = '/arcade/showcase/project/' + id + '/edit' @@ -124,7 +125,7 @@ const CohortCard = ({ rel="noopener noreferrer" > Project Image diff --git a/components/arcade/showcase/project-view.js b/components/arcade/showcase/project-view.js index 572f7e05..48ceb345 100644 --- a/components/arcade/showcase/project-view.js +++ b/components/arcade/showcase/project-view.js @@ -1,5 +1,7 @@ import styles from './project-view.module.css' import { Button } from 'theme-ui' +import randomNotFoundImg from './random-not-found-img' +import CohortCard from './cohort-card' /** @jsxImportSource theme-ui */ const ProjectView = ({ @@ -18,6 +20,8 @@ const ProjectView = ({ const codeHost = codeLink.includes('github') ? 'View on GitHub' : 'View project source' + + const imagesList = images.length > 0 ? images : [randomNotFoundImg(id)] return (
@@ -43,7 +47,7 @@ const ProjectView = ({ gridTemplateColumns: images > 1 ? ['1fr', '1fr 1fr', '1fr 1fr 1fr'] : '1fr' }} > - {images.map((image, index) => ( + {imagesList.map((image, index) => (
s.split('').reduce((a,b)=>{a=((a<<5)-a)+b.charCodeAt(0);return a&a},0) +const randomNotFoundImg = (key) => { + return notFoundImgs[hashCode(key) % notFoundImgs.length] +} + +export default randomNotFoundImg \ No newline at end of file From 3574e29d1a82fc4676126fa4bc0efbeed8008e32 Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Sat, 17 Aug 2024 11:06:56 -0400 Subject: [PATCH 2/3] Run formatter on random image generator --- .../arcade/showcase/random-not-found-img.js | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/components/arcade/showcase/random-not-found-img.js b/components/arcade/showcase/random-not-found-img.js index 302fa881..f49a6125 100644 --- a/components/arcade/showcase/random-not-found-img.js +++ b/components/arcade/showcase/random-not-found-img.js @@ -1,14 +1,19 @@ const notFoundImgs = [ - "https://cloud-6laa73jem-hack-club-bot.vercel.app/0not_found5.png", - "https://cloud-6laa73jem-hack-club-bot.vercel.app/1not_found4.png", - "https://cloud-6laa73jem-hack-club-bot.vercel.app/2not_found3.png", - "https://cloud-6laa73jem-hack-club-bot.vercel.app/3not_found2.png", - "https://cloud-6laa73jem-hack-club-bot.vercel.app/4not_found1.png", + 'https://cloud-6laa73jem-hack-club-bot.vercel.app/0not_found5.png', + 'https://cloud-6laa73jem-hack-club-bot.vercel.app/1not_found4.png', + 'https://cloud-6laa73jem-hack-club-bot.vercel.app/2not_found3.png', + 'https://cloud-6laa73jem-hack-club-bot.vercel.app/3not_found2.png', + 'https://cloud-6laa73jem-hack-club-bot.vercel.app/4not_found1.png' ] -const hashCode = s => s.split('').reduce((a,b)=>{a=((a<<5)-a)+b.charCodeAt(0);return a&a},0) -const randomNotFoundImg = (key) => { +const hashCode = (s='key') => + s.split('').reduce((a, b) => { + a = (a << 5) - a + b.charCodeAt(0) + return a & a + }, 0) + +const randomNotFoundImg = key => { return notFoundImgs[hashCode(key) % notFoundImgs.length] } -export default randomNotFoundImg \ No newline at end of file +export default randomNotFoundImg From b37e92926847d968cb663d5e1af6e76e88e8948d Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Sat, 17 Aug 2024 11:08:32 -0400 Subject: [PATCH 3/3] Remove unused lines --- pages/api/arcade/showcase/projects/[projectID]/edit.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pages/api/arcade/showcase/projects/[projectID]/edit.js b/pages/api/arcade/showcase/projects/[projectID]/edit.js index 3b0e898f..860d50fa 100644 --- a/pages/api/arcade/showcase/projects/[projectID]/edit.js +++ b/pages/api/arcade/showcase/projects/[projectID]/edit.js @@ -20,14 +20,6 @@ export default async function handler(req, res) { updatedFields['Play Link'] = body.playLink updatedFields['Screenshot'] = body.images - // allow list of fields to change - // const allowedFields = ['Name', 'Description', 'Slack Link', 'Code Link', 'Play Link', 'Screenshot', 'Github Profile'] - // Object.keys(body).forEach(key => { - // if (!allowedFields.includes(key)) { - // delete body[key] - // } - // }) - const airtable = new AirtablePlus({ apiKey: process.env.AIRTABLE_API_KEY, baseID: 'app4kCWulfB02bV8Q', @@ -38,8 +30,6 @@ export default async function handler(req, res) { const project = await airtable.update(projectID, updatedFields ) - console.log(project.fields) - const results = { id: project.id, title: project.fields['Name'] || '',