hide year headings when all items are hidden

fixes #7
This commit is contained in:
Rhiannon Morris 2020-09-27 01:36:20 +02:00
parent debefa0d3d
commit b9ea7f7bcb
2 changed files with 28 additions and 10 deletions

View file

@ -122,7 +122,7 @@ makeYearItems :: Bool -- ^ nsfw
-> [(FilePath, Info)] -> [(FilePath, Info)]
-> Builder -> Builder
makeYearItems nsfw year infos = [b|@4 makeYearItems nsfw year infos = [b|@4
<li class="item year-marker"> <li class="item year-marker" id="marker-$year">
<span class=year-text>$year'</span> <span class=year-text>$year'</span>
$4.items $4.items
|] |]
@ -132,7 +132,8 @@ makeYearItems nsfw year infos = [b|@4
makeItem :: Bool -> FilePath -> Info -> Builder makeItem :: Bool -> FilePath -> Info -> Builder
makeItem nsfw file info@(Info {title, bg}) = [b|@4 makeItem nsfw file info@(Info {title, bg}) = [b|@4
<li class="item post$nsfw'" data-date="$date'" data-updated="$updated'" <li class="item post$nsfw'" data-date="$date'" data-year=$year'
data-updated="$updated'"
data-tags="$tags'"> data-tags="$tags'">
<figure> <figure>
<a href="$dir"> <a href="$dir">
@ -149,6 +150,8 @@ makeItem nsfw file info@(Info {title, bg}) = [b|@4
thumb = getThumb dir info thumb = getThumb dir info
nsfw' = if nsfw && #anyNsfw info then [b| nsfw|] else "" nsfw' = if nsfw && #anyNsfw info then [b| nsfw|] else ""
tags' = fold $ intersperse ";" $ map fromText $ tagsFor nsfw info tags' = fold $ intersperse ";" $ map fromText $ tagsFor nsfw info
date' = formatShort $ #latestDate info date = #latestDate info
date' = formatShort date
year' = #year date
updated' = if #updated info then [b|true|] else [b|false|] updated' = if #updated info then [b|true|] else [b|false|]
bgStyle = ifJust bg \col -> [b| style="background: $col"|] bgStyle = ifJust bg \col -> [b| style="background: $col"|]

View file

@ -1,11 +1,11 @@
(function() { (function() {
'use strict'; 'use strict';
let items;
let reqBoxes; let reqBoxes;
let excBoxes; let excBoxes;
let allBoxes; let allBoxes;
let tags; let tags;
let itemsByYear;
let showSingles = true; let showSingles = true;
@ -21,11 +21,19 @@ function updateItems() {
let [reqTags, excTags] = fillSets(); let [reqTags, excTags] = fillSets();
let anyReq = reqTags.size > 0; let anyReq = reqTags.size > 0;
for (let [year, items] of itemsByYear) {
let hide = true;
for (let item of items) { for (let item of items) {
let req = tags.get(item).some(x => reqTags.has(x)); let req = tags.get(item).some(x => reqTags.has(x));
let exc = tags.get(item).some(x => excTags.has(x)); let exc = tags.get(item).some(x => excTags.has(x));
let hidden = exc || (anyReq && !req);
item.hidden = exc || (anyReq && !req); item.hidden = hidden;
hide &&= hidden;
}
document.getElementById(`marker-${year}`).hidden = hide;
} }
} }
@ -101,13 +109,20 @@ function useFragment() {
function setup() { function setup() {
items = Array.from(document.getElementsByClassName('post'));
function inputs(id) { function inputs(id) {
let iter = document.getElementById(id).getElementsByTagName('input'); let iter = document.getElementById(id).getElementsByTagName('input');
return Array.from(iter); return Array.from(iter);
} }
let items = Array.from(document.getElementsByClassName('post'));
itemsByYear = new Map;
for (let item of items) {
let year = item.dataset.year;
if (!itemsByYear.has(year)) itemsByYear.set(year, new Set);
itemsByYear.get(year).add(item);
}
reqBoxes = inputs('require'); reqBoxes = inputs('require');
excBoxes = inputs('exclude'); excBoxes = inputs('exclude');
allBoxes = [...reqBoxes, ...excBoxes]; allBoxes = [...reqBoxes, ...excBoxes];