Search links and pagination in data objects of wp-source

Roadmap Card

Description

Right now themes need to include a lot of verbose code in their pagination and search pages using libraries.source just to get:

  • query
  • if it is a search
  • the search query
  • page
  • path
  • next page link
  • previous page link

It doesn’t make sense. Frontity themes should be easy to create.

User Stories

As a Frontity theme developer
I want to access pagination and search in the data objects
so that I don’t have to repeat the same code over and over on all my themes

Possible solution

Let’s improve searches and pagination by adding:

  • For all entities:
    • data.link
    • data.query
  • For searches:
    • data.isSearch
    • data.searchQuery
  • For archives:
    • data.page
    • data.path
    • data.next
    • data.previous

Luis said in the PR:

I’ve found that when you pass down data like this:

<Post data={data} />

it feels a bit weird to know everything about the post (the type , the id , the isPost …) but to get the link you have to go somewhere else to get it:

const id = data.id; 
const type = data.type; 
const isPost = data.isPost; 
const link = state.source[data.type][data.id].link // <-- feels overcomplicated.

or you have to pass it down along with data :

so I thought it made sense to store it in data.link along with the rest of the properties.

I agree with the reasoning :+1:

:smile:

This has been implemented according to https://github.com/frontity/frontity/pull/253

The following properties have been added to state.source:

  • For all entities:
    • data.link
    • data.query
  • For searches:
    • data.isSearch
    • data.searchQuery
  • For archives:
    • data.page
    • data.route
    • data.next
    • data.previous

The 2020 theme has been updated to include the new attributes in examples:

The documentation: https://docs.frontity.org/api-reference-1/wordpress-source#source-get

1 Like