From 534b0f9356cc8f25613092d6e05dba05ffc7963e Mon Sep 17 00:00:00 2001 From: Dominic Zimmer Date: Thu, 22 Oct 2020 16:56:16 +0200 Subject: [PATCH] Initial commit --- src/App.css | 11 +++++++++-- src/App.tsx | 9 ++++++--- src/Gallery.tsx | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/GalleryCard.tsx | 13 +++++++++++++ src/index.tsx | 4 ++-- 5 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 src/Gallery.tsx create mode 100644 src/GalleryCard.tsx diff --git a/src/App.css b/src/App.css index 74b5e05..57bbcbe 100644 --- a/src/App.css +++ b/src/App.css @@ -1,5 +1,7 @@ -.App { - text-align: center; +body { + margin: 8px; + padding: 10px; + background-color: #1e1e1e; } .App-logo { @@ -13,6 +15,11 @@ } } +.img-card { + width: 95px; + padding: 0px 1px 0px 1px; +} + .App-header { background-color: #282c34; min-height: 100vh; diff --git a/src/App.tsx b/src/App.tsx index a53698a..79f857b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,14 +1,17 @@ import React from 'react'; import logo from './logo.svg'; import './App.css'; +import BoldText from './BoldText'; -function App() { + + +const App : React.FC<{}> = () => { return (
logo

- Edit src/App.tsx and save to reload. + Edit src/App.tsx and to reload.

); -} +}; export default App; diff --git a/src/Gallery.tsx b/src/Gallery.tsx new file mode 100644 index 0000000..434d4b2 --- /dev/null +++ b/src/Gallery.tsx @@ -0,0 +1,45 @@ +import React, { Fragment, useEffect, useState } from 'react'; +import './App.css'; +import GalleryCard from './GalleryCard'; + +const defaultSet: any = (size: number) => { + const newSet = new Set(); + for (var i: number = 1; i <= size; i++) newSet.add(i); + return newSet; +} + +const loadSet: (() => Set) = () => { + var href: string = document.location.href; + var afterHref: string = href.indexOf("#") === -1 ? "" : href.substring(href.indexOf("#") + 1); + var numbers = afterHref === "" ? [] : afterHref.split(",").filter(s => s !== "").map(i => parseInt(i)); + return new Set([...numbers]); +}; + +const Gallery: React.FC<{ size: number }> = ({ size }) => { + const originalSet: Set = defaultSet(size); + const [collection, setCollection] = useState(loadSet()); + + function addToCollection(toRemove: number) { + return setCollection(previousState => new Set([...Array.from(previousState), toRemove])); + } + + function getStateString() { + var s = Array.from(collection).sort((a, b) => a - b).join(",") + return s; + } + + useEffect(() => { + var href = document.location.href; + var pureHref = (href.indexOf("#") === -1) ? href : href.substring(0, href.indexOf("#")); + document.location.href = `${pureHref}#${getStateString()}`; + }); + + return ( + + {Array.from(originalSet).filter(element => !collection.has(element)).map((value, key, theset) => + addToCollection(value)} /> + )} + ) +}; + +export default Gallery; \ No newline at end of file diff --git a/src/GalleryCard.tsx b/src/GalleryCard.tsx new file mode 100644 index 0000000..ae498fa --- /dev/null +++ b/src/GalleryCard.tsx @@ -0,0 +1,13 @@ +import React from 'react'; +import './App.css'; + +const GalleryCard: React.FC<{ id: number, clickHandler: any }> = ({ id, clickHandler }) => { + return {`Pokemon; +}; + +export default GalleryCard; \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx index f5185c1..0ef5b24 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,12 +1,12 @@ import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; -import App from './App'; +import Gallery from './Gallery'; import * as serviceWorker from './serviceWorker'; ReactDOM.render( - + , document.getElementById('root') );