Skip to content

Commit

Permalink
basic frontend working with tailwind
Browse files Browse the repository at this point in the history
  • Loading branch information
worm-emoji committed Aug 30, 2021
1 parent 7cb12e1 commit 09d14a5
Show file tree
Hide file tree
Showing 11 changed files with 752 additions and 134 deletions.
41 changes: 0 additions & 41 deletions components/Layout.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions components/List.tsx

This file was deleted.

16 changes: 0 additions & 16 deletions components/ListDetail.tsx

This file was deleted.

18 changes: 0 additions & 18 deletions components/ListItem.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
"@types/node": "^12.12.21",
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
"autoprefixer": "^10.3.3",
"postcss": "^8.3.6",
"prettier": "^2.3.2",
"typescript": "4.0"
"tailwindcss": "^2.2.8",
"typescript": "^4.4.2"
}
}
26 changes: 26 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'tailwindcss/tailwind.css'
import Head from 'next/head'
function Robes({ Component, pageProps }) {
return (
<>
<Component {...pageProps} />
<style jsx global>
{`
body {
background: black;
color: white;
}
`}
</style>
<Head>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link
href="https://fonts.googleapis.com/css2?family=Inconsolata:wght@400;600;700&display=swap"
rel="stylesheet"
/>
</Head>
</>
)
}

export default Robes
6 changes: 3 additions & 3 deletions pages/api/robes/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NextApiRequest, NextApiResponse } from 'next'
import pMap from 'p-map'
import { chunk, flatten, orderBy, take } from 'lodash'
import { chunk, flatten, orderBy } from 'lodash'
import { utils as etherUtils, BigNumber } from 'ethers'
import type { OpenseaResponse, Asset } from '../../../utils/openseaTypes'
import RobeIDs from '../../../data/robes-ids.json'

const chunked = take(chunk(RobeIDs, 20), 3)
const chunked = chunk(RobeIDs, 20)
const apiKey = process.env.OPENSEA_API_KEY

const fetchRobePage = async (ids: string[]) => {
Expand Down Expand Up @@ -46,7 +46,7 @@ const fetchRobes = async () => {
svg: a.image_url,
}
})
return orderBy(mapped, 'price', 'asc')
return orderBy(mapped, ['price', 'id'], 'asc')
}

const handler = async (_req: NextApiRequest, res: NextApiResponse) => {
Expand Down
66 changes: 54 additions & 12 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
import Link from 'next/link'
import Layout from '../components/Layout'

const IndexPage = () => (
<Layout title="Home | Next.js + TypeScript Example">
<h1>Hello Next.js 👋</h1>
<p>
<Link href="/about">
<a>About</a>
</Link>
</p>
</Layout>
)
import { RobeInfo } from './api/robes'
import { format as ts } from 'timeago.js'

export async function getStaticProps() {
const res = await fetch('https://robes-market.vercel.app/api/robes')
const data = await res.json()

return {
props: {
robes: data.robes,
lastUpdate: data.lastUpdate,
},
revalidate: 300,
}
}

interface Props {
robes: RobeInfo[]
lastUpdate: string
}

const Robe = ({ robe }: { robe: RobeInfo }) => {
return (
<a href={robe.url} target="_blank">
<div className="flex flex-col justify-center items-center gap-2 p-4 m-4 border border-white transform hover:scale-105 transition-all">
<img src={robe.svg} />
<div className="text-center">
<p className="text-lg">#{robe.id}</p>
<p>{robe.price} ETH</p>
</div>
</div>
</a>
)
}

const IndexPage = ({ robes, lastUpdate }: Props) => {
return (
<div className="font-mono flex flex-col justify-center items-center gap-4 pt-10 w-screen">
<h1 className="text-3xl">Divine Robes</h1>
<div className="text-center">
<p className="text-xl">
The current floor price for Divine Robes is {robes[0].price} ETH.
</p>
<p>Last updated {ts(lastUpdate)}</p>

<div className="grid grid-cols-2 pt-5">
{robes.map((robe) => {
return <Robe robe={robe} key={robe.id} />
})}
</div>
</div>
</div>
)
}

export default IndexPage
6 changes: 6 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
14 changes: 14 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
darkMode: false, // or 'media' or 'class'
theme: {
fontFamily: {
mono: 'Inconsolata, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
},
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
Loading

0 comments on commit 09d14a5

Please sign in to comment.