Skip to content

Commit

Permalink
fixed breadcrumbs not having access to DAO info context in page header
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Jun 5, 2024
1 parent 26d64d9 commit cc03bd0
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 12 deletions.
3 changes: 3 additions & 0 deletions packages/stateful/components/dao/CreateDaoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
TooltipInfoIcon,
useAppContext,
useCachedLoadable,
useDaoInfoContextIfAvailable,
useDaoNavHelpers,
useSupportedChainContext,
useThemeContext,
Expand Down Expand Up @@ -146,6 +147,7 @@ export const InnerCreateDaoForm = ({
initialPageIndex = 0,
}: CreateDaoFormProps) => {
const { t } = useTranslation()
const daoInfo = useDaoInfoContextIfAvailable()

const chainContext = useSupportedChainContext()
const {
Expand Down Expand Up @@ -733,6 +735,7 @@ export const InnerCreateDaoForm = ({
}
: undefined,
current: makingSubDao ? t('title.newSubDao') : t('title.newDao'),
daoInfo,
}}
centerNode={
!makingSubDao && (
Expand Down
1 change: 1 addition & 0 deletions packages/stateful/components/dao/CreateDaoProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ const InnerCreateDaoProposal = ({
sdaLabel: t('title.proposals'),
},
current: t('title.createProposal'),
daoInfo,
}}
/>

Expand Down
7 changes: 5 additions & 2 deletions packages/stateful/components/dao/DaoProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface InnerDaoProposalProps {

const InnerDaoProposal = ({ proposalInfo }: InnerDaoProposalProps) => {
const { t } = useTranslation()
const { coreAddress } = useDaoInfoContext()
const daoInfo = useDaoInfoContext()
const { address } = useWallet()

const proposalModuleAdapterContext = useProposalModuleAdapterContext()
Expand Down Expand Up @@ -135,7 +135,9 @@ const InnerDaoProposal = ({ proposalInfo }: InnerDaoProposalProps) => {
toast.loading(t('success.proposalExecuted'))

// Manually revalidate DAO static props.
await fetch(`/api/revalidate?d=${coreAddress}&p=${proposalInfo.id}`)
await fetch(
`/api/revalidate?d=${daoInfo.coreAddress}&p=${proposalInfo.id}`
)

// Refresh entire app since any DAO config may have changed.
window.location.reload()
Expand Down Expand Up @@ -244,6 +246,7 @@ const InnerDaoProposal = ({ proposalInfo }: InnerDaoProposalProps) => {
sdaLabel: t('title.proposals'),
},
current: `${t('title.proposal')} ${proposalInfo.id}`,
daoInfo,
}}
rightNode={
canVote ? (
Expand Down
8 changes: 7 additions & 1 deletion packages/stateful/components/gov/CreateGovProposal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { useRef } from 'react'
import { useTranslation } from 'react-i18next'

import { CreateProposal, PageLoader } from '@dao-dao/stateless'
import {
CreateProposal,
PageLoader,
useDaoInfoContextIfAvailable,
} from '@dao-dao/stateless'
import { DaoTabId } from '@dao-dao/types'

import { GovActionsProvider } from '../../actions'
Expand All @@ -11,6 +15,7 @@ import { NewGovProposal } from './NewGovProposal'

export const CreateGovProposal = () => {
const { t } = useTranslation()
const daoInfo = useDaoInfoContextIfAvailable()

const clearRef = useRef(() => {})
const copyDraftLinkRef = useRef(() => {})
Expand All @@ -24,6 +29,7 @@ export const CreateGovProposal = () => {
sdaLabel: t('title.proposals'),
},
current: t('title.createProposal'),
daoInfo,
}}
/>

Expand Down
3 changes: 3 additions & 0 deletions packages/stateful/components/gov/GovProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ProposalNotFound,
useCachedLoadingWithError,
useChain,
useDaoInfoContextIfAvailable,
} from '@dao-dao/stateless'
import {
BaseProposalVotesProps,
Expand Down Expand Up @@ -47,6 +48,7 @@ type InnerGovProposalProps = {
const InnerGovProposal = ({ proposal }: InnerGovProposalProps) => {
const { t } = useTranslation()
const { chain_id: chainId } = useChain()
const daoInfo = useDaoInfoContextIfAvailable()

const proposalId = proposal.id.toString()
const loadingProposal = useLoadingGovProposal(proposalId)
Expand Down Expand Up @@ -114,6 +116,7 @@ const InnerGovProposal = ({ proposal }: InnerGovProposalProps) => {
sdaLabel: t('title.proposals'),
},
current: `${t('title.proposal')} ${proposalId}`,
daoInfo,
}}
rightNode={
proposal.proposal.status ===
Expand Down
4 changes: 2 additions & 2 deletions packages/stateful/components/pages/DaoDappHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ export const InnerDaoDappHome = ({
...props
}: InnerDaoDappHomeProps) => {
const { t } = useTranslation()
const { getDaoPath, getDaoProposalPath, router } = useDaoNavHelpers()

const daoInfo = useDaoInfoContext()
const { getDaoPath, getDaoProposalPath, router } = useDaoNavHelpers()

const { isFollowing, setFollowing, setUnfollowing, updatingFollowing } =
useFollowingDaos()
Expand Down Expand Up @@ -111,6 +110,7 @@ export const InnerDaoDappHome = ({
breadcrumbs={{
home: true,
current: daoInfo.name,
daoInfo,
}}
rightNode={
<>
Expand Down
11 changes: 6 additions & 5 deletions packages/stateful/components/pages/DaoSdaHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { SuspenseLoader } from '../SuspenseLoader'

export const DaoSdaHome = () => {
const router = useRouter()
const { coreAddress } = useDaoInfoContext()
const daoInfo = useDaoInfoContext()
const { getDaoPath } = useDaoNavHelpers()

const loadingTabs = useDaoTabs()
Expand All @@ -27,9 +27,9 @@ export const DaoSdaHome = () => {
// Pre-fetch tabs.
useEffect(() => {
tabs?.forEach((tab) => {
router.prefetch(getDaoPath(coreAddress, tab.id))
router.prefetch(getDaoPath(daoInfo.coreAddress, tab.id))
})
}, [coreAddress, getDaoPath, router, tabs])
}, [daoInfo.coreAddress, getDaoPath, router, tabs])

const slug = (router.query.slug || []) as string[]
const checkedSlug = useRef(false)
Expand All @@ -44,11 +44,11 @@ export const DaoSdaHome = () => {

// If no slug, redirect to first tab.
if (slug.length === 0) {
router.replace(getDaoPath(coreAddress, firstTabId), undefined, {
router.replace(getDaoPath(daoInfo.coreAddress, firstTabId), undefined, {
shallow: true,
})
}
}, [coreAddress, getDaoPath, router, slug.length, firstTabId])
}, [daoInfo.coreAddress, getDaoPath, router, slug.length, firstTabId])

const selectedTabId =
slug.length > 0 && tabs?.some(({ id }) => id === slug[0])
Expand All @@ -65,6 +65,7 @@ export const DaoSdaHome = () => {
breadcrumbs={{
home: true,
current: activeTab?.label,
daoInfo,
}}
/>

Expand Down
3 changes: 2 additions & 1 deletion packages/stateless/components/layout/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ export const Breadcrumbs = ({
override = false,
homeTab,
current,
daoInfo: _daoInfo,
className,
}: BreadcrumbsProps) => {
const { t } = useTranslation()
// Allow using Breadcrumbs outside of DaoPageWrapper.
const daoInfo = useDaoInfoContextIfAvailable()
const daoInfo = useDaoInfoContextIfAvailable() || _daoInfo
const { mode } = useAppContext()
const { getDaoPath } = useDaoNavHelpers()

Expand Down
7 changes: 6 additions & 1 deletion packages/types/components/Breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode } from 'react'

import { DaoTabId } from '../dao'
import { DaoInfo, DaoTabId } from '../dao'

export type BreadcrumbCrumb = {
href: string
Expand Down Expand Up @@ -31,6 +31,11 @@ export type BreadcrumbsProps = {
* The current crumb.
*/
current: ReactNode
/**
* DAO info, if this is being rendered outside of the context provider (like
* in the PageHeader), but still needs access to the DAO info.
*/
daoInfo?: DaoInfo | null
/**
* Optional container class name.
*/
Expand Down

0 comments on commit cc03bd0

Please sign in to comment.