From 16552790069070c6a5435f37523173b1be6a4652 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Wed, 29 Sep 2021 17:12:25 +0200 Subject: Display a meaningful error when all sourcesets are filtered (#2161) --- .../dokka/scripts/platform-content-handler.js | 25 ++++++++++++++++------ .../base/src/main/resources/dokka/styles/style.css | 6 ++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js b/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js index 64a1ce53..de5c6b15 100644 --- a/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js +++ b/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js @@ -6,6 +6,7 @@ filteringContext = { let highlightedAnchor; let topNavbarOffset; let instances = []; +let sourcesetNotification; const samplesDarkThemeName = 'darcula' const samplesLightThemeName = 'idea' @@ -201,10 +202,6 @@ function initializeFiltering() { let cached = window.localStorage.getItem('inactive-filters') if (cached) { let parsed = JSON.parse(cached) - //Events are used by react to get values in 'on this page' - const event = new CustomEvent('sourceset-filter-change', {detail: parsed}); - window.dispatchEvent(event); - filteringContext.activeFilters = filteringContext.restrictedDependencies .filter(q => parsed.indexOf(q) == -1) } else { @@ -304,11 +301,25 @@ function refreshFiltering() { elem.setAttribute("data-filterable-current", platformList.join(' ')) } ) - const event = new CustomEvent('sourceset-filter-change', {detail: sourcesetList}); - window.dispatchEvent(event); - refreshFilterButtons() refreshPlatformTabs() + refreshNoContentNotification() +} + +function refreshNoContentNotification() { + const element = document.getElementsByClassName("main-content")[0] + if(filteringContext.activeFilters.length === 0){ + element.style.display = "none"; + + const appended = document.createElement("div") + appended.className = "filtered-message" + appended.innerText = "All documentation is filtered, please adjust your source set filters in top-right corner of the screen" + sourcesetNotification = appended + element.parentNode.prepend(appended) + } else { + if(sourcesetNotification) sourcesetNotification.remove() + element.style.display = "block" + } } function refreshPlatformTabs() { diff --git a/plugins/base/src/main/resources/dokka/styles/style.css b/plugins/base/src/main/resources/dokka/styles/style.css index 65a76042..2e69c3ee 100644 --- a/plugins/base/src/main/resources/dokka/styles/style.css +++ b/plugins/base/src/main/resources/dokka/styles/style.css @@ -1071,6 +1071,12 @@ div.runnablesample { background: var(--white-10); } +.filtered-message { + margin: 25px; + font-size: 20px; + font-weight: bolder; +} + @media screen and (max-width: 1119px) { h1.cover { font-size: 48px; -- cgit