feat: index page for desktop
This commit is contained in:
@@ -30,7 +30,7 @@ case class Routes(countries: List[Country])(implicit
|
||||
}
|
||||
val engine: TemplateEngine = buildTemplateEngine()
|
||||
|
||||
private val pageSize = 10
|
||||
private val pageSize = 12
|
||||
|
||||
@cask.get("/")
|
||||
def indexPage(region: Option[String] = None, page: Int = 0) = {
|
||||
@@ -62,6 +62,38 @@ case class Routes(countries: List[Country])(implicit
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* this method returns directly set of cards
|
||||
* and new anchor for loading next page of cards
|
||||
*
|
||||
* intended to be called from "next-page-anchor" with htmx
|
||||
*/
|
||||
@cask.get("/countries-cards")
|
||||
def getPageOfCountriesCards(region: Option[String] = None, page: Int = 0) = {
|
||||
val context = new Context()
|
||||
|
||||
val selectedCountries = region match {
|
||||
case None => countries
|
||||
case Some("") => countries
|
||||
case Some(selectedRegion) => countries.filter(_.region == selectedRegion)
|
||||
}
|
||||
|
||||
val startIndex = page * pageSize
|
||||
val countriesPage =
|
||||
selectedCountries.slice(startIndex, startIndex + pageSize)
|
||||
// if current page is not full - there will be no next page
|
||||
val nextPage = if (countriesPage.length == pageSize) page + 1 else -1
|
||||
context.setVariable("countriesList", countriesPage.asJava)
|
||||
context.setVariable("selectedRegion", region.getOrElse(""))
|
||||
context.setVariable("nextPage", nextPage)
|
||||
|
||||
val cards = engine.process("index", Set("cards-of-countries", "infiniteScrollAnchor").asJava, context)
|
||||
Response(
|
||||
cards,
|
||||
headers = Seq("Content-Type" -> "text/html; charset=utf-8")
|
||||
)
|
||||
}
|
||||
|
||||
@cask.get("/country")
|
||||
def getCountryPage(countryName: String) = {
|
||||
val context = new Context()
|
||||
|
||||
Reference in New Issue
Block a user