diff --git a/pages/api/bin/wokwi/new/index.js b/pages/api/bin/wokwi/new/index.js index 1a6852574..51f616821 100644 --- a/pages/api/bin/wokwi/new/index.js +++ b/pages/api/bin/wokwi/new/index.js @@ -43,7 +43,8 @@ const createProject = async (partsList = []) => { const ROW_HEIGHT = 215; // close enough for jazz, keypad is too big for this but ¯\_(ツ)_/¯ const parts = [ - { "type": "board-pi-pico-w", "id": "pico", "top": 0, "left": 0, "attrs": {} } + { "type": "board-pi-pico-w", "id": "pico", "top": 0, "left": 0, "attrs": {}, + "type": "board-pi-pico-w", "id": "pico", "top": 100, "left": 100 , "attrs": {}} ] let x = 88 + PADDING; // for already included Pico let y = 0; @@ -54,15 +55,17 @@ const createProject = async (partsList = []) => { }) return airPart[0].fields['Wokwi Name'].split(',').forEach((name, i) => { const width = airPart[0].fields['Wokwi X-Offset']; + const attrs = airPart[0].fields['attrs']; if ((x + width + PADDING) > MAX_WIDTH) { x = 0; y += ROW_HEIGHT; } parts.push({ type: name, - id: name + '-' + i, + id: name + '--' + i, left: x, - top: y + top: y, + attrs: attrs }) x += width + PADDING; }) diff --git a/pages/bin/gallery.js b/pages/bin/gallery.js new file mode 100644 index 000000000..4359d0968 --- /dev/null +++ b/pages/bin/gallery.js @@ -0,0 +1,130 @@ +import React from 'react' +import BinPost from '../../components/bin/GalleryPosts' +import styles from '../../public/bin/style/gallery.module.css' +import Script from 'next/script' +import Nav from '../../components/bin/nav' +import Footer from '../../components/footer' +import PartTag from '../../components/bin/PartTag'; +import { useEffect, useRef, useState } from 'react'; +import { resolve } from 'styled-jsx/css'; +import { set } from 'lodash'; + +export async function getStaticProps() { + const host = process.env.NODE_ENV === 'development' ? 'http://localhost:3000' : 'https://hackclub.com'; + const res = await fetch(`${host}/api/bin/gallery/posts/`); + const posts = await res.json(); + + const filteredPosts = await posts.filter(post => post.status === 'Accepted' && post.parts && !post.hide); + + //Tags + + const resTag = await fetch(`${host}/api/bin/gallery/tags/`); + const tags = await resTag.json(); + + const filteredTags = tags.filter(tag => !tag.hide); + return { + props: { posts: filteredPosts, + tags: filteredTags + }, + }; +} + + + +function Gallery({ posts = [], tags = [] }) { + + const [allPosts, setAllPosts] = useState([]); + const [filterPosts, setFilterPosts] = useState([]); + const [filterParts, setFilterParts] = useState([]); + + useEffect(() => { + setAllPosts(posts); + setFilterParts([]); + + }, []); + + useEffect(() => { + setFilterPosts( + allPosts.filter(post => + post.parts && filterParts.every(part => post.parts.includes(part)) + ) + ); + }, [filterParts]); + + + const addFilter = (partID) => { + setFilterParts((prevParts) => { + if (!prevParts.includes(partID)) { + return [...prevParts, partID]; + } + return prevParts; + }); + + }; + + const removeFilter = (partID) => { + setFilterParts((prevParts) => { + return prevParts.filter(id => id !== partID); + }); + }; + + return ( +
+ +
+ + + + +
+
+
Want to add to the gallery? window.location.href = '/bin'}>Create a bin project in wokwi and your project will be added to the gallery!
+
+ Search By Tag: +
+ + {tags.map(tag => { + return ( + ) + + })} + +
+ +
+ + + + {filterPosts.map(post => { + return ( + ) + + })} + +
+
+ ) +} + + + +export default Gallery \ No newline at end of file diff --git a/public/bin/index.html b/public/bin/index.html index 881487ad5..66ed8f280 100644 --- a/public/bin/index.html +++ b/public/bin/index.html @@ -104,7 +104,14 @@

Design your project

in 1 week...

Get it IRL

-

Submit your design to the gallery of +

Submit your design and it will get reviewed.

+
+ +
+
+ ...Finally +

View on Gallery

+

See your design on the gallery of projects so other high schoolers can learn from your project.

@@ -171,6 +178,12 @@

Get started or click the raccoon for project ideas!

+
+ +

Check out other projects on the

+