Skip to content

Commit

Permalink
Fix action error renderResult
Browse files Browse the repository at this point in the history
  • Loading branch information
garridinsi committed Apr 6, 2024
1 parent 65f1ca4 commit 8922f91
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion carbonbadge-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Plugin Name: Carbonbadge Block
* Description: The Website Carbon widget Gutenberg block, made with the Interactivity API.
* Version: 1.2.1
* Version: 1.2.2
* Requires at least: 6.5
* Requires PHP: 7.0
* Author: garridinsi
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "carbonbadge-block",
"version": "1.2.1",
"version": "1.2.2",
"description": "An interactive block with the Interactivity API",
"author": "The WordPress Contributors",
"license": "GPL-3.0-or-later",
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: block
Donate link: https://buymeacoffee.com/garridinsi
Requires at least: 6.5
Tested up to: 6.5
Stable tag: 1.2.1
Stable tag: 1.2.2
License: GPL-3.0-or-later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -34,6 +34,9 @@ You can find the code of this plugin on [GitHub](https://github.com/garridinsi/c
3. Place the block on any Gutenberg post or page.

== Changelog ==
= 1.2.2 =
* Fix a error with an action on the view

= 1.2.1 =
* Fix some issues with translations

Expand Down
2 changes: 1 addition & 1 deletion src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "carbonbadge-block/carbonbadge-block",
"version": "1.2.1",
"version": "1.2.2",
"title": "Carbonbadge",
"category": "widgets",
"description": "Block to display your website's carbon footprint using the Carbonbadge API.",
Expand Down
2 changes: 1 addition & 1 deletion src/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
'showLinkToWebCarbon' => $show_link_to_wc,
"i18n" => array(
"measuringCO2" => __("Measuring CO₂", "carbonbadge-block"),
"noDataAvailable" => __("No data available", "carbonbadge-block"),
"noResult" => __("No Result", "carbonbadge-block"),
"gOfCO2PerView" => __("%sg of CO₂/view", "carbonbadge-block"),
"websiteCarbon" => __("Website Carbon", "carbonbadge-block"),
"cleanerThan" => __("Cleaner than %s% of pages tested", "carbonbadge-block")
Expand Down
9 changes: 7 additions & 2 deletions src/view.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { store, getContext } from '@wordpress/interactivity';
import { store, getContext, withScope } from '@wordpress/interactivity';
import {
getCurrentPage,
determineUrl,
Expand Down Expand Up @@ -32,8 +32,12 @@ const { state, actions } = store( 'carbonbadge-block', {
* Renders the result of a measurement.
* Gets the measurement and percentage values from the context.
*/
renderResult: () => {
*renderResult() {
const context = getContext();
if ( ! context || ! context.resultData ) {
context.measureDiv = state.i18n.noResult;
return;
}
const data = context.resultData;
if ( ! data || ! data.c || ! data.p ) {
context.measureDiv = state.i18n.noResult;
Expand Down Expand Up @@ -77,6 +81,7 @@ const { state, actions } = store( 'carbonbadge-block', {
} )
.catch( ( err ) => {
removeFromStorage( urlToCheck );
context.measureDiv = state.i18n.noResult;
throw new Error( err );
} );
},
Expand Down

0 comments on commit 8922f91

Please sign in to comment.