Skip to content

Commit

Permalink
realms navigation and query cluster improvements (solana-labs#39)
Browse files Browse the repository at this point in the history
* cluster as query param

* better navigation in realms and default dao mode

* fix dao navigation
  • Loading branch information
abrzezinski94 authored Oct 6, 2021
1 parent 07dcd26 commit 2a863cd
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 15 deletions.
15 changes: 11 additions & 4 deletions components/OrganzationsBackNav.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import React from 'react'
import useRealm from '../hooks/useRealm'
import { useRouter } from 'next/router'
import { GlobeAltIcon } from '@heroicons/react/outline'
import { ArrowLeftIcon } from '@heroicons/react/solid'
import Link from 'next/link'
import { TwitterIcon } from '../components/icons'
import { EndpointTypes } from '../models/types'

const OrganzationsBackNav = () => {
const { symbol, realm, realmInfo } = useRealm()
const { REALM } = process.env
const router = useRouter()
const { cluster } = router.query
const { realm, realmInfo } = useRealm()

const endpoint = cluster ? (cluster as EndpointTypes) : 'mainnet'
const realmName = realmInfo?.displayName ?? realm?.info?.name
const hideBackNav = !router.asPath.includes('dao') // only hide backnav when on default realm
const backNavLink =
endpoint === 'mainnet' ? '/realms' : `/realms?cluster=${endpoint}`

const hideBackNav = REALM != symbol // only hide backnav when on default realm
return (
<div className="pb-4">
{hideBackNav ? (
<Link href={`/realms`}>
<Link href={backNavLink}>
<a className="default-transition flex items-center mb-6 text-fgd-3 text-sm transition-all hover:text-fgd-1">
<ArrowLeftIcon className="h-4 w-4 mr-1 text-primary-light" />
Back
Expand Down
4 changes: 3 additions & 1 deletion components/ProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import useProposalVotes from '../hooks/useProposalVotes'
import VoteResultsBar from './VoteResultsBar'
import ProposalTimeStatus from './ProposalTimeStatus'
import useWalletStore from '../stores/useWalletStore'
import useRealmContext from '../hooks/useRealmContext'

type ProposalCardProps = {
id: string
Expand All @@ -27,6 +28,7 @@ const StyledCardWrapepr = styled.div`

const ProposalCard = ({ id, proposal }: ProposalCardProps) => {
const { symbol } = useRealm()
const { urlContext } = useRealmContext()
const {
yesVoteProgress,
relativeNoVotes,
Expand All @@ -41,7 +43,7 @@ const ProposalCard = ({ id, proposal }: ProposalCardProps) => {

return (
<div>
<Link href={`/dao/${symbol}/proposal/${id}`}>
<Link href={`/${urlContext}/${symbol}/proposal/${id}`}>
<a>
<StyledCardWrapepr className="bg-bkg-2 border border-bkg-3 default-transition rounded-lg hover:bg-bkg-3">
<div className="px-6 py-4">
Expand Down
4 changes: 2 additions & 2 deletions hooks/useHydrateStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import useWalletStore, { ENDPOINTS } from '../stores/useWalletStore'

export default function useHydrateStore() {
const router = useRouter()
const { symbol, endpoint, pk } = router.query
const apiEndpoint = endpoint ? (endpoint[0] as EndpointTypes) : 'mainnet'
const { symbol, cluster, pk } = router.query
const apiEndpoint = cluster ? (cluster as EndpointTypes) : 'mainnet'
const mints = useWalletStore((s) => s.mints)
const setWalletStore = useWalletStore((s) => s.set)
const { fetchAllRealms, fetchRealm, fetchProposal } = useWalletStore(
Expand Down
4 changes: 2 additions & 2 deletions hooks/useRealm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import useWalletStore from '../stores/useWalletStore'

export default function useRealm() {
const router = useRouter()
const { symbol, endpoint } = router.query
const apiEndpoint = endpoint ? (endpoint[0] as EndpointTypes) : 'mainnet'
const { symbol, cluster } = router.query
const apiEndpoint = cluster ? (cluster as EndpointTypes) : 'mainnet'
const connected = useWalletStore((s) => s.connected)
const wallet = useWalletStore((s) => s.current)
const tokenAccounts = useWalletStore((s) => s.tokenAccounts)
Expand Down
9 changes: 9 additions & 0 deletions hooks/useRealmContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useRouter } from 'next/router'

export default function useRealmContext() {
const router = useRouter()
const urlContext = router.asPath.includes('realm') ? 'realm' : 'dao'
return {
urlContext,
}
}
1 change: 0 additions & 1 deletion models/registry/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export function getRealmInfo(
if (!symbol) {
return undefined
}
console.log(endpoint === 'devnet', '@@@@@@@@')
if (endpoint === 'devnet') {
let devRealmInfo = getAllRealmInfos('devnet').find((r) =>
equalsIgnoreCase(r.symbol, symbol)
Expand Down
8 changes: 8 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ module.exports = withTM({
env: {
REALM: process.env.REALM,
},
async rewrites() {
return [
{
source: '/realm/:symbol*',
destination: '/dao/:symbol*',
},
]
},
})
File renamed without changes.
4 changes: 3 additions & 1 deletion pages/dao/[symbol]/proposal/[pk].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import useProposalVotes from '../../../../hooks/useProposalVotes'
import VoteResultsBar from '../../../../components/VoteResultsBar'
import ProposalTimeStatus from '../../../../components/ProposalTimeStatus'
import { option } from '../../../../tools/core/option'
import useRealmContext from '../../../../hooks/useRealmContext'

const Proposal = () => {
const { urlContext } = useRealmContext()
const { symbol } = useRealm()
const { proposal, description, instructions } = useProposal()
const {
Expand All @@ -41,7 +43,7 @@ const Proposal = () => {
<div className="bg-bkg-2 border border-bkg-3 rounded-lg p-6 col-span-8 space-y-3">
{proposal ? (
<>
<Link href={`/dao/${symbol}/`}>
<Link href={`/${urlContext}/${symbol}/`}>
<a className="flex items-center text-fgd-3 text-sm transition-all hover:text-fgd-1">
<ArrowLeftIcon className="h-4 w-4 mr-1 text-primary-light" />
Back
Expand Down
10 changes: 6 additions & 4 deletions pages/realms/[[...endpoint]].tsx → pages/realms/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ import { EndpointTypes } from '../../models/types'

const Realms = () => {
const router = useRouter()
const { cluster } = router.query

const endpoint = cluster ? (cluster as EndpointTypes) : 'mainnet'
//TODO when we fetch realms data from api add loader handling
const [isLoading] = useState(false)
const [realms, setRealms] = useState([])
// const [realmsSearchResults, setSearchResult] = useState([])
// const [search, setSerach] = useState('')
// const [viewType, setViewType] = useState(ROW)
const { actions, selectedRealm } = useWalletStore((s) => s)
const endpoint = router.query.endpoint
? (router.query.endpoint[0] as EndpointTypes)
: 'mainnet'

useEffect(() => {
const data: RealmInfo[] = getAllRealmInfos(endpoint)
Expand All @@ -40,7 +39,10 @@ const Realms = () => {
// }, [search, realms])

const goToRealm = ({ symbol }) => {
router.push(`/dao/${symbol}`)
router.push({
pathname: `/realm/${symbol}`,
query: endpoint !== 'mainnet' ? { cluster: endpoint } : null,
})
}

return (
Expand Down

0 comments on commit 2a863cd

Please sign in to comment.