Commit 9bd4854d authored by Matija Obreza's avatar Matija Obreza

Merge branch '279-activitypost-url-incorrect'

* 279-activitypost-url-incorrect:
  ActivityPost URL incorrect
parents 35cace83 cd0f92eb
......@@ -58,14 +58,13 @@ class ActivityPostDisplayPage extends React.Component<IActivityPostDisplayPage>
public render() {
const { lastNews, activityPost } = this.props;
const title = activityPost &&
activityPost.title.split(/<.*?>/).filter((el) => !!el).join('');
const title = activityPost && ActivityPost.htmlTitleToText(activityPost);
const lastNewsMenu = new Menu();
if (lastNews) {
lastNewsMenu.items = lastNews.map((lastNewsItem) => {
const newsMenuItem = new MenuItem();
newsMenuItem.id = lastNewsItem.id;
newsMenuItem.text = lastNewsItem.title.split(/<.*?>/).filter((el) => !!el).join('');
newsMenuItem.text = ActivityPost.htmlTitleToText(lastNewsItem, {replacer: ' '});
newsMenuItem.url = `/content/news/${newsMenuItem.id}/${
newsMenuItem.text.toLowerCase().replace(/\s/g, '-')
}`;
......@@ -79,7 +78,7 @@ class ActivityPostDisplayPage extends React.Component<IActivityPostDisplayPage>
) : (
<Grid container style={ {height: '100%'} }>
<PageTitle title={ title }/>
<ContentHeader title={ title }/>
<ContentHeader title={ <span dangerouslySetInnerHTML={ {__html: activityPost.title} }/> }/>
<ArticleSection title={ title } body={ activityPost.body }/>
<MenuStepper menu={ lastNewsMenu }/>
</Grid>
......
......@@ -27,7 +27,9 @@ class ActivityPostBrowsePage extends BrowsePageTemplate<ActivityPost> {
}
public render() {
const { paged, loadMoreData, error, loading, t } = this.props;
const {apiCall, loadMoreData, t } = this.props;
const {data: paged, loading, error} = apiCall || {data: undefined, loading: true, error: undefined};
const renderActivityPost = (post: ActivityPost, index: number) => {
return <div key={ index }><ActivityPostCard key={ index } index={ index } post={ post } compact/></div>;
......@@ -67,9 +69,7 @@ class ActivityPostBrowsePage extends BrowsePageTemplate<ActivityPost> {
}
const mapStateToProps = (state, ownProps) => ({
paged: state.cms.public.activityPost.paged ? state.cms.public.activityPost.paged.data : undefined,
loading: state.cms.public.activityPost.paged ? state.cms.public.activityPost.paged.loading : false,
error: state.cms.public.activityPost.paged ? state.cms.public.activityPost.paged.error : undefined,
apiCall: state.cms.public.activityPost.paged,
filterCode: ownProps.match.params.filterCode,
});
......
......@@ -52,12 +52,7 @@ const style = (theme) => ({
});
const ActivityPostCard = ({classes, className, post, compact, edit, t, ...gridSizes}: { post: ActivityPost, compact?: false, edit?: false, classes?: any, className?: string, t: any, gridSizes: IGridSizes }) => {
const urlTitle = post.title && post.title
.split(/<.*?>/)
.filter((el) => !!el)
.join('')
.toLowerCase()
.replace(/\s/g, '-');
const urlTitle = ActivityPost.htmlTitleToText(post);
return (
<Grid item { ...gridSizes }>
......
......@@ -43,6 +43,16 @@ class ActivityPost {
direction: SortDirection.ASC,
},
};
public static htmlTitleToText = (activityPost: ActivityPost, config: { length?: number, replacer?: string, lowerCase?: boolean } = {length: 60, replacer: '-', lowerCase: true}) => {
const textTitle = activityPost.title
.replace(/<.*?>/g, '')
.slice(0, config.length)
.replace(/[^\w]+/g, config.replacer)
.replace(`${ config.replacer }+$`, '');
return config.lowerCase ? textTitle.toLocaleLowerCase() : textTitle;
}
}
export default ActivityPost;
......@@ -23,11 +23,11 @@ class ContentHeader extends React.Component<IContentHeader , any> {
<Grid container spacing={ 0 } className={ `back-green pt-10 pb-10 pl-20 pr-20` }>
<Grid item xs={ 12 }>
<h1 className="font-bold white mb-5" style={ { marginBottom: 0, fontSize: '1.714rem'} }>
{ t(title) }
{ typeof title === 'string' ? t(title) : title }
</h1>
<Hidden implementation="css" smDown>
<h3 className="font-medium white m-0" style={ { marginTop: '.5rem', fontSize: '0.8571rem' } }>
{ t(subTitle) }
{ typeof subTitle === 'string' ? t(subTitle) : subTitle }
</h3>
</Hidden>
</Grid>
......
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