Skip to content

Commit 9b4a582

Browse files
committed
Merge branch 'feature/534-settings-page' of github.com:material-components/material-design-for-wordpress into feature/534-settings-page
2 parents ee3b659 + b57278c commit 9b4a582

File tree

63 files changed

+2407
-306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2407
-306
lines changed

plugin/assets/css/src/block-editor.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@
5757
width: 100%;
5858
}
5959

60+
.block-editor-block-list__block .material-design-block-handpicked-posts__types__list .components-radio-control__option {
61+
display: inline-block;
62+
63+
& label {
64+
margin-right: 8px;
65+
}
66+
}
67+
6068
.mdc-image-list--with-text-protection .mdc-image-list__supporting {
6169
align-items: start;
6270
height: auto;

plugin/assets/css/src/settings/api.css

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/**
2-
* Copyright 2021 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
.material-settings__api {
182
padding-left: 0;
193
padding-right: 0;
Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/**
2-
* Copyright 2021 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
.material-settings__cell--justify-end {
182
justify-self: flex-end;
193
}

plugin/assets/css/src/settings/index.css

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/**
2-
* Copyright 2021 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
@import "./base.css";
182
@import "./updater.css";
193
@import "./switch.css";

plugin/assets/css/src/settings/switch.css

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/**
2-
* Copyright 2021 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
.material-settings__switch {
182
align-items: center;
193
display: flex;
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
/**
2-
* Copyright 2021 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
.material-settings__updater {
182
background-color: var(--material-design-settings-background-color);
193
border-radius: 8px;
204
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
215
margin-bottom: 15px;
6+
7+
& .material-settings__message {
8+
align-items: center;
9+
color: var(--material-design-settings-error-color);
10+
display: flex;
11+
}
12+
13+
& .material-settings__message-text {
14+
font-size: 16px;
15+
font-weight: 500;
16+
margin-left: 10px;
17+
}
2218
}

plugin/assets/src/block-editor/blocks/common-posts-list/components/single-post.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
/**
18+
* External dependencies
19+
*/
20+
import { get } from 'lodash';
21+
1722
/**
1823
* WordPress dependencies
1924
*/
@@ -36,8 +41,12 @@ import HorizontalCardLayout from './horizontal-card-layout';
3641
* @return {Function} A functional component.
3742
*/
3843
const SinglePost = ( { post, style, attributes } ) => {
39-
const titleTrimmed = post.title.rendered.trim();
40-
let excerpt = post.excerpt.rendered;
44+
const titleTrimmed = get( post, [ 'title', 'rendered' ], '' ).trim();
45+
let excerpt = get( post, [ 'excerpt', 'rendered' ], '' );
46+
47+
if ( ! excerpt ) {
48+
excerpt = get( post, [ 'content', 'rendered' ], '' );
49+
}
4150

4251
const excerptElement = document.createElement( 'div' );
4352
excerptElement.innerHTML = excerpt;
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/**
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* External dependencies
19+
*/
20+
import { get, isUndefined, pickBy } from 'lodash';
21+
22+
/**
23+
* WordPress dependencies
24+
*/
25+
import { createHigherOrderComponent } from '@wordpress/compose';
26+
import { withSelect } from '@wordpress/data';
27+
import { useEffect, useState } from '@wordpress/element';
28+
29+
/**
30+
* Internal dependencies
31+
*/
32+
import './style.css';
33+
import NoPosts from './components/no-posts';
34+
import PostsList from './components/posts-list';
35+
import { getPosts } from '../../utils/api';
36+
37+
/**
38+
* Edit component.
39+
*
40+
* @param {Object} props - Component props.
41+
*
42+
* @return {Function} A functional component.
43+
*/
44+
const Edit = props => {
45+
const { postsToDisplay } = props;
46+
const hasPosts = Array.isArray( postsToDisplay ) && postsToDisplay.length;
47+
48+
if ( ! hasPosts ) {
49+
return <NoPosts { ...props } />;
50+
}
51+
52+
return <PostsList { ...props } />;
53+
};
54+
55+
/**
56+
* @type {Function} A functional component.
57+
*/
58+
const EditWithSelect = withSelect( ( select, props ) => {
59+
const {
60+
category,
61+
postsToShow,
62+
posts,
63+
orderby,
64+
displayFeaturedImage,
65+
style,
66+
} = props.attributes;
67+
const { name } = props;
68+
let { fetchedPosts } = props;
69+
70+
const featuredImageSizeSlug = style === 'list' ? 'medium' : 'large';
71+
72+
const { getEntityRecords, getMedia } = select( 'core' );
73+
74+
let queryArgs = {
75+
categories: category,
76+
per_page: postsToShow,
77+
};
78+
79+
if ( name === 'material/hand-picked-posts' ) {
80+
queryArgs = {
81+
include: posts.map( Number ),
82+
per_page: posts.length,
83+
orderby: 'date',
84+
order: 'desc',
85+
};
86+
87+
if ( orderby ) {
88+
if ( orderby === 'title' ) {
89+
queryArgs.orderby = 'title';
90+
queryArgs.order = 'asc';
91+
} else if ( orderby === 'popularity' ) {
92+
queryArgs.orderby = 'comment_count';
93+
queryArgs.order = 'desc';
94+
}
95+
}
96+
}
97+
98+
const fetchedPostsQuery = pickBy(
99+
queryArgs,
100+
value => ! isUndefined( value )
101+
);
102+
103+
fetchedPosts = Array.isArray( fetchedPosts )
104+
? fetchedPosts
105+
: getEntityRecords( 'postType', 'post', fetchedPostsQuery );
106+
107+
return {
108+
postsToDisplay: ! Array.isArray( fetchedPosts )
109+
? fetchedPosts
110+
: fetchedPosts.map( post => {
111+
if ( displayFeaturedImage && post.featured_media ) {
112+
const image = getMedia( post.featured_media );
113+
let url = get(
114+
image,
115+
[ 'media_details', 'sizes', featuredImageSizeSlug, 'source_url' ],
116+
null
117+
);
118+
if ( ! url ) {
119+
url = get( image, 'source_url', null );
120+
}
121+
return { ...post, featuredImageSourceUrl: url };
122+
}
123+
return post;
124+
} ),
125+
};
126+
} )( Edit );
127+
128+
export default EditWithSelect;
129+
130+
const withGetPosts = createHigherOrderComponent( WrappedComponent => {
131+
return props => {
132+
const { category, posts, orderby, postType } = props.attributes;
133+
134+
const queryArgs = {
135+
categories: category,
136+
include: posts.map( Number ),
137+
per_page: posts.length,
138+
orderby: 'date',
139+
order: 'desc',
140+
};
141+
142+
if ( orderby ) {
143+
if ( orderby === 'title' ) {
144+
queryArgs.orderby = 'title';
145+
queryArgs.order = 'asc';
146+
} else if ( orderby === 'popularity' ) {
147+
queryArgs.orderby = 'comment_count';
148+
queryArgs.order = 'desc';
149+
}
150+
}
151+
152+
const [ postsToDisplay, setPostsToDisplay ] = useState( [] );
153+
154+
useEffect( () => {
155+
getPosts( { selected: posts, postType, queryArgs } )
156+
.then( data => {
157+
setPostsToDisplay( data );
158+
} )
159+
.catch( e => {
160+
console.error( e );
161+
} );
162+
}, [] ); // eslint-disable-line react-hooks/exhaustive-deps
163+
164+
return <WrappedComponent { ...props } fetchedPosts={ postsToDisplay } />;
165+
};
166+
}, 'withGetPosts' );
167+
168+
export const EditWithGetPosts = withGetPosts( EditWithSelect );

plugin/assets/src/block-editor/blocks/common-posts-list/style.css

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@
1919
padding: 16px;
2020
}
2121

22-
.single-post-card .mdc-button__label {
23-
white-space: nowrap;
22+
.single-post-card {
23+
24+
& .mdc-card__action--button {
25+
text-transform: none;
26+
}
27+
28+
& .mdc-button__label {
29+
white-space: nowrap;
30+
}
2431
}
2532

2633
/* @todo: Will need refactoring. */
@@ -36,12 +43,15 @@
3643

3744
.single-post-card__secondary {
3845
padding: 0 16px 8px 16px;
46+
47+
& > p {
48+
margin: 0;
49+
}
3950
}
4051

41-
/* @todo: Will need refactoring. */
4252
.single-post-card__secondary-text-over-media,
4353
.single-post-card__secondary-text-above-media {
44-
padding-top: 1em !important;
54+
padding-top: 16px;
4555
}
4656

4757
.single-post-card__media.mdc-card__media--square {

plugin/assets/src/block-editor/blocks/hand-picked-posts/block.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
"preview": {
8181
"type": "boolean",
8282
"default": false
83+
},
84+
"postType": {
85+
"type": "string",
86+
"default": "posts-pages"
8387
}
8488
},
8589
"supports": {
@@ -88,4 +92,4 @@
8892
"full"
8993
]
9094
}
91-
}
95+
}

0 commit comments

Comments
 (0)