Commit 9c73de40 authored by Jure's avatar Jure

feat: simplify ConnectedNavigation

parent ef60a27b
Pipeline #12089 failed with stages
in 7 minutes and 41 seconds
import React from 'react'
import { get } from 'lodash'
import { adopt } from 'react-adopt'
import CurrentUserQuery from './queries/currentUser'
import { Query, ApolloConsumer } from 'react-apollo'
import gql from 'graphql-tag'
import Navigation from './Navigation'
const mapper = { CurrentUserQuery }
const mapProps = args => ({
currentUser: get(args.CurrentUserQuery, 'data.currentUser'),
loading: args.CurrentUserQuery.loading,
client: args.CurrentUserQuery.client,
})
const Composed = adopt(mapper, mapProps)
const CURRENT_USER = gql`
query CurrentUser {
currentUser {
id
username
admin
}
}
`
const ConnectedNavigation = props => (
<Composed>
{({ loading, currentUser, client }) => {
<Query query={CURRENT_USER}>
{({ loading, error, data }) => {
if (loading) return 'Loading...'
return (
<Navigation
client={client}
currentUser={currentUser}
loading={loading}
{...props}
/>
<ApolloConsumer>
{client => (
<Navigation
client={client}
currentUser={data.currentUser}
loading={loading}
{...props}
/>
)}
</ApolloConsumer>
)
}}
</Composed>
</Query>
)
export default ConnectedNavigation
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment