Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Fix header component - Closes #506 #542

Merged
merged 4 commits into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/account/accountComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ import { getAccountStatus } from '../../utils/api/account';
* @param {object} props - include properties of component
*/
class AccountComponent extends React.Component {
constructor(props) {
super(props);
this.update = this.update.bind(this);
}
componentDidMount() {
this.update();
document.addEventListener('beat', this.update.bind(this));
document.addEventListener('beat', this.update);
}

componentWillUnmount() {
document.removeEventListener('beat', this.update);
}

update() {
Expand Down
4 changes: 4 additions & 0 deletions src/components/header/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
.material-icons{
font-size: 24px !important;
}

.menu {
right: -16px !important;
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be less (maybe right: -8px !important;) and the put the rest on .wrapper.
.wrapper has too much space on the right compared to nano 1.0.0 and not enough at the bottom.

I mean something like this is missing

.wrapper {
  margin-right: -8px;
  margin-bottom: 16px;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

menu is a theme param, and it passes to the component and merges with other styles. it is so hard to style Menu component through IconMenu component.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This is still an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do i need to fix it in other pr?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please.

}
69 changes: 36 additions & 33 deletions src/components/header/headerElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,47 @@ import styles from './header.css';
import VerifyMessage from '../signVerify/verifyMessage';
import SignMessage from '../signVerify/signMessage';
import Send from '../send';
import PrivateWrapper from '../privateWrapper';

const HeaderElement = props => (
<header className={styles.wrapper}>
<img className={styles.logo} src={logo} alt="logo" />
<IconMenu
className={`${styles.iconButton} main-menu-icon-button`}
icon="more_vert"
position="topRight"
menuRipple
theme={styles}
>
<MenuItem caption="Register second passphrase" />
<MenuItem caption="Register as delegate" />
<MenuItem caption="Sign message"
className='sign-message'
<PrivateWrapper>
<IconMenu
className={`${styles.iconButton} main-menu-icon-button`}
icon="more_vert"
position="topRight"
menuRipple
theme={styles}
>
<MenuItem caption="Register second passphrase" />
<MenuItem caption="Register as delegate" />
<MenuItem caption="Sign message"
className='sign-message'
onClick={() => props.setActiveDialog({
title: 'Sign message',
childComponentProps: {
account: props.account,
},
childComponent: SignMessage,
})}
/>
<MenuItem caption="Verify message"
className='verify-message'
onClick={() => props.setActiveDialog({
title: 'Verify message',
childComponent: VerifyMessage,
})}
/>
</IconMenu>
<Button className={`${styles.button} logout-button`} raised onClick={props.logOut}>logout</Button>
<Button className={`${styles.button} send-button`}
raised primary
onClick={() => props.setActiveDialog({
title: 'Sign message',
childComponentProps: {
account: props.account,
},
childComponent: SignMessage,
})}
/>
<MenuItem caption="Verify message"
className='verify-message'
onClick={() => props.setActiveDialog({
title: 'Verify message',
childComponent: VerifyMessage,
})}
/>
</IconMenu>
<Button className={`${styles.button} logout-button`} raised>logout</Button>
<Button className={`${styles.button} send-button`}
raised primary
onClick={() => props.setActiveDialog({
title: 'Send',
childComponent: Send,
})}>Send</Button>
title: 'Send',
childComponent: Send,
})}>Send</Button>
</PrivateWrapper>
</header>
);

Expand Down
2 changes: 2 additions & 0 deletions src/components/header/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { connect } from 'react-redux';
import { dialogDisplayed } from '../../actions/dialog';
import { accountLoggedOut } from '../../actions/account';
import HeaderElement from './headerElement';

const mapStateToProps = state => ({
Expand All @@ -8,6 +9,7 @@ const mapStateToProps = state => ({

const mapDispatchToProps = dispatch => ({
setActiveDialog: data => dispatch(dialogDisplayed(data)),
logOut: () => dispatch(accountLoggedOut()),
});

const Header = connect(
Expand Down
12 changes: 12 additions & 0 deletions src/components/privateWrapper/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { connect } from 'react-redux';

export const PrivateWrapperComponent = ({ isAuthenticated, children }) => (
isAuthenticated && <span>{ children }</ span>
);

const mapStateToProps = state => ({
isAuthenticated: !!state.account.publicKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be something else then publicKey because now it shows the haeder right when I click the "Login" button, but it should only after the server request is finished and it is redirected from login page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently, all private routes look to the same params.

Copy link
Contributor

@slaweet slaweet Aug 1, 2017

Choose a reason for hiding this comment

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

In private routes, it makes no user-visible difference. But on the login page if user is on slower network, it can longer time for the request and only then user is redirected from login page. Logout and Send buttons should not be on login page in the meantime.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was fixed in the meantime by some other changes.

});

export default connect(mapStateToProps)(PrivateWrapperComponent);
25 changes: 25 additions & 0 deletions src/components/privateWrapper/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import { PrivateWrapperComponent } from '.';

const Private = () => <h1>Private</h1>;

describe('PrivateWrapperComponent', () => {
const isAuth = isAuthenticated => (
shallow(
<PrivateWrapperComponent isAuthenticated={isAuthenticated}>
<Private/ >
</PrivateWrapperComponent>,
)
);
it('should render children components if user is authenticated', () => {
const wrapper = isAuth(true);
expect(wrapper.find(Private)).to.have.length(1);
});

it('should do not render children components if user is not authenticated', () => {
const wrapper = isAuth(false);
expect(wrapper.find(Private)).to.have.length(0);
});
});
2 changes: 1 addition & 1 deletion src/components/transactions/transactionsComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Transactions extends React.Component {
length: parseInt(res.count, 10),
});
})
.catch(error => console.error(error.message));
.catch(error => console.error(error.message)); //eslint-disable-line
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that finally somebody got annoyed enough by the warning in console :-) Though I would prefer to disable the specific rule. In this case a believe it is //eslint-disable-line no-console

}
}

Expand Down