Skip to content

Commit

Permalink
feat: Navbar from UI2 (#3235)
Browse files Browse the repository at this point in the history
* feat: Navbar from UI2

* feat: use DclThemeProvider

* feat: decentraland-ui2 v0.8.7
  • Loading branch information
braianj authored Jan 8, 2025
1 parent e25ca3e commit c6bd5a7
Show file tree
Hide file tree
Showing 8 changed files with 631 additions and 78 deletions.
662 changes: 593 additions & 69 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
"decentraland-builder-scripts": "^0.24.0",
"decentraland-connect": "^7.3.2",
"decentraland-crypto-fetch": "^2.0.1",
"decentraland-dapps": "^23.17.0",
"decentraland-dapps": "^23.22.0",
"decentraland-ecs": "6.12.4-7784644013.commit-f770b3e",
"decentraland-experiments": "^1.0.2",
"decentraland-transactions": "^2.16.0",
"decentraland-ui": "^6.12.1",
"decentraland-ui2": "^0.8.7",
"ethers": "^5.6.8",
"file-saver": "^2.0.1",
"graphql": "^15.8.0",
Expand Down
4 changes: 3 additions & 1 deletion src/components/Navbar/Navbar.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { RootState } from 'modules/common/types'
import { getTransactions } from 'modules/transaction/selectors'
import { MapStateProps, MapDispatchProps, OwnProps } from './Navbar.types'
import Navbar from './Navbar'
import { getIsNavbar2Enabled } from 'modules/features/selectors'

const mapState = (state: RootState): MapStateProps => ({
hasPendingTransactions: getTransactions(state).some(tx => isPending(tx.status)),
address: getAddress(state),
isSignedIn: isLoggedIn(state)
isSignedIn: isLoggedIn(state),
isNavbar2Enabled: getIsNavbar2Enabled(state)
})

const mergeProps = (mapStateProps: MapStateProps, mapDispatchProps: MapDispatchProps, ownProps: OwnProps) => ({
Expand Down
16 changes: 15 additions & 1 deletion src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React, { useMemo } from 'react'
import { useHistory } from 'react-router-dom'
import { locations } from 'routing/locations'
import { Navbar as BaseNavbar } from 'decentraland-dapps/dist/containers/'
import { Navbar2 as BaseNavbar2 } from 'decentraland-dapps/dist/containers/Navbar'
import { NavbarPages } from 'decentraland-ui/dist/components/Navbar/Navbar.types'
import { localStorageGetIdentity } from '@dcl/single-sign-on-client'
import { Props } from './Navbar.types'

import './Navbar.css'

const Navbar: React.FC<Props> = ({ hasPendingTransactions, address, ...props }: Props) => {
const Navbar: React.FC<Props> = ({ hasPendingTransactions, address, isNavbar2Enabled, ...props }: Props) => {
const history = useHistory()
const identity = useMemo(() => {
if (address) {
Expand All @@ -21,6 +22,19 @@ const Navbar: React.FC<Props> = ({ hasPendingTransactions, address, ...props }:
history.push(locations.signIn())
}

if (isNavbar2Enabled) {
return (
<BaseNavbar2
{...props}
withNotifications
activePage={NavbarPages.CREATE}
hasActivity={hasPendingTransactions}
identity={identity}
onSignIn={onSignIn}
/>
)
}

return (
<BaseNavbar
activePage={NavbarPages.CREATE}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Navbar/Navbar.types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NavbarProps } from 'decentraland-dapps/dist/containers/Navbar/Navbar.types'
import { Dispatch } from 'redux'

export type Props = Partial<NavbarProps> & { hasPendingTransactions: boolean; address?: string }
export type Props = Partial<NavbarProps> & { hasPendingTransactions: boolean; address?: string; isNavbar2Enabled: boolean }

export type MapStateProps = Pick<Props, 'hasPendingTransactions' | 'isSignedIn' | 'address'>
export type MapStateProps = Pick<Props, 'hasPendingTransactions' | 'isSignedIn' | 'address' | 'isNavbar2Enabled'>
export type MapDispatchProps = Pick<Props, 'onSignIn'>
export type MapDispatch = Dispatch
export type OwnProps = Partial<Props>
9 changes: 6 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ModalProvider from 'decentraland-dapps/dist/providers/ModalProvider'
import ToastProvider from 'decentraland-dapps/dist/providers/ToastProvider'
import TranslationProvider from 'decentraland-dapps/dist/providers/TranslationProvider'
import WalletProvider from 'decentraland-dapps/dist/providers/WalletProvider'
import { darkTheme, DclThemeProvider } from 'decentraland-ui2'

import { store, history } from 'modules/common/store'
import * as modals from 'components/Modals'
Expand All @@ -25,11 +26,13 @@ ReactDOM.render(
<TranslationProvider locales={Object.keys(languages)}>
<WalletProvider>
<ConnectedRouter history={history}>
<ModalProvider components={modals}>
<DclThemeProvider theme={darkTheme}>
<ToastProvider>
<Routes />
<ModalProvider components={modals}>
<Routes />
</ModalProvider>
</ToastProvider>
</ModalProvider>
</DclThemeProvider>
</ConnectedRouter>
</WalletProvider>
</TranslationProvider>
Expand Down
8 changes: 8 additions & 0 deletions src/modules/features/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,11 @@ export const getIsOffchainPublicItemOrdersEnabled = (state: RootState) => {
return false
}
}

export const getIsNavbar2Enabled = (state: RootState) => {
try {
return getIsFeatureEnabled(state, ApplicationName.DAPPS, FeatureName.NAVBAR_UI2)
} catch (e) {
return false
}
}
3 changes: 2 additions & 1 deletion src/modules/features/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export enum FeatureName {
WORLD_CONTRIBUTOR = 'world-contributor',
LINKED_WEARABLES_V2 = 'linked-wearables-v2',
LINKED_WEARABLES_PAYMENTS = 'linked-wearables-payments',
OFFCHAIN_PUBLIC_ITEM_ORDERS = 'offchain-public-item-orders'
OFFCHAIN_PUBLIC_ITEM_ORDERS = 'offchain-public-item-orders',
NAVBAR_UI2 = 'navbar-ui2'
}

0 comments on commit c6bd5a7

Please sign in to comment.