Skip to content

Commit

Permalink
Example options
Browse files Browse the repository at this point in the history
  • Loading branch information
jconroy committed Nov 12, 2020
1 parent 26681dc commit 412b865
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 2 deletions.
52 changes: 50 additions & 2 deletions js/src/get-started-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,66 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { compose } from '@wordpress/compose';
import { withDispatch, withSelect } from '@wordpress/data';
import { OPTIONS_STORE_NAME } from '@woocommerce/data';
import { Button } from '@wordpress/components';

/**
* Internal dependencies
*/
import './index.scss';

const GetStartedPage = ( { query } ) => {
const GetStartedPage = ( { query, optionView, updateOptions } ) => {

const updateTest = () => {

let temp = optionView;

if (temp == 'yes') {
temp = 'no';
} else {
temp = 'yes';
}

console.log(temp);

updateOptions( {
gla_started: temp,
} );
};

return (
<div>
Hello World!
<div>
<Button
label={ __( 'Test Option Update', 'gla' ) }
onClick={ updateTest }
>
Click me
</Button>
</div>
</div>
);
};

export default GetStartedPage;
export { GetStartedPage };

// default export
export default compose(
withSelect( ( select ) => {
const { getOption, isOptionsUpdating } = select( OPTIONS_STORE_NAME );
const isUpdateRequesting = isOptionsUpdating();

return {
optionView: getOption( 'gla_started' ),
};
} ),
withDispatch( ( dispatch ) => {
const { updateOptions } = dispatch( OPTIONS_STORE_NAME );
return {
updateOptions,
};
} )
)( GetStartedPage );
134 changes: 134 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"stylelint-config-wordpress": "^17.0.0"
},
"dependencies": {
"@woocommerce/data": "^1.1.1",
"@woocommerce/date": "^2.1.0",
"@woocommerce/navigation": "^5.2.0",
"@woocommerce/tracks": "^1.0.0",
"@wordpress/components": "^11.1.1",
"@wordpress/icons": "^2.8.0"
Expand Down

0 comments on commit 412b865

Please sign in to comment.