Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

fix: don't break the page structure while loading data for the headerbar #7

Merged
merged 3 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/HeaderBar/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const Notifications = ({ interpretations, messages }) => (

<style jsx>{`
div {
margin-left: auto;
user-select: none;
display: flex;
flex-direction: row;
Expand Down
39 changes: 25 additions & 14 deletions src/HeaderBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,35 @@ export const HeaderBar = ({ appName, className }) => {
},
})

if (loading) return <span>...</span>

if (error) return <span>{`ERROR: ${error.message}`}</span>

const locale = data.user.settings.keyUiLocale || 'en'
i18n.changeLanguage(locale)
if (!loading) {
// TODO: This will run every render which is probably wrong! Also, setting the global locale shouldn't be done in the headerbar
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be in headerbar I don't think....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I forgot to remove this after implementing i18n. It should be moved to the Storybook part since it simulates the App role.

Copy link
Member Author

@amcgee amcgee May 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do that in another PR then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just leave it as it is with the TODO and we can do it in a different PR.

const locale = data.user.settings.keyUiLocale || 'en'
i18n.changeLanguage(locale)
}

return (
<header className={className}>
<Logo />

<Title app={appName} instance={data.systemInfo.systemName} />

<Notifications
interpretations={data.notifications.unreadInterpretations}
messages={data.notifications.unreadMessageConversations}
/>

<Apps apps={data.apps.modules} />

<Profile user={data.user} />
{!loading && (
<>
<Title
app={appName}
instance={data.systemInfo.systemName}
/>
<div className="right-control-spacer" />
<Notifications
interpretations={
data.notifications.unreadInterpretations
}
messages={data.notifications.unreadMessageConversations}
/>
<Apps apps={data.apps.modules} />
<Profile user={data.user} />
</>
)}

<style jsx>{`
header {
Expand All @@ -67,6 +75,9 @@ export const HeaderBar = ({ appName, className }) => {
border-bottom: 1px solid rgba(32, 32, 32, 0.15);
color: ${colors.white};
}
.right-control-spacer {
margin-left: auto;
}
`}</style>
</header>
)
Expand Down
16 changes: 11 additions & 5 deletions stories/HeaderBar.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ const customData = {
},
}

storiesOf('HeaderBar', module).add('Default', () => (
<CustomDataProvider data={customData}>
<HeaderBar appName="Example!" />
</CustomDataProvider>
))
storiesOf('HeaderBar', module)
.add('Default', () => (
<CustomDataProvider data={customData}>
<HeaderBar appName="Example!" />
</CustomDataProvider>
))
.add('Loading...', () => (
<CustomDataProvider options={{ loadForever: true }}>
<HeaderBar appName="Example!" />
</CustomDataProvider>
))