Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add menu component #6

Merged
merged 2 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions components/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Link from "next/link";
import { useRouter } from "next/router"

const config = [
{
name: 'Home',
path: '/'
},
{
name: '+Create',
path: '/create'
},
{
name: 'My Articles',
path: '/articles-my'
},
{
name: 'All Articles',
path: '/articles-all'
},
{
name: 'My NFTs',
path: '/my-nfts'
},
{
name: 'My Collections',
path: '/my-collections'
},
{
name: 'NFT Market',
path: '/nft-market'
},
]

export const Navigation = () => {
const router = useRouter()
console.log(router.asPath);
const isActivePath = (path: string) => router.asPath === path
return (
<div className="flex mt-4">
{ config.map((item) => {
return (
<Link key={item.path} href={item.path}>
<a className={`mr-4 text-pink-500 _nav ${ isActivePath(item.path) && 'current'}`} id="_home">
{item.name}
</a>
</Link>
)
})}
</div>
)
}
43 changes: 3 additions & 40 deletions pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import "../styles/globals.css"
import "../styles/markdown.css"
import { FrontendVersion } from "../version.js"
import Link from "next/link"
import Head from "next/head"
import { useState } from "react"
import { ethers } from "ethers"
import { Menu, Transition } from "@headlessui/react"
import { Fragment, useEffect, useRef } from "react"
import { Fragment, useEffect } from "react"
import { ChevronDownIcon } from "@heroicons/react/solid"
import { useRouter } from "next/router"
import {Navigation} from "../components/Navigation";
import axios from "axios"

// On production, you should use something like web3Modal
Expand Down Expand Up @@ -181,43 +180,7 @@ function Marketplace({ Component, pageProps }) {

<nav className="border-b p-6">
<p className="text-4xl font-bold">Creative Commons NFT Playground</p>
<div className="flex mt-4">
<Link href="/">
<a className="mr-4 text-pink-500 _nav" id="_home">
Home
</a>
</Link>
<Link href="/create">
<a className="mr-4 text-pink-500 _nav" id="_create">
+Create
</a>
</Link>
<Link href="/articles-my">
<a className="mr-4 text-pink-500 _nav" id="_articles_my">
My Articles
</a>
</Link>
<Link href="/articles-all">
<a className="mr-4 text-pink-500 _nav" id="_articles_all">
All Articles
</a>
</Link>
<Link href="/my-nfts">
<a className="mr-4 text-pink-500 _nav" id="_my_nfts">
My NFTs
</a>
</Link>
<Link href="/my-collections">
<a className="mr-4 text-pink-500 _nav" id="_my_collections">
My Collections
</a>
</Link>
<Link href="/nft-market">
<a className="mr-4 text-pink-500 _nav" id="_nft_market">
NFT Market
</a>
</Link>
</div>
<Navigation />
<button
style={{ display: Logined ? "none" : "block" }}
onClick={ConnectWallet}
Expand Down
9 changes: 0 additions & 9 deletions pages/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ export default function MyAssets() {
// const [nft, setNft] = useState({})
const [loadingState, setLoadingState] = useState("not-loaded")
const router = useRouter()
console.log(router) // pathname: '/', route: '/', asPath: '/'
if (router.pathname == "/article") {
if (typeof document !== "undefined") {
var els = document.getElementsByClassName("_nav")
Array.prototype.forEach.call(els, function (el) {
el.classList.remove("current")
})
}
}

async function createMint() {
/* first, upload to IPFS */
Expand Down
15 changes: 0 additions & 15 deletions pages/articles-all.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
import { ethers } from "ethers"
import { useEffect, useState } from "react"
import axios from "axios"
import { useRouter } from "next/router"

import { nftmarketaddress, nftaddress } from "../config"

let ethAccount
export default function MyAssets() {
const [nfts, setNfts] = useState([])
const [loadingState, setLoadingState] = useState("not-loaded")
const router = useRouter()
console.log(router) // pathname: '/', route: '/', asPath: '/'
if (router.pathname == "/articles-all") {
if (typeof document !== "undefined") {
var els = document.getElementsByClassName("_nav")
Array.prototype.forEach.call(els, function (el) {
console.log(el.tagName)
console.log(el.classList)
el.classList.remove("current")
})
document.getElementById("_articles_all").classList.add("current")
}
}

console.log("router.query", router.query)
ethAccount = "*"
useEffect(() => {
loadNFTs()
Expand Down
11 changes: 0 additions & 11 deletions pages/articles-my.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import { ethers } from "ethers"
import { useEffect, useState } from "react"
import axios from "axios"
import { useRouter } from "next/router"

import { nftmarketaddress, nftaddress } from "../config"

let ethAccount
export default function MyAssets() {
const [nfts, setNfts] = useState([])
const [loadingState, setLoadingState] = useState("not-loaded")
const router = useRouter()

if (router.pathname == "/articles-my") {
if (typeof document !== "undefined") {
var els = document.getElementsByClassName("_nav")
Array.prototype.forEach.call(els, function (el) {
el.classList.remove("current")
})
document.getElementById("_articles_my").classList.add("current")
}
}
if (typeof window !== "undefined") {
ethAccount = localStorage.getItem("ethAccount")
}
Expand Down
9 changes: 0 additions & 9 deletions pages/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ export default function MyAssets() {
// useEffect(function() {
// },[]);
const router = useRouter()
console.log(router)
if (router.pathname == "/articles") {
if (typeof document !== "undefined") {
var els = document.getElementsByClassName("_nav")
Array.prototype.forEach.call(els, function (el) {
el.classList.remove("current")
})
}
}

console.log(router.query)
if ("author" in router.query) {
Expand Down
11 changes: 0 additions & 11 deletions pages/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ export default function CreateItem() {
const [ethAccount, setEthAccount] = useState<string>()
const [preview, setPreview] = useState<string>()

// todo: remove this menu active track
if (router.pathname == "/create") {
if (typeof document !== "undefined") {
const els = document.getElementsByClassName("_nav")
Array.prototype.forEach.call(els, function (el) {
el.classList.remove("current")
})
document.getElementById("_create")?.classList?.add("current")
}
}

useEffect(() => {
if (typeof window !== "undefined") {
const account = localStorage.getItem("ethAccount")
Expand Down
12 changes: 0 additions & 12 deletions pages/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ethers } from "ethers"
import { useEffect, useState } from "react"
import axios from "axios"
import { useRouter } from "next/router"

import { nftaddress, nftmarketaddress } from "../config"

Expand All @@ -12,17 +11,6 @@ let provider

export default function Home() {
const [nfts, setNfts] = useState([])
const router = useRouter()
console.log(router) // pathname: '/', route: '/', asPath: '/'
if (router.pathname == "/") {
if (typeof document !== "undefined") {
var els = document.getElementsByClassName("_nav")
Array.prototype.forEach.call(els, function (el) {
el.classList.remove("current")
})
document.getElementById("_home").classList.add("current")
}
}

return (
<div className="px-4" style={{ maxWidth: "1600px" }}>
Expand Down
13 changes: 0 additions & 13 deletions pages/my-collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ethers } from "ethers"
import { useEffect, useState } from "react"
import axios from "axios"
import Web3Modal from "web3modal"
import { useRouter } from "next/router"
import { nftmarketaddress, nftaddress } from "../config"

import Market from "../artifacts/contracts/Market.sol/NFTMarket.json"
Expand All @@ -12,18 +11,6 @@ export default function MyAssets() {
const [nfts, setNfts] = useState([])
const [loadingState, setLoadingState] = useState("not-loaded")

const router = useRouter()
console.log(router)
if (router.pathname == "/my-collections") {
if (typeof document !== "undefined") {
var els = document.getElementsByClassName("_nav")
Array.prototype.forEach.call(els, function (el) {
el.classList.remove("current")
})
document.getElementById("_my_collections").classList.add("current")
}
}

useEffect(() => {
loadNFTs()
}, [])
Expand Down
13 changes: 0 additions & 13 deletions pages/my-nfts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ethers } from "ethers"
import { useEffect, useState } from "react"
import axios from "axios"
import Web3Modal from "web3modal"
import { useRouter } from "next/router"
import { nftmarketaddress, nftaddress } from "../config"

import Market from "../artifacts/contracts/Market.sol/NFTMarket.json"
Expand All @@ -13,18 +12,6 @@ export default function CreatorDashboard() {
const [sold, setSold] = useState([])
const [loadingState, setLoadingState] = useState("not-loaded")

const router = useRouter()
console.log(router)
if (router.pathname == "/my-nfts") {
if (typeof document !== "undefined") {
var els = document.getElementsByClassName("_nav")
Array.prototype.forEach.call(els, function (el) {
el.classList.remove("current")
})
document.getElementById("_my_nfts").classList.add("current")
}
}

useEffect(() => {
loadNFTs()
}, [])
Expand Down
13 changes: 0 additions & 13 deletions pages/nft-market.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ethers } from "ethers"
import { useEffect, useState } from "react"
import axios from "axios"
import Web3Modal from "web3modal"
import { useRouter } from "next/router"

import { nftaddress, nftmarketaddress } from "../config"

Expand All @@ -13,18 +12,6 @@ export default function Home() {
const [nfts, setNfts] = useState([])
const [loadingState, setLoadingState] = useState("not-loaded")

const router = useRouter()
console.log(router)
if (router.pathname == "/nft-market") {
if (typeof document !== "undefined") {
var els = document.getElementsByClassName("_nav")
Array.prototype.forEach.call(els, function (el) {
el.classList.remove("current")
})
document.getElementById("_nft_market").classList.add("current")
}
}

useEffect(() => {
loadNFTs()
}, [])
Expand Down