add button to skip all cws

This commit is contained in:
rhiannon morris 2022-12-26 22:04:57 +01:00
parent 1e7a58359d
commit ccb4c2eabd
4 changed files with 60 additions and 32 deletions

View file

@ -9,7 +9,7 @@ import qualified NsfwWarning
import Control.Exception
import Control.Monad
import Data.List (sort, intersperse)
import Data.Maybe (fromMaybe, isNothing)
import Data.Maybe (fromMaybe, isNothing, isJust)
import qualified Data.Text as Strict
import qualified Data.Text.Lazy as Lazy
import System.FilePath (joinPath, splitPath)
@ -234,21 +234,32 @@ makeButtonBar title images =
| otherwise ->
makeNav "cat" $ map (uncurry makeCat) cats
where
makeNav (cls :: Text) inner = [b|@0
<nav id=alts class=$cls aria-label="alternate versions">
$2.inner
</nav> |]
makeCat lbl imgs = [b|@0
<section>
<h3 class=alt-cat>$lbl</h3>
$0.alts
</section> |]
where alts = makeAlts imgs
makeAlts imgs = [b|@0
<ul class="buttonbar bb-choice">
$2.elems
</ul> |]
where elems = map (\(img,i) -> altButton img i) imgs
makeNav (cls :: Text) inner = [b|@0
<nav id=alts class=$cls aria-label="alternate versions">
$2.inner
$2.skipAll
</nav> |]
makeCat lbl imgs = [b|@0
<section>
<h3 class=alt-cat>$lbl</h3>
$0.alts
</section> |]
where alts = makeAlts imgs
makeAlts imgs = [b|@0
<ul class="buttonbar bb-choice">
$2.elems
</ul> |]
where elems = map (\(img,i) -> altButton img i) imgs
skipAll =
if any (isJust . #warning . fst) images then
[b|@0
<div class=buttonbar id=skipAllDiv>
<input type=checkbox name=skipAll id=skipAll>
<label for=skipAll>skip warnings</label>
</div>
|]
else
""
flatten :: [(Text, [(Image, a)])] -> [(Image, Text)]
flatten cats =