added main page pagination

This commit is contained in:
nek0 2015-02-12 00:15:07 +01:00
parent 11a37855c5
commit 1dd08f9f59
4 changed files with 45 additions and 0 deletions

View file

@ -18,11 +18,24 @@
module Handler.Home where module Handler.Home where
import Import import Import
import qualified Data.Text as T
getHomeR :: Handler Html getHomeR :: Handler Html
getHomeR = do getHomeR = do
recentMedia <- runDB $ selectList [] [Desc MediumTime, LimitTo 30] recentMedia <- runDB $ selectList [] [Desc MediumTime, LimitTo 30]
nextMediaQuery <- runDB $ selectList [] [Desc MediumTime, LimitTo 1, OffsetBy 30]
nextMedia <- return $ not $ null nextMediaQuery
widgetLayout <- return $ widgetFile "default-widget" widgetLayout <- return $ widgetFile "default-widget"
defaultLayout $ do defaultLayout $ do
setTitle "Eidolon :: Home" setTitle "Eidolon :: Home"
$(widgetFile "home") $(widgetFile "home")
getPageR :: Int -> Handler Html
getPageR page = do
pageMedia <- runDB $ selectList [] [Desc MediumTime, LimitTo 30, OffsetBy (page*30)]
nextMediaQuery <- runDB $ selectList [] [Desc MediumTime, LimitTo 1, OffsetBy ((page + 1) * 30)]
nextMedia <- return $ not $ null nextMediaQuery
widgetLayout <- return $ widgetFile "default-widget"
defaultLayout $ do
setTitle $ toHtml ("Eidolon :: Page " `T.append` (T.pack $ show page))
$(widgetFile "page")

View file

@ -20,6 +20,7 @@
/robots.txt RobotsR GET /robots.txt RobotsR GET
/ HomeR GET / HomeR GET
/page/#Int PageR GET
/signup SignupR GET POST /signup SignupR GET POST
/login LoginR GET POST /login LoginR GET POST
/logout LogoutR GET /logout LogoutR GET

View file

@ -10,3 +10,9 @@ $forall (Entity mediumId medium) <- recentMedia
<figure> <figure>
<img src=#{mediumThumb medium}> <img src=#{mediumThumb medium}>
<figcaption>#{mediumTitle medium} <figcaption>#{mediumTitle medium}
$if nextMedia
<div id="header" class="item" data-width="400">
<div class="inner">
<p>
<a href=@{PageR 1}>
older

25
templates/page.hamlet Normal file
View file

@ -0,0 +1,25 @@
$doctype 5
$if page == 1
<div id="header" class="item" data-width="400">
<div class="inner">
<p>
<a href=@{HomeR}>
newer
$else
<div id="header" class="item" data-width="400">
<div class="inner">
<p>
<a href=@{PageR (page - 1)}>
newer
$forall (Entity mediumId medium) <- pageMedia
<article class="item" data-width=#{mediumThumbWidth medium}>
<a href=@{MediumR mediumId}>
<figure>
<img src=#{mediumThumb medium}>
<figcaption>#{mediumTitle medium}
$if nextMedia
<div id="header" class="item" data-width="400">
<div class="inner">
<p>
<a href=@{PageR (page + 1)}>
older