From 61aaaeeebcb1c0c562be59e8447df6cb7374ca41 Mon Sep 17 00:00:00 2001
From: Kevin Szuchet <31735779+kevinszuchet@users.noreply.github.com>
Date: Tue, 15 Aug 2023 17:25:10 +0200
Subject: [PATCH] feat: Add navbar (#5)
* feat: Add navbar
* chore: Open server when start app
* style: Css file styles and delete empty file
---
src/components/Navbar/Navbar.container.ts | 11 +++++
src/components/Navbar/Navbar.css | 33 +++++++++++++
src/components/Navbar/Navbar.tsx | 28 +++++++++++
src/components/Navbar/Navbar.types.ts | 7 +++
src/components/Navbar/index.ts | 1 +
.../PageLayout/PageLayout.module.css | 1 +
src/components/PageLayout/PageLayout.tsx | 2 +
src/components/UserMenu/UserMenu.container.ts | 48 +++++++++++++++++++
src/components/UserMenu/UserMenu.types.ts | 12 +++++
src/components/UserMenu/index.ts | 1 +
vite.config.ts | 2 +-
11 files changed, 145 insertions(+), 1 deletion(-)
create mode 100644 src/components/Navbar/Navbar.container.ts
create mode 100644 src/components/Navbar/Navbar.css
create mode 100644 src/components/Navbar/Navbar.tsx
create mode 100644 src/components/Navbar/Navbar.types.ts
create mode 100644 src/components/Navbar/index.ts
create mode 100644 src/components/UserMenu/UserMenu.container.ts
create mode 100644 src/components/UserMenu/UserMenu.types.ts
create mode 100644 src/components/UserMenu/index.ts
diff --git a/src/components/Navbar/Navbar.container.ts b/src/components/Navbar/Navbar.container.ts
new file mode 100644
index 0000000..6782959
--- /dev/null
+++ b/src/components/Navbar/Navbar.container.ts
@@ -0,0 +1,11 @@
+import { connect } from 'react-redux'
+import { isConnected } from 'decentraland-dapps/dist/modules/wallet/selectors'
+import { RootState } from '../../modules/reducer'
+import Navbar from './Navbar'
+import { MapStateProps } from './Navbar.types'
+
+const mapState = (state: RootState): MapStateProps => ({
+ isConnected: isConnected(state)
+})
+
+export default connect(mapState)(Navbar)
diff --git a/src/components/Navbar/Navbar.css b/src/components/Navbar/Navbar.css
new file mode 100644
index 0000000..8172045
--- /dev/null
+++ b/src/components/Navbar/Navbar.css
@@ -0,0 +1,33 @@
+.dcl.navbar .ui.menu .item .bell {
+ color: var(--text);
+}
+
+.dcl.navbar .ui.menu .item.active .bell {
+ color: var(--primary);
+}
+
+.dcl.account-wrapper .dcl.mana {
+ flex: none;
+}
+
+@media (max-width: 991px) {
+ .dcl.navbar .dcl.account-wrapper {
+ flex-direction: column;
+ align-items: flex-start;
+ }
+
+ .dcl.account-wrapper .dcl.mana+.dcl.mana {
+ padding: 0;
+ }
+}
+
+.dcl.navbar .ui.menu .item .bell.pending:after {
+ content: '';
+ width: 5px;
+ height: 5px;
+ background-color: var(--primary);
+ position: absolute;
+ border-radius: 100%;
+ top: -5px;
+ right: -5px;
+}
diff --git a/src/components/Navbar/Navbar.tsx b/src/components/Navbar/Navbar.tsx
new file mode 100644
index 0000000..978091e
--- /dev/null
+++ b/src/components/Navbar/Navbar.tsx
@@ -0,0 +1,28 @@
+import React, { useCallback } from 'react'
+import { useNavigate } from 'react-router-dom'
+import { Navbar as BaseNavbar } from 'decentraland-dapps/dist/containers'
+import { locations } from '../../modules/routing/locations'
+import UserMenu from '../UserMenu'
+import { Props } from './Navbar.types'
+import './Navbar.css'
+
+const Navbar = (props: Props) => {
+ const { isConnected } = props
+ const { pathname, search } = location
+ const navigate = useNavigate()
+
+ if (isConnected) {
+ props = { ...props, rightMenu: }
+ }
+
+ const handleOnSignIn = useCallback(() => {
+ const searchParams = new URLSearchParams(search)
+ const currentRedirectTo = searchParams.get('redirectTo')
+ const redirectTo = !currentRedirectTo ? `${pathname}${search}` : currentRedirectTo
+ navigate(locations.signIn(redirectTo))
+ }, [navigate, pathname, search])
+
+ return
+}
+
+export default Navbar
diff --git a/src/components/Navbar/Navbar.types.ts b/src/components/Navbar/Navbar.types.ts
new file mode 100644
index 0000000..c075fb6
--- /dev/null
+++ b/src/components/Navbar/Navbar.types.ts
@@ -0,0 +1,7 @@
+import { NavbarProps } from 'decentraland-ui/dist/components/Navbar/Navbar'
+
+export type Props = Partial & {
+ isConnected: boolean
+}
+
+export type MapStateProps = Pick
diff --git a/src/components/Navbar/index.ts b/src/components/Navbar/index.ts
new file mode 100644
index 0000000..464b90b
--- /dev/null
+++ b/src/components/Navbar/index.ts
@@ -0,0 +1 @@
+export { default } from './Navbar.container'
diff --git a/src/components/PageLayout/PageLayout.module.css b/src/components/PageLayout/PageLayout.module.css
index 8dd0336..f011e08 100644
--- a/src/components/PageLayout/PageLayout.module.css
+++ b/src/components/PageLayout/PageLayout.module.css
@@ -15,6 +15,7 @@
.navbar {
flex-shrink: 0;
+ background-color: var(--background);
}
@media (max-width: 767px) {
diff --git a/src/components/PageLayout/PageLayout.tsx b/src/components/PageLayout/PageLayout.tsx
index 1a3a0de..e5a253f 100644
--- a/src/components/PageLayout/PageLayout.tsx
+++ b/src/components/PageLayout/PageLayout.tsx
@@ -1,11 +1,13 @@
import React from 'react'
import classNames from 'classnames'
+import Navbar from '../Navbar'
import { Props } from './PageLayout.types'
import styles from './PageLayout.module.css'
const PageLayout = ({ children, className }: Props) => {
return (
)
diff --git a/src/components/UserMenu/UserMenu.container.ts b/src/components/UserMenu/UserMenu.container.ts
new file mode 100644
index 0000000..4ad8df9
--- /dev/null
+++ b/src/components/UserMenu/UserMenu.container.ts
@@ -0,0 +1,48 @@
+import { connect } from 'react-redux'
+import { Network } from '@dcl/schemas/dist/dapps/network'
+import { getData as getProfiles } from 'decentraland-dapps/dist/modules/profile/selectors'
+import { isEnabled } from 'decentraland-dapps/dist/modules/translation/selectors'
+import { disconnectWallet } from 'decentraland-dapps/dist/modules/wallet/actions'
+import { getAddress, getNetworks, isConnected, isConnecting } from 'decentraland-dapps/dist/modules/wallet/selectors'
+import { UserMenu } from 'decentraland-ui/dist/components/UserMenu/UserMenu'
+import { RootState } from '../../modules/reducer'
+import { MapStateProps, MapDispatch, MapDispatchProps, Props } from './UserMenu.types'
+
+const mapState = (state: RootState): MapStateProps => {
+ const isSignedIn = isConnected(state)
+ const address = getAddress(state)
+ const profile = address ? getProfiles(state)[address] : undefined
+ const networks = getNetworks(state)
+
+ const manaBalances: Props['manaBalances'] = {}
+ if (isSignedIn) {
+ const networkList = Object.values(Network) as Network[]
+ for (const network of networkList) {
+ const networkData = networks?.[network]
+ if (networkData) {
+ manaBalances[network] = networks?.[network].mana
+ }
+ }
+ }
+
+ return {
+ address,
+ manaBalances,
+ avatar: profile ? profile.avatars[0] : undefined,
+ isSignedIn,
+ isSigningIn: isConnecting(state),
+ hasActivity: false,
+ hasTranslations: isEnabled(state)
+ }
+}
+
+const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({
+ onSignOut: () => dispatch(disconnectWallet())
+})
+
+const mergeProps = (mapStateProps: MapStateProps, mapDispatchProps: MapDispatchProps) => ({
+ ...mapStateProps,
+ ...mapDispatchProps
+})
+
+export default connect(mapState, mapDispatch, mergeProps)(UserMenu)
diff --git a/src/components/UserMenu/UserMenu.types.ts b/src/components/UserMenu/UserMenu.types.ts
new file mode 100644
index 0000000..4ecc8ee
--- /dev/null
+++ b/src/components/UserMenu/UserMenu.types.ts
@@ -0,0 +1,12 @@
+import { Dispatch } from '@reduxjs/toolkit'
+import { ConnectWalletRequestAction, DisconnectWalletAction } from 'decentraland-dapps/dist/modules/wallet/actions'
+import { UserMenuProps } from 'decentraland-ui/dist/components/UserMenu/UserMenu'
+
+export type Props = UserMenuProps & { hasTranslations: boolean }
+
+export type MapStateProps = Pick<
+ Props,
+ 'isSignedIn' | 'isSigningIn' | 'address' | 'avatar' | 'manaBalances' | 'hasActivity' | 'hasTranslations'
+>
+export type MapDispatchProps = Pick
+export type MapDispatch = Dispatch
diff --git a/src/components/UserMenu/index.ts b/src/components/UserMenu/index.ts
new file mode 100644
index 0000000..501cf7c
--- /dev/null
+++ b/src/components/UserMenu/index.ts
@@ -0,0 +1 @@
+export { default } from './UserMenu.container'
diff --git a/vite.config.ts b/vite.config.ts
index 5c83c47..3ebf6d8 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -45,6 +45,6 @@ export default defineConfig(({ command, mode }) => {
}
}
}
- : undefined)
+ : { server: { open: true } })
}
})