[c] add loading indicators
This commit is contained in:
parent
2ecb95bb94
commit
d740a8005b
5 changed files with 52 additions and 9 deletions
|
@ -14,6 +14,7 @@
|
||||||
"@sveltejs/adapter-node": "^1.2.4",
|
"@sveltejs/adapter-node": "^1.2.4",
|
||||||
"@sveltejs/adapter-static": "^2.0.3",
|
"@sveltejs/adapter-static": "^2.0.3",
|
||||||
"@sveltejs/kit": "^1.20.5",
|
"@sveltejs/kit": "^1.20.5",
|
||||||
|
"nprogress": "^0.2.0",
|
||||||
"sass": "^1.62.0",
|
"sass": "^1.62.0",
|
||||||
"svelte": "^3.54.0",
|
"svelte": "^3.54.0",
|
||||||
"svelte-material-icons": "^3.0.5",
|
"svelte-material-icons": "^3.0.5",
|
||||||
|
|
|
@ -68,3 +68,12 @@ button.transparent,
|
||||||
[data-theme="dark"] .overflowing::after {
|
[data-theme="dark"] .overflowing::after {
|
||||||
background: linear-gradient(to top, $slate-800, #00000000);
|
background: linear-gradient(to top, $slate-800, #00000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#nprogress .bar {
|
||||||
|
background: #398711 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fancy blur effect */
|
||||||
|
#nprogress .peg {
|
||||||
|
box-shadow: 0 0 10px #398711, 0 0 6px #398711 !important;
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
let searchQuery = "";
|
let searchQuery = "";
|
||||||
let selectedFile = "modlist-rekindled.json";
|
let selectedFile = "modlist-rekindled.json";
|
||||||
let fileList = [];
|
let fileList = [];
|
||||||
|
let loading = true;
|
||||||
|
|
||||||
let searchQueryInput = (event) => {
|
let searchQueryInput = (event) => {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
@ -37,11 +38,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
loading = true;
|
||||||
const response = await fetch("/assets/json/modlist-items.json");
|
const response = await fetch("/assets/json/modlist-items.json");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
fileList = data;
|
fileList = data;
|
||||||
await fetchData(selectedFile);
|
await fetchData(selectedFile);
|
||||||
checkOverflow();
|
checkOverflow();
|
||||||
|
loading = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
function fuzzySearch(query, mods) {
|
function fuzzySearch(query, mods) {
|
||||||
|
@ -63,8 +66,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
|
loading = true;
|
||||||
removeOverflow();
|
removeOverflow();
|
||||||
checkOverflow();
|
checkOverflow();
|
||||||
|
loading = false;
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -83,7 +88,9 @@
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
{#if fuzzySearch(searchQuery, mods.mods).length === 0 && fuzzySearch(searchQuery, mods.optional_mods).length === 0}
|
{#if loading}
|
||||||
|
<p>Loading...</p>
|
||||||
|
{:else if fuzzySearch(searchQuery, mods.mods).length === 0 && fuzzySearch(searchQuery, mods.optional_mods).length === 0}
|
||||||
<p>⚠️ No results found.</p>
|
<p>⚠️ No results found.</p>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="grid" id="mods">
|
<div class="grid" id="mods">
|
||||||
|
@ -177,7 +184,8 @@
|
||||||
margin-right: 1em;
|
margin-right: 1em;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
align-self: center;
|
align-self: flex-start;
|
||||||
|
margin: 0.5em 1em 0.5em 0;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,36 +1,56 @@
|
||||||
<script>
|
<script>
|
||||||
import "../app.scss";
|
import "../app.scss";
|
||||||
import Header from "./Header.svelte";
|
import Header from "./Header.svelte";
|
||||||
|
import NProgress from "nprogress";
|
||||||
|
import { navigating } from "$app/stores";
|
||||||
|
import { page } from '$app/stores';
|
||||||
|
import "nprogress/nprogress.css";
|
||||||
import { smoothScrollTo, handleKeydown } from "$lib/common";
|
import { smoothScrollTo, handleKeydown } from "$lib/common";
|
||||||
|
|
||||||
import { fly } from "svelte/transition";
|
import { fly } from "svelte/transition";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
export let data;
|
export let data;
|
||||||
|
let cached = $page.scrollRestoration === 'manual';
|
||||||
|
|
||||||
|
NProgress.configure({
|
||||||
|
// Full list: https://github.com/rstacruz/nprogress#configuration
|
||||||
|
minimum: 0.16,
|
||||||
|
showSpinner: false
|
||||||
|
});
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if ($navigating && !cached) {
|
||||||
|
NProgress.start();
|
||||||
|
}
|
||||||
|
if (!$navigating && !cached) {
|
||||||
|
NProgress.done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
function smoothScrollTo(elementId) {
|
function smoothScrollTo(elementId) {
|
||||||
document.getElementById(elementId).scrollIntoView({
|
document.getElementById(elementId).scrollIntoView({
|
||||||
behavior: 'smooth'
|
behavior: "smooth",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleKeydown(elementId, event) {
|
function handleKeydown(elementId, event) {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === "Enter") {
|
||||||
smoothScrollTo(elementId);
|
smoothScrollTo(elementId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleTopButton() {
|
function toggleTopButton() {
|
||||||
const topButton = document.querySelector('.top-button');
|
const topButton = document.querySelector(".top-button");
|
||||||
if (window.scrollY >= window.innerHeight) {
|
if (window.scrollY >= window.innerHeight) {
|
||||||
topButton.classList.add('show');
|
topButton.classList.add("show");
|
||||||
} else {
|
} else {
|
||||||
topButton.classList.remove('show');
|
topButton.classList.remove("show");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('scroll', toggleTopButton);
|
window.addEventListener("scroll", toggleTopButton);
|
||||||
})
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="app">
|
<div class="app">
|
||||||
|
|
|
@ -635,6 +635,11 @@ normalize-path@^3.0.0, normalize-path@~3.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
|
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
|
||||||
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
|
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
|
||||||
|
|
||||||
|
nprogress@^0.2.0:
|
||||||
|
version "0.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1"
|
||||||
|
integrity sha512-I19aIingLgR1fmhftnbWWO3dXc0hSxqHQHQb3H8m+K3TnEn/iSeTZZOyvKXWqQESMwuUVnatlCnZdLBZZt2VSA==
|
||||||
|
|
||||||
once@^1.3.0:
|
once@^1.3.0:
|
||||||
version "1.4.0"
|
version "1.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
|
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
|
||||||
|
|
Loading…
Reference in a new issue