mirror of
https://github.com/revanced/revanced-website.git
synced 2025-05-02 07:34:34 +02:00
feat: search debounce
This commit is contained in:
parent
7509a724b3
commit
fc0ce3332a
@ -3,8 +3,19 @@
|
|||||||
export let searchTerm: string | null;
|
export let searchTerm: string | null;
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
import { quintOut } from 'svelte/easing';
|
import { quintOut } from 'svelte/easing';
|
||||||
|
// import { onMount } from 'svelte';
|
||||||
|
|
||||||
|
// let search: HTMLInputElement;
|
||||||
|
|
||||||
|
// function handleKeydown(event) {
|
||||||
|
// if (event.code === 'Slash') {
|
||||||
|
// search.focus;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- <svelte:window on:keydown={handleKeydown} /> -->
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<img src="../icons/search.svg" id="search" alt="Search" />
|
<img src="../icons/search.svg" id="search" alt="Search" />
|
||||||
{#if searchTerm}
|
{#if searchTerm}
|
||||||
@ -17,7 +28,13 @@
|
|||||||
transition:fade|local={{ easing: quintOut, duration: 250 }}
|
transition:fade|local={{ easing: quintOut, duration: 250 }}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
<input type="text" class:clear={searchTerm} placeholder={title} bind:value={searchTerm} />
|
<input
|
||||||
|
type="text"
|
||||||
|
class:clear={searchTerm}
|
||||||
|
placeholder={title}
|
||||||
|
bind:value={searchTerm}
|
||||||
|
on:keyup
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@ -46,7 +63,7 @@
|
|||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
border: 1px solid var(--grey-three);
|
border: 1px solid var(--grey-three);
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
color: var(--grey-five);
|
color: var(--accent-color);
|
||||||
padding-left: 2.5rem;
|
padding-left: 2.5rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
.menu {
|
.menu {
|
||||||
height: calc(100vh - 70px);
|
height: calc(100vh - 60px);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 0px 30px 30px 10px;
|
padding: 0px 30px 30px 10px;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -17,6 +17,13 @@
|
|||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.menu::-webkit-scrollbar-thumb {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
.menu:hover::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--accent-color);
|
||||||
|
}
|
||||||
|
|
||||||
.package-list {
|
.package-list {
|
||||||
margin-top: 0.75rem;
|
margin-top: 0.75rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -15,21 +15,30 @@
|
|||||||
|
|
||||||
let current: boolean = false;
|
let current: boolean = false;
|
||||||
let searchTerm: string;
|
let searchTerm: string;
|
||||||
$: searchTermLowerCase = searchTerm?.toLowerCase();
|
let searchTermFiltered: string;
|
||||||
|
let timeout: any = null;
|
||||||
|
|
||||||
|
const debounce = () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
searchTermFiltered = searchTerm?.replace(/\./g, '').replace(/\s/g, '').replace(/-/g, '').toLowerCase()
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function search(patch: Patch) {
|
function search(patch: Patch) {
|
||||||
function checkPkgName(findTerm: string | boolean, array: any) {
|
function checkPkgName(findTerm: string | boolean, array: any) {
|
||||||
for (let i = 0; i < array.length; i++) {
|
for (let i = 0; i < array.length; i++) {
|
||||||
if (array[i].name.includes(findTerm)) {
|
if (array[i].name.replace(/\./g, '').includes(findTerm)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
patch.description.toLowerCase().includes(searchTermLowerCase) ||
|
patch.description.toLowerCase().replace(/\s/g, '').includes(searchTermFiltered) ||
|
||||||
patch.name.replace(/-/g, ' ').toLowerCase().includes(searchTermLowerCase) ||
|
patch.name.replace(/-/g, '').toLowerCase().includes(searchTermFiltered) ||
|
||||||
checkPkgName(searchTermLowerCase, patch.compatiblePackages)
|
checkPkgName(searchTermFiltered, patch.compatiblePackages)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +61,7 @@
|
|||||||
<main>
|
<main>
|
||||||
<aside in:fly={{ y: 10, easing: quintOut, duration: 750, delay: 100 }}>
|
<aside in:fly={{ y: 10, easing: quintOut, duration: 750, delay: 100 }}>
|
||||||
<TreeMenu title="Search patches...">
|
<TreeMenu title="Search patches...">
|
||||||
<Search bind:searchTerm title="Search patches" />
|
<Search bind:searchTerm title="Search patches" on:keyup={debounce} />
|
||||||
<span>
|
<span>
|
||||||
{#each packages as pkg}
|
{#each packages as pkg}
|
||||||
<TreeMenuButton bind:current name={pkg} />
|
<TreeMenuButton bind:current name={pkg} />
|
||||||
@ -63,7 +72,7 @@
|
|||||||
|
|
||||||
<div class="patches-container">
|
<div class="patches-container">
|
||||||
{#each patches as patch}
|
{#each patches as patch}
|
||||||
{#key current || searchTerm}
|
{#key current || searchTermFiltered}
|
||||||
{#if filterByPackage(current, patch.compatiblePackages) || !current}
|
{#if filterByPackage(current, patch.compatiblePackages) || !current}
|
||||||
{#if search(patch) || !searchTerm}
|
{#if search(patch) || !searchTerm}
|
||||||
<div in:fly={{ x: 10, easing: quintOut, duration: 750, delay: 100 }}>
|
<div in:fly={{ x: 10, easing: quintOut, duration: 750, delay: 100 }}>
|
||||||
@ -91,7 +100,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.patches-container {
|
.patches-container {
|
||||||
margin-top: 6rem;
|
margin-top: 6.7rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user