mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-03 14:38:50 +00:00
feat(web): ability to search resources
This commit is contained in:
1 parent
4cbcd57a8a
commit
9c8bb33c4a
3 files changed
+28
-4
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let icon: ConstructorOfATypedSvelteComponent;
|
export let icon: ConstructorOfATypedSvelteComponent;
|
||||||
|
export let value: string;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -8,5 +9,5 @@
|
|||||||
<div class="pr-2">
|
<div class="pr-2">
|
||||||
<svelte:component this={icon} />
|
<svelte:component this={icon} />
|
||||||
</div>
|
</div>
|
||||||
<input type="text" class="bg-transparent outline-none w-full" placeholder="Search resources..." />
|
<input type="text" bind:value class="bg-transparent outline-none w-full" placeholder="Search resources..." />
|
||||||
</div>
|
</div>
|
||||||
@@ -2,8 +2,9 @@
|
|||||||
import Input from '../../components/Input.svelte';
|
import Input from '../../components/Input.svelte';
|
||||||
import { IconSearch } from '@tabler/icons-svelte';
|
import { IconSearch } from '@tabler/icons-svelte';
|
||||||
import { router } from 'tinro';
|
import { router } from 'tinro';
|
||||||
|
import { search, filteredResources, resources } from '../../store';
|
||||||
|
|
||||||
const resources = [
|
$resources = [
|
||||||
'ox_core',
|
'ox_core',
|
||||||
'oxmysql',
|
'oxmysql',
|
||||||
'ox_inventory',
|
'ox_inventory',
|
||||||
@@ -25,10 +26,10 @@
|
|||||||
<div class="bg-dark-700 p-4 pr-0 flex flex-col w-2/3 rounded-md">
|
<div class="bg-dark-700 p-4 pr-0 flex flex-col w-2/3 rounded-md">
|
||||||
<div class="pr-4">
|
<div class="pr-4">
|
||||||
<p class="text-2xl mb-4">Resources</p>
|
<p class="text-2xl mb-4">Resources</p>
|
||||||
<Input icon={IconSearch} />
|
<Input icon={IconSearch} bind:value={$search} />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-3 mt-6 overflow-y-auto pr-4">
|
<div class="flex flex-col gap-3 mt-6 overflow-y-auto pr-4">
|
||||||
{#each resources as resource}
|
{#each $filteredResources as resource}
|
||||||
<button
|
<button
|
||||||
on:click={() => router.goto(`/${resource}`)}
|
on:click={() => router.goto(`/${resource}`)}
|
||||||
class="bg-dark-600 p-3 text-left hover:bg-dark-400 rounded-md"
|
class="bg-dark-600 p-3 text-left hover:bg-dark-400 rounded-md"
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { derived, writable } from 'svelte/store';
|
||||||
|
|
||||||
|
export const search = writable('');
|
||||||
|
|
||||||
|
let timeout: NodeJS.Timeout;
|
||||||
|
export const debouncedSearch = derived(search, (value, set: (value: string) => void) => {
|
||||||
|
timeout = setTimeout(() => set(value), 500);
|
||||||
|
return () => clearTimeout(timeout);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const resources = writable<string[]>([]);
|
||||||
|
|
||||||
|
export const filteredResources = derived(
|
||||||
|
[resources, debouncedSearch],
|
||||||
|
([$resources, $debouncedSearch], set: (value: string[]) => void) => {
|
||||||
|
if ($debouncedSearch === '' || !$debouncedSearch) return set($resources);
|
||||||
|
|
||||||
|
const query = $debouncedSearch.toLowerCase();
|
||||||
|
|
||||||
|
return set($resources.filter((resource) => resource.toLowerCase().includes(query)));
|
||||||
|
}
|
||||||
|
);
|
||||||
Reference in new issue
Block a user