Skip to content

Commit

Permalink
working behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmaguitar committed Oct 4, 2024
1 parent 48b716a commit 6291b57
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
3 changes: 0 additions & 3 deletions plugins/interactivity-router-2f43f8/src/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<?php echo wp_kses_data( get_block_wrapper_attributes() ); ?>
data-wp-interactive="router-2f43f8"
data-wp-router-region="region-example-2f43f8"
data-wp-init="callbacks.setUrlPathname"
>

<p><em>Displaying region "region-example-2f43f8" from <a data-wp-bind--href="state.urlRegionDisplay" data-wp-text="state.urlRegionDisplay"></a></em></p>
Expand All @@ -40,14 +39,12 @@
</nav>

<div class="debugInfo">
<p>state.isPlayground: <code data-wp-text="state.isPlayground"></code></p>
<p>block (region in display) attributes: <code style="text-align: left;">
<?php echo wp_json_encode( $attributes ); ?>
</code></p>

<p>state.urlRegionDisplay: <code data-wp-text="state.urlRegionDisplay"></code></p>

<p>state.urlRegionDisplaySlug: <code data-wp-text="state.urlRegionDisplaySlug"></code></p>

</div>

Expand Down
19 changes: 6 additions & 13 deletions plugins/interactivity-router-2f43f8/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@ import { store } from '@wordpress/interactivity';

const { state } = store( 'router-2f43f8', {
state: {
urlPathname: '',
urlRegionDisplay: window.location.href,
get urlRegionDisplaySlug() {
const isHome = state.urlPathname === '/';
const { pathname } = new URL( state.urlRegionDisplay );
const isHome = pathname === '/';
return isHome
? '/'
: '/' + state.urlPathname.split( '/' ).filter( Boolean ).pop();
},
get isPlayground() {
return state.urlPathname.includes( 'scope' );
},
},
callbacks: {
setUrlPathname: () => {
state.urlPathname = new URL( state.urlRegionDisplay ).pathname;
: '/' + pathname.split( '/' ).filter( Boolean ).pop();
},
},
actions: {
*navigate( e ) {
console.log( 'navigate', e );
e.preventDefault();
const { actions } = yield import(
'@wordpress/interactivity-router'
);
state.urlRegionDisplay = e.target.href;
yield actions.navigate( state.urlRegionDisplaySlug );

//yield actions.navigate( state.urlRegionDisplaySlug );
yield actions.navigate( e.target.href );
},
},
} );

0 comments on commit 6291b57

Please sign in to comment.