Skip to content

Commit

Permalink
Fix anontools in header, convert it to functional (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh authored Sep 22, 2023
1 parent 052284b commit 381ce6f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 90 deletions.
4 changes: 2 additions & 2 deletions dockerfiles/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ services:
volumes:
- ${CURRENT_DIR}:/app/src/addons/${ADDON_PATH}/
environment:
# RAZZLE_INTERNAL_API_PATH: http://backend:8080/Plone
RAZZLE_INTERNAL_API_PATH: http://backend:8080/Plone
# In case that you want to connect to and outside (non-docker) local instance
# coment the above, use the next line
RAZZLE_INTERNAL_API_PATH: http://host.docker.internal:8080/Plone
# RAZZLE_INTERNAL_API_PATH: http://host.docker.internal:8080/Plone
RAZZLE_API_PATH: http://127.0.0.1:8080/Plone
HOST: 0.0.0.0
depends_on:
Expand Down
1 change: 1 addition & 0 deletions news/236.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix anontools in header, convert it to functional @sneridagh
114 changes: 44 additions & 70 deletions src/components/Anontools/Anontools.jsx
Original file line number Diff line number Diff line change
@@ -1,79 +1,53 @@
// SemanticUI-free pre-@plone/components
// Refactor when https://github.com/plone/volto/pull/4845 is merged
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { FormattedMessage } from 'react-intl';
import { flattenToAppURL } from '@plone/volto/helpers';
import config from '@plone/volto/registry';
import { useSelector, shallowEqual } from 'react-redux';

/**
* Anontools container class.
*/
export class Anontools extends Component {
/**
* Property types.
* @property {Object} propTypes Property types.
* @static
*/
static propTypes = {
token: PropTypes.string,
content: PropTypes.shape({
'@id': PropTypes.string,
}),
};
const Anontools = () => {
const token = useSelector((state) => state.userSession.token, shallowEqual);
const content = useSelector((state) => state.content.data, shallowEqual);

/**
* Default properties.
* @property {Object} defaultProps Default properties.
* @static
*/
static defaultProps = {
token: null,
content: {
'@id': null,
},
};
const { settings } = config;

/**
* Render method.
* @method render
* @returns {string} Markup for the component.
*/
render() {
const { settings } = config;
return (
!this.props.token && (
<div className="anontools">
{settings.showSelfRegistration && (
<div>
<Link aria-label="register" to="/register">
<FormattedMessage id="Register" defaultMessage="Register" />
</Link>
</div>
)}
<div>
<Link
aria-label="login"
to={`/login${
this.props.content?.['@id']
? `?return_url=${this.props.content['@id'].replace(
settings.apiPath,
'',
)}`
: ''
}`}
>
<FormattedMessage id="Log in" defaultMessage="Log in" />
</Link>
</div>
</div>
)
);
}
}
return (
!token && (
<div className="anontools">
{settings.showSelfRegistration && (
<Link aria-label="register" to="/register">
<FormattedMessage id="Register" defaultMessage="Register" />
</Link>
)}

export default connect((state) => ({
token: state.userSession.token,
content: state.content.data,
}))(Anontools);
<Link
aria-label="login"
to={`/login${
content?.['@id']
? `?return_url=${flattenToAppURL(content['@id'])}`
: ''
}`}
>
<FormattedMessage id="Log in" defaultMessage="Log in" />
</Link>
</div>
)
);
};

export default Anontools;

Anontools.propTypes = {
token: PropTypes.string,
content: PropTypes.shape({
'@id': PropTypes.string,
}),
};

Anontools.defaultProps = {
token: null,
content: {
'@id': null,
},
};
19 changes: 7 additions & 12 deletions src/theme/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
.language-selector a {
text-transform: uppercase;
}
.tools {
display: flex;
}

.tools a {
margin-right: 10px;
Expand All @@ -224,26 +227,18 @@
font-size: 14px;
}

// .tools a:last-child:after {
// padding-right: 5px;
// padding-left: 5px;
// content: '';
// }

.tools .anontools {
display: flex;
margin-right: 10px;

a {
margin-right: 0;
margin-right: 10px;
color: $black;
}

> div {
&:first-of-type::after {
content: '|';
font-size: 1rem;
}
&:after {
content: '|';
font-size: 14px;
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/theme/_typo-custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,15 @@ h1.documentFirstHeading {
line-height: 48px;
}

.block-editor-heading {
.block .heading-wrapper {
margin-right: 0 !important;
margin-left: 0 !important;
}
}
// Sept2023 - @sneridagh: removing this, since it's breaking
// the layout in edit view. Can't say why it was here in the
// first place, we'll see if it breaks in another place after it.
// .block-editor-heading {
// .block .heading-wrapper {
// margin-right: 0 !important;
// margin-left: 0 !important;
// }
// }

// Slate headings
h2 {
Expand Down

0 comments on commit 381ce6f

Please sign in to comment.