Skip to content

Commit

Permalink
Merge pull request #430 from greenpeace/less-libs
Browse files Browse the repository at this point in the history
Less libs
  • Loading branch information
Inwerpsel authored Nov 24, 2020
2 parents 4537018 + 8a1f648 commit 07f7aa5
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 23 deletions.
12 changes: 5 additions & 7 deletions assets/src/blocks/Articles/ArticlePreview.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Component } from '@wordpress/element';
import { dateI18n } from '@wordpress/date';
import { unescape } from '../../functions/unescape';
const { __ } = wp.i18n;

export class ArticlePreview extends Component {
constructor(props) {
Expand Down Expand Up @@ -100,7 +98,7 @@ export class ArticlePreview extends Component {
page_type_link,
post_title,
post_excerpt,
post_date
date_formatted,
}
} = this.props;

Expand Down Expand Up @@ -149,10 +147,10 @@ export class ArticlePreview extends Component {
}
<p className="article-list-item-meta">
{this.getAuthorLink()}
{post_date &&
<time className="article-list-item-date" dateTime="">
{dateI18n(window.p4bk_vars.dateFormat, post_date)}
</time>
{date_formatted &&
<time className="article-list-item-date" dateTime="">
{date_formatted}
</time>
}
</p>
</header>
Expand Down
7 changes: 4 additions & 3 deletions assets/src/blocks/Articles/useArticlesFetch.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState, useEffect } from '@wordpress/element';
import { fetchJson } from '../../functions/fetchJson';
import { addQueryArgs } from '../../functions/addQueryArgs';

const { apiFetch } = wp;
const { addQueryArgs } = wp.url;

export const useArticlesFetch = (attributes, postType, postId, baseUrl = null, postCategories = []) => {
const { article_count, post_types, posts, tags, ignore_categories } = attributes;
Expand Down Expand Up @@ -34,11 +34,12 @@ export const useArticlesFetch = (attributes, postType, postId, baseUrl = null, p
args.categories = postCategories;
}

const path = addQueryArgs('planet4/v1/get-posts', args);

try {
const response = baseUrl
? await fetchJson(`${ baseUrl }/wp-json/${ addQueryArgs('planet4/v1/get-posts', args) }`)
: await apiFetch({ path: addQueryArgs('planet4/v1/get-posts', args) });
? await fetchJson(`${ baseUrl }/wp-json/${ path }`)
: await apiFetch({ path });

const newPosts = [...prevPosts, ...response.recent_posts];

Expand Down
2 changes: 1 addition & 1 deletion assets/src/blocks/Gallery/useGalleryImages.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState, useEffect } from '@wordpress/element';
import { fetchJson } from '../../functions/fetchJson';
import { addQueryArgs } from '../../functions/addQueryArgs';

const { apiFetch } = wp;
const { addQueryArgs } = wp.url;

const GALLERY_IMAGE_SIZES = {
'slider': 'retina-large',
Expand Down
2 changes: 1 addition & 1 deletion assets/src/blocks/Happypoint/useHappypointImageData.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState, useEffect } from '@wordpress/element';
import { fetchJson } from '../../functions/fetchJson';
import { addQueryArgs } from '../../functions/addQueryArgs';

const { apiFetch } = wp;
const { addQueryArgs } = wp.url;

export const useHappypointImageData = imageId => {
const [imageData, setImageData] = useState({});
Expand Down
3 changes: 0 additions & 3 deletions assets/src/blocks/Socialmedia/Socialmedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import {
import withCharacterCounter from '../../components/withCharacterCounter/withCharacterCounter';
import {URLInput} from "../../components/URLInput/URLInput";

const {apiFetch} = wp;
const {addQueryArgs} = wp.url;

const TextControl = withCharacterCounter( BaseTextControl );
const TextareaControl = withCharacterCounter( BaseTextareaControl );

Expand Down
2 changes: 1 addition & 1 deletion assets/src/blocks/Spreadsheet/SpreadsheetFrontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ArrowIcon } from './ArrowIcon';
import { toDeclarations } from '../toDeclarations';
import { HighlightMatches } from '../HighlightMatches';
import { fetchJson } from '../../functions/fetchJson';
import { addQueryArgs } from '../../functions/addQueryArgs';

const { apiFetch } = wp;
const { addQueryArgs } = wp.url;
const { __ } = wp.i18n;

const placeholderData = {
Expand Down
3 changes: 0 additions & 3 deletions assets/src/blocks/Takeactionboxout/Takeactionboxout.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import {
} from '@wordpress/components';
import withCharacterCounter from '../../components/withCharacterCounter/withCharacterCounter';

const {apiFetch} = wp;
const {addQueryArgs} = wp.url;

const TextControl = withCharacterCounter( BaseTextControl );
const TextareaControl = withCharacterCounter( BaseTextareaControl );

Expand Down
21 changes: 21 additions & 0 deletions assets/src/functions/addQueryArgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const addQueryArgs = (path, args) => {
if (typeof path !== 'string' || typeof args !== 'object') {
return path;
}

Object.keys(args).forEach(k => {
const value = args[k];
if (typeof value === 'undefined' || value === '') {
delete args[k];
return;
}
if (Array.isArray(value)) {
value.forEach((v, i) => {
args[`${ k }[${ i }]`] = v;
});
delete args[k];
}
});

return `${ path }?${ new URLSearchParams(args) }`;
};
1 change: 1 addition & 0 deletions classes/blocks/class-articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ private static function populate_post_items( $posts ) {
$recent['page_type'] = $page_type;
$recent['page_type_link'] = get_term_link( $page_type_id );
$recent['link'] = get_permalink( $recent['ID'] );
$recent['date_formatted'] = get_the_date( '', $recent['ID'] );

$recent_posts[] = $recent;
}
Expand Down
4 changes: 0 additions & 4 deletions classes/class-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,6 @@ public function enqueue_public_assets() {
'wp-element',
// Exports the __() function.
'wp-i18n',
// URL helpers (as addQueryArgs).
'wp-url',
// Use to translate date.
'wp-date',
'main',
],
true
Expand Down

0 comments on commit 07f7aa5

Please sign in to comment.