10 results @ a time, floating Install button, fixed height while loading styles.

This commit is contained in:
derv82 2017-12-08 01:44:55 -08:00
parent cab2345bc6
commit 4732184670
3 changed files with 72 additions and 27 deletions

View File

@ -88,7 +88,6 @@
<a class="search-result-title"></a> <a class="search-result-title"></a>
<div class="search-result-info"> <div class="search-result-info">
<img class="search-result-screenshot" /> <img class="search-result-screenshot" />
<div class="search-result-overlay">
<div class="actions"> <div class="actions">
<button class="search-result-install" i18n-text="installButton"></button> <button class="search-result-install" i18n-text="installButton"></button>
<button class="search-result-uninstall hidden" i18n-text="deleteStyleLabel"></button> <button class="search-result-uninstall hidden" i18n-text="deleteStyleLabel"></button>
@ -96,6 +95,7 @@
i18n-text="searchResultCustomize" i18n-text="searchResultCustomize"
i18n-title="searchResultCustomizeTooltip"></button> i18n-title="searchResultCustomizeTooltip"></button>
</div> </div>
<div class="search-result-overlay">
<div class="search-result-author"> <div class="search-result-author">
<label i18n-text="author"></label>: <label i18n-text="author"></label>:
<a class="search-result-author-link" target="_blank"></a> <a class="search-result-author-link" target="_blank"></a>
@ -123,6 +123,10 @@
</div> </div>
</template> </template>
<template data-id="emptySearchResult">
<div class="search-result-empty"></div>
</template>
<link rel="stylesheet" href="vendor-overwrites/colorpicker/colorpicker.css"> <link rel="stylesheet" href="vendor-overwrites/colorpicker/colorpicker.css">
<script src="vendor-overwrites/colorpicker/colorpicker.js"></script> <script src="vendor-overwrites/colorpicker/colorpicker.js"></script>

View File

@ -22,13 +22,23 @@ body.search-results-shown {
#search-results-list { #search-results-list {
position: relative; position: relative;
min-height: 200px; /* Size of lds-spinner */ min-height: 200px;
} }
.search-result { .search-result, .search-result-empty {
min-height: 170px;
padding: 5px; padding: 5px;
} }
.search-result-empty {
position: relative;
}
.search-result-empty .lds-spinner {
top: 0;
width: 150px;
height: 150px;
}
.search-result-screenshot { .search-result-screenshot {
height: 140px; height: 140px;
width: 100%; width: 100%;
@ -44,22 +54,35 @@ body.search-results-shown {
.search-result-info { .search-result-info {
position: relative; position: relative;
} }
.search-result-info > div {
.search-result-overlay {
width: 100%;
height: 85px;
position: absolute;
top: 55px;
opacity: 0; opacity: 0;
background-color: rgba(255, 255, 255, 0.6); position: absolute;
width: 100%;
transition: opacity linear 0.2s; transition: opacity linear 0.2s;
overflow: hidden; overflow: hidden;
text-align: center;
} }
.search-result-info:hover .search-result-overlay { .search-result-info:hover > div {
opacity: 1; opacity: 1;
} }
.search-result-overlay > .actions { .search-result-overlay {
height: 55px;
top: 85px;
background-color: rgba(255, 255, 255, 0.6);
}
.search-result-info > .actions {
top: 30px;
}
.search-result-info > .actions > button {
background-color: #fff;
}
.search-result-info > .actions > button:hover {
background-color: #ccc;
}
.search-result-overlay > * {
text-align: center; text-align: center;
} }
@ -131,7 +154,8 @@ body.search-results-shown {
.search-result-install, .search-result-install,
.search-result-customize, .search-result-customize,
.search-result-uninstall { .search-result-uninstall {
width: 50%; width: 40%;
margin: 3px;
} }
#search-results-nav { #search-results-nav {

View File

@ -32,7 +32,7 @@
* @returns {Object} Includes load(), next(), and prev() methods to alter the search results. * @returns {Object} Includes load(), next(), and prev() methods to alter the search results.
*/ */
function searchResultsController() { function searchResultsController() {
const DISPLAYED_RESULTS_PER_PAGE = 3; // Number of results to display in popup.html const DISPLAYED_RESULTS_PER_PAGE = 10; // Number of results to display in popup.html
const DELAY_AFTER_FETCHING_STYLES = 0; // Millisecs to wait before fetching next batch of search results. const DELAY_AFTER_FETCHING_STYLES = 0; // Millisecs to wait before fetching next batch of search results.
const DELAY_BEFORE_SEARCHING_STYLES = 0; // Millisecs to wait before fetching .JSON for next search result. const DELAY_BEFORE_SEARCHING_STYLES = 0; // Millisecs to wait before fetching .JSON for next search result.
const searchAPI = searchUserstyles(); const searchAPI = searchUserstyles();
@ -98,6 +98,14 @@
const totalPageCount = Math.ceil(Math.max(1, totalResultsCount / DISPLAYED_RESULTS_PER_PAGE)); const totalPageCount = Math.ceil(Math.max(1, totalResultsCount / DISPLAYED_RESULTS_PER_PAGE));
$('#search-results-nav-next').disabled = (currentDisplayedPage >= totalPageCount || loading); $('#search-results-nav-next').disabled = (currentDisplayedPage >= totalPageCount || loading);
$('#search-results-nav-total-pages').textContent = totalPageCount; $('#search-results-nav-total-pages').textContent = totalPageCount;
// Fill in remaining search results with blank results + spinners
const maxResults = currentDisplayedPage < totalPageCount
? DISPLAYED_RESULTS_PER_PAGE
: displayedResults.length + unprocessedResults.length;
for (let i = displayedResults.length; i < maxResults; i++) {
createLoadingSearchResultNode();
}
} }
/** /**
@ -109,10 +117,7 @@
function loadMoreIfNeeded() { function loadMoreIfNeeded() {
if (shouldLoadMore()) { if (shouldLoadMore()) {
setLoading(true);
setTimeout(load, DELAY_BEFORE_SEARCHING_STYLES); setTimeout(load, DELAY_BEFORE_SEARCHING_STYLES);
} else {
setLoading(false);
} }
} }
@ -157,7 +162,10 @@
processNextResult(); processNextResult();
} else if (searchAPI.isExhausted()) { } else if (searchAPI.isExhausted()) {
// Stop if no more search results. // Stop if no more search results.
setLoading(false); if (processedResults.length === 0) {
// No results
error(404);
}
} else { } else {
setLoading(true); setLoading(true);
// Search for more results. // Search for more results.
@ -169,6 +177,7 @@
category = searchAPI.getCategory(tab.url); category = searchAPI.getCategory(tab.url);
searchAPI.search(category) searchAPI.search(category)
.then(searchResults => { .then(searchResults => {
setLoading(false);
if (searchResults.data.length === 0) { if (searchResults.data.length === 0) {
throw 404; throw 404;
} }
@ -188,7 +197,6 @@
*/ */
function processNextResult() { function processNextResult() {
if (!shouldLoadMore()) { if (!shouldLoadMore()) {
setLoading(false);
return; return;
} }
@ -265,6 +273,16 @@
}); });
} }
function createLoadingSearchResultNode() {
const entry = template.emptySearchResult.cloneNode(true);
entry.appendChild(
$create(
'.lds-spinner',
new Array(12).fill($create('div')).map(e => e.cloneNode()))
);
$('#search-results-list').appendChild(entry);
}
/** /**
* Constructs and adds the given search result to the popup's Search Results container. * Constructs and adds the given search result to the popup's Search Results container.
* @param {Object} userstyleSearchResult The SearchResult object from userstyles.org * @param {Object} userstyleSearchResult The SearchResult object from userstyles.org
@ -308,8 +326,7 @@
screenshotUrl = searchAPI.BASE_URL + '/style_screenshot_thumbnails/' + screenshotUrl; screenshotUrl = searchAPI.BASE_URL + '/style_screenshot_thumbnails/' + screenshotUrl;
} }
Object.assign(screenshot, { Object.assign(screenshot, {
src: screenshotUrl, src: screenshotUrl
title: searchResultName
}); });
const searchResultOverlay = $('.search-result-overlay', entry); const searchResultOverlay = $('.search-result-overlay', entry);