Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map: Add filters for format, type, month, country #523

Closed
wants to merge 8 commits into from

Conversation

iandunn
Copy link
Member

@iandunn iandunn commented Nov 29, 2023

@iandunn iandunn self-assigned this Nov 29, 2023
@iandunn
Copy link
Member Author

iandunn commented Nov 29, 2023

@StevenDufresne here's a rough sketch of how I see filters working. It's a bit hacky to integrate the query-filters block, though, because that is rendered in PHP and the map block is rendered in React. query-filters is also built to use WP posts, and the map block uses arbitrary data.

I think it could work with some effort, but I'm curious if you see a better way or have any other thoughts.

Comment on lines +106 to +108
<!-- TODO: rearrange this so that .wporg-google-map-query-filters above and the map/list/search elements below are all direct descendents of the same container.
-- then use Grid to change the `order` so that filters shows up after search
-->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing a good way to do this. If react renders into wporg-google-map-container then it'll wipe out the filters. In order to hydrate instead of render, the server markup would have to match the react markup. Subgrid support isn't good enough yet.

I could do something hacky, like using JS to save the innerHTML content to a variable, set display:none, then use <RawHTML> (dangerouslySetInnerHTML) to render it inside the react container. It feels like there should be a better way, though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also thought about refactoring so that each React component is independent. So, the server would generate something like this:

<div id="container">
	<div id="map"></div>
	<div id="search"></div>

	<div id="filters">
		<?php echo do_blocks( <!-- wp:wporg/query-filter ... --> ); ?>
	</div>

	<div id="list"></div>
</div>

...then call createRoot() for map, search, and list seperately. The problem there is that there needs to be a Main component managing the state for those subcomponents.

Another idea might be to basically re-create the InnerBlocks / ServerSideRender concept, and grab the query-filter content via a REST API request, then render the result into the DOM. That's similar to the hacky idea about about grabbing the InnerHTML, though 🤷🏻‍♂️

@StevenDufresne
Copy link
Contributor

Alright, I spent some time looking at these pieces today. I have a theory of what can work, but haven't tried it.

I think you can get the query filter state by hooking into the interactivity API store. Take a read through the doc to understand more how it works.

In the events.wordpress.org UI it doesn't appear like the search needs to update the map. It would actually be weird to update something below it and have it change up there so to speak. So can we avoid using the map component for the list of events and just do it with another component and make it behave more like WordPress and a post query? Allow it to post-back, intercept the query server-side, replace it with an events-specific query results, and reload the page?

If we want have the postback-less interactivity, I would suggest we still make our own list component that uses the interactivity API and therefore will work nicely with the QueryFilters (with some slight modifications I think).

The last approach would be to try and access the interactivity API store, like store.wporg.queryFilters (it may not be available because its declared via wp-context which is a local state) and create a wrapper component in wporg-events-2023 that reacts to changes in the property and re-renders the new list component or in this case, we could probably re-use the google map block in list-mode.

Reference from the proposal doc:

State: Defines data available to the HTML nodes of the page. It is important to differentiate between two ways to define the data:
Global state: It is defined using the store() function, and the data is available to all the HTML nodes of the page.
Context/Local State: It is defined using the data-wp-context directive in an HTML node, and the data is available to that HTML node and its children

can't use innerblocks or serversiderender, would have to fork it. plus interactivity api isnt stable yet. better to just write from scratch
@iandunn
Copy link
Member Author

iandunn commented Dec 4, 2023

Closing in favor of WordPress/wordcamp.org#1124

@iandunn iandunn closed this Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants