I need to transfer the logic of displaying pages from the backend to the frontend, that is, I need to transfer this has_more_items, that is, that on the frontend it would be possible to receive data without has_more_items.
Ruby on rails, controller.rb
def index
props = {
years: params[:year],
months: params[:month]
}
unless props_valid?(props)
return render_api({ years: registers.years }, :ok)
end
items = registers.extract_by_date(props).by_page(params[:page])
next_page_registers = registers.extract_by_date(props).by_page(params[:page].to_i)
has_more_items = next_page_registers.empty?
render_api({ items: items, years: registers.years, has_more_items: has_more_items },
:ok, each_serializer: RegistersSerializer)
end
React list.js
fetchRegistersOnScroll() {
const { actions, current, dispatch } = this.props
page++
actions.fetchRegisters(current, page)
.then(res => this.setState({ hasMoreItems: res.data.has_more_items }))
}