Skip to content

Commit

Permalink
Merge 895374b into 33345a9
Browse files Browse the repository at this point in the history
  • Loading branch information
sohkai committed Sep 2, 2019
2 parents 33345a9 + 895374b commit 1555289
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
12 changes: 0 additions & 12 deletions packages/aragon-api-react/README.md
Expand Up @@ -216,14 +216,6 @@ function App() {
}
```

#### `displayMenuButton`

Whether or not to display the menu button (`Boolean`), depending on it being automatically hidden or not in the client.

#### `requestMenu()`

Call this function to display the Aragon menu, when hidden automatically. This should be called when the user clicks on the menu button.

### useApi()

This Hook returns the same data as the `api` entry from the `useAragonApi()` hook.
Expand All @@ -240,10 +232,6 @@ This Hook returns the same data as the `connectedAccount` entry from the `useAra

This Hook returns the same data as the `installedApps` entry from the `useAragonApi()` hook.

### useMenuButton()

This Hook returns an array containing the `displayMenuButton` and the `requestMenu` entries from the `useAragonApi()` hook, in that order.

### useNetwork()

This Hook returns the same data as the `network` entry from the `useAragonApi()` hook.
Expand Down
42 changes: 29 additions & 13 deletions packages/aragon-api-react/src/index.js
Expand Up @@ -7,12 +7,21 @@ import {
} from 'react'
import Aragon, { providers } from '@aragon/api'

const warn = (...params) => {
// Warn in dev mode only
if (process.env.NODE_ENV === 'development') {
console.warn(...params)
}
}

const postMessage = (name, value) => {
window.parent.postMessage({ from: 'app', name, value }, '*')
}

const requestMenu = () => {
postMessage('requestMenu', true)
warn(
'api-react: "requestMenu" is deprecated and is a noop. It can safely be removed from your codebase.'
)
}

const AragonApiContext = createContext()
Expand All @@ -28,7 +37,6 @@ function AragonApi({
const [currentApp, setCurrentApp] = useState(null)
const [installedApps, setInstalledApps] = useState([])
const [network, setNetwork] = useState(null)
const [displayMenuButton, setDisplayMenuButton] = useState(false)
const [path, setPath] = useState('/')
const [requestPath, setRequestPath] = useState(null)

Expand Down Expand Up @@ -63,10 +71,6 @@ function AragonApi({
return
}

if (data.name === 'displayMenuButton') {
setDisplayMenuButton(data.value)
}

if (data.name === 'ready') {
subscribers = [
// app state
Expand Down Expand Up @@ -122,12 +126,14 @@ function AragonApi({
currentApp,
installedApps,
network,
displayMenuButton,
path,
requestPath,

// reducer(null) is called to get the initial state
appState: appState === null ? reducer(null) : appState,

// Deprecated
displayMenuButton: false,
},
},
children
Expand All @@ -150,8 +156,10 @@ function getAragonApiData(hookName) {

const useAragonApi = () => ({
...getAragonApiData('useAragonApi()'),
requestMenu,
_sendMessage: postMessage,

// Deprecated
requestMenu,
})

// direct access hooks
Expand All @@ -161,16 +169,22 @@ const useConnectedAccount = () =>
getAragonApiData('useConnectedAccount()').connectedAccount
const useCurrentApp = () => getAragonApiData('useCurrentApp()').currentApp
const useInstalledApps = () => getAragonApiData('useInstalledApps()').installedApps
const useMenuButton = () => [
getAragonApiData('useMenuButton()').displayMenuButton,
requestMenu,
]
const useNetwork = () => getAragonApiData('useNetwork()').network
const usePath = () => {
const { path, requestPath } = getAragonApiData('usePath()')
return [path, requestPath]
}

// Deprecated
const useMenuButton = () => {
warn('api-react: "useMenuButton" is deprecated. It can safely be removed from your codebase.')

return [
getAragonApiData('useMenuButton()').displayMenuButton,
requestMenu,
]
}

export {
AragonApi,
AragonApiContext as _AragonApiContext,
Expand All @@ -180,7 +194,9 @@ export {
useConnectedAccount,
useCurrentApp,
useInstalledApps,
useMenuButton,
useNetwork,
usePath,

// Deprecated
useMenuButton,
}

0 comments on commit 1555289

Please sign in to comment.