[c] add loading indicators

This commit is contained in:
Sangelo 2024-06-12 10:58:26 +02:00
parent 2ecb95bb94
commit d740a8005b
5 changed files with 52 additions and 9 deletions

View file

@ -14,6 +14,7 @@
"@sveltejs/adapter-node": "^1.2.4",
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.20.5",
"nprogress": "^0.2.0",
"sass": "^1.62.0",
"svelte": "^3.54.0",
"svelte-material-icons": "^3.0.5",

View file

@ -68,3 +68,12 @@ button.transparent,
[data-theme="dark"] .overflowing::after {
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;
}

View file

@ -8,6 +8,7 @@
let searchQuery = "";
let selectedFile = "modlist-rekindled.json";
let fileList = [];
let loading = true;
let searchQueryInput = (event) => {
clearTimeout(timeout);
@ -37,11 +38,13 @@
}
onMount(async () => {
loading = true;
const response = await fetch("/assets/json/modlist-items.json");
const data = await response.json();
fileList = data;
await fetchData(selectedFile);
checkOverflow();
loading = false;
});
function fuzzySearch(query, mods) {
@ -63,8 +66,10 @@
}
afterUpdate(() => {
loading = true;
removeOverflow();
checkOverflow();
loading = false;
})
</script>
@ -83,7 +88,9 @@
<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>
{:else}
<div class="grid" id="mods">
@ -177,7 +184,8 @@
margin-right: 1em;
border-radius: 8px;
cursor: pointer;
align-self: center;
align-self: flex-start;
margin: 0.5em 1em 0.5em 0;
z-index: 2;
}

View file

@ -1,36 +1,56 @@
<script>
import "../app.scss";
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 { fly } from "svelte/transition";
import { onMount } from "svelte";
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(() => {
function smoothScrollTo(elementId) {
document.getElementById(elementId).scrollIntoView({
behavior: 'smooth'
behavior: "smooth",
});
}
function handleKeydown(elementId, event) {
if (event.key === 'Enter') {
if (event.key === "Enter") {
smoothScrollTo(elementId);
}
}
function toggleTopButton() {
const topButton = document.querySelector('.top-button');
const topButton = document.querySelector(".top-button");
if (window.scrollY >= window.innerHeight) {
topButton.classList.add('show');
topButton.classList.add("show");
} else {
topButton.classList.remove('show');
topButton.classList.remove("show");
}
}
window.addEventListener('scroll', toggleTopButton);
})
window.addEventListener("scroll", toggleTopButton);
});
</script>
<div class="app">

View file

@ -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"
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:
version "1.4.0"
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"