-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
71 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
import { Card } from './components/Card' | ||
import * as rawChallenges from './challenges' | ||
import { List } from './components/List' | ||
|
||
export function App() { | ||
const challenges = Object.values(rawChallenges) | ||
|
||
return ( | ||
<div className="App"> | ||
{challenges.map((challenge) => ( | ||
<Card key={challenge.title} {...challenge} /> | ||
))} | ||
</div> | ||
<main className="App"> | ||
<List challenges={challenges} /> | ||
</main> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type Challenge = { | ||
title: string | ||
url: string | ||
solution: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
import { HTMLAttributes } from 'react' | ||
import parse from 'html-react-parser' | ||
|
||
import { Challenge } from '../../challenges/types' | ||
import { IFrame } from '../IFrame' | ||
// import styles from './index.module.css' | ||
|
||
export type CardProps = HTMLAttributes<HTMLDivElement> & { | ||
title: string | ||
url: string | ||
solution: string | ||
} | ||
export type CardProps = HTMLAttributes<HTMLDivElement> & Challenge | ||
|
||
export function Card({ title, url, solution }: CardProps) { | ||
export function Card({ solution }: CardProps) { | ||
return ( | ||
<a href={url} target="_blank" rel="noreferrer"> | ||
<article className="Card"> | ||
<h1>{title}</h1> | ||
|
||
<IFrame width={400} height={300}> | ||
{parse(solution)} | ||
</IFrame> | ||
</article> | ||
</a> | ||
<IFrame width={400} height={300}> | ||
{parse(solution)} | ||
</IFrame> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.container { | ||
display: block; | ||
border: none; | ||
pointer-events: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.container { | ||
display: flex; | ||
flex-wrap: wrap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { HTMLAttributes, useEffect, useRef, useState } from 'react' | ||
|
||
import { Challenge } from '../../challenges/types' | ||
import { Card } from '../Card' | ||
import styles from './index.module.css' | ||
|
||
export type ListProps = HTMLAttributes<HTMLUListElement> & { | ||
challenges: Challenge[] | ||
} | ||
|
||
export function List({ challenges }: ListProps) { | ||
const debounceRef = useRef<number>() | ||
const [availableWidth, setAvailableWidth] = useState(window.innerWidth) | ||
|
||
function handleResize() { | ||
clearTimeout(debounceRef.current) | ||
|
||
debounceRef.current = setTimeout(() => { | ||
setAvailableWidth(window.innerWidth) | ||
}, 100) | ||
} | ||
|
||
useEffect(() => { | ||
window.addEventListener('resize', handleResize) | ||
|
||
return () => { | ||
window.removeEventListener('resize', handleResize) | ||
} | ||
}, []) | ||
|
||
const columns = Math.floor(availableWidth / 400) | ||
const contentWidth = columns * 400 | ||
const scale = availableWidth / contentWidth | ||
|
||
return ( | ||
<ul | ||
className={styles.container} | ||
style={{ | ||
transform: `scale(${scale})`, | ||
transformOrigin: 'top left', | ||
maxWidth: contentWidth, | ||
}} | ||
> | ||
{challenges.map((challenge) => ( | ||
<li key={challenge.title}> | ||
<Card {...challenge} /> | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
} |