feat: improve search experience/autofocus
This commit is contained in:
1 parent
d581884a1e
commit
4f3227a31d
5 files changed
+59
-23
No files matched your search
@@ -231,7 +231,10 @@
|
|||||||
"accounts": "Accounts",
|
"accounts": "Accounts",
|
||||||
"communities": {
|
"communities": {
|
||||||
"title": "Communities",
|
"title": "Communities",
|
||||||
"trending": "Trending"
|
"trending": "Trending",
|
||||||
|
"search": {
|
||||||
|
"placeholder": "Search for a new community"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"search": {
|
"search": {
|
||||||
"title": "Search",
|
"title": "Search",
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
export let id: string = generateID()
|
export let id: string = generateID()
|
||||||
export let inlineAffixes: boolean = false
|
export let inlineAffixes: boolean = false
|
||||||
export let shadow: Shadow = 'none'
|
export let shadow: Shadow = 'none'
|
||||||
|
export let element: HTMLInputElement | undefined = undefined
|
||||||
|
|
||||||
const borderClass = `
|
const borderClass = `
|
||||||
border border-slate-200 border-b-slate-300 dark:border-zinc-900 dark:border-t-zinc-800
|
border border-slate-200 border-b-slate-300 dark:border-zinc-900 dark:border-t-zinc-800
|
||||||
@@ -68,6 +69,7 @@
|
|||||||
{placeholder}
|
{placeholder}
|
||||||
{disabled}
|
{disabled}
|
||||||
bind:value
|
bind:value
|
||||||
|
bind:this={element}
|
||||||
on:input
|
on:input
|
||||||
on:change
|
on:change
|
||||||
on:focus
|
on:focus
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/stores'
|
import { navigating, page } from '$app/stores'
|
||||||
import {
|
import {
|
||||||
GlobeAmericas,
|
GlobeAmericas,
|
||||||
Icon,
|
Icon,
|
||||||
@@ -26,17 +26,28 @@
|
|||||||
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
|
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
|
||||||
import { contentPadding } from '$lib/components/ui/layout/Shell.svelte'
|
import { contentPadding } from '$lib/components/ui/layout/Shell.svelte'
|
||||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||||
|
import { fly } from 'svelte/transition'
|
||||||
|
import { backOut, expoOut } from 'svelte/easing'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
let search = data.query || ''
|
let search = data.query || ''
|
||||||
|
let searchElement: HTMLInputElement
|
||||||
let instance = ''
|
let instance = ''
|
||||||
|
|
||||||
let virtualList: HTMLDivElement
|
let virtualList: HTMLDivElement
|
||||||
let offset: number = 0
|
let offset: number = 0
|
||||||
|
|
||||||
|
$: showTop =
|
||||||
|
(data.query ?? '' != '') && data.communities.length > 0 && data.page == 1
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window bind:scrollY={offset} />
|
<svelte:window
|
||||||
|
bind:scrollY={offset}
|
||||||
|
on:keydown={(e) => {
|
||||||
|
if (e.target == document.body) searchElement?.focus()
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>{$t('routes.communities.title')}</title>
|
<title>{$t('routes.communities.title')}</title>
|
||||||
@@ -83,19 +94,22 @@
|
|||||||
>
|
>
|
||||||
<TextInput
|
<TextInput
|
||||||
bind:value={search}
|
bind:value={search}
|
||||||
|
bind:element={searchElement}
|
||||||
aria-label={$t('routes.search.query')}
|
aria-label={$t('routes.search.query')}
|
||||||
size="lg"
|
size="lg"
|
||||||
class="flex-1 !rounded-full h-full !text-base"
|
class="flex-1 !rounded-full h-full"
|
||||||
|
placeholder={$t('routes.communities.search.placeholder')}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
submit
|
submit
|
||||||
color="secondary"
|
color="primary"
|
||||||
size="custom"
|
size="custom"
|
||||||
class="flex-shrink-0 h-full aspect-square"
|
class="flex-shrink-0 h-full aspect-square"
|
||||||
title="Search"
|
title="Search"
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
|
loading={$navigating != null}
|
||||||
>
|
>
|
||||||
<Icon src={MagnifyingGlass} size="16" mini />
|
<Icon src={MagnifyingGlass} size="16" micro slot="prefix" />
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
@@ -105,7 +119,7 @@
|
|||||||
<Sort selected={data.sort} />
|
<Sort selected={data.sort} />
|
||||||
</div>
|
</div>
|
||||||
<ul
|
<ul
|
||||||
class="flex flex-col divide-y divide-slate-200 dark:divide-zinc-800 my-6 h-full"
|
class="flex flex-col divide-y divide-slate-100 dark:divide-zinc-800 my-6 h-full"
|
||||||
>
|
>
|
||||||
{#if data.communities.length == 0}
|
{#if data.communities.length == 0}
|
||||||
<Placeholder
|
<Placeholder
|
||||||
@@ -115,14 +129,23 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if (data.query ?? '' != '') && data.communities.length > 0}
|
{#if showTop}
|
||||||
<SectionTitle class="!border-0 pb-2">
|
<SectionTitle class="!border-0 pb-2">
|
||||||
{$t('routes.search.top')}
|
{$t('routes.search.top')}
|
||||||
</SectionTitle>
|
</SectionTitle>
|
||||||
<div
|
<div
|
||||||
class="grid md:grid-cols-2 lg:grid-cols-3 gap-4 items-center mb-6 !border-0"
|
class="grid md:grid-cols-2 lg:grid-cols-3 gap-4 items-center mb-6 !border-0"
|
||||||
>
|
>
|
||||||
{#each data.communities.slice(0, 3) as community}
|
{#each data.communities.slice(0, 3) as community, index (community.community.id)}
|
||||||
|
<div
|
||||||
|
class="h-full"
|
||||||
|
in:fly|global={{
|
||||||
|
duration: 1000,
|
||||||
|
easing: expoOut,
|
||||||
|
delay: index < 20 ? index * 100 : 0,
|
||||||
|
y: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Material
|
<Material
|
||||||
color="distinct"
|
color="distinct"
|
||||||
padding="none"
|
padding="none"
|
||||||
@@ -136,22 +159,29 @@
|
|||||||
view="cozy"
|
view="cozy"
|
||||||
/>
|
/>
|
||||||
</Material>
|
</Material>
|
||||||
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if data.communities.slice((data.query ?? '' != '') ? 3 : 0).length > 0}
|
{#if data.communities.slice(showTop ? 3 : 0).length > 0}
|
||||||
<SectionTitle class="!border-0 pb-2">
|
<SectionTitle class="!border-0 pb-2">
|
||||||
{$t('routes.search.other')}
|
{$t('routes.search.other')}
|
||||||
</SectionTitle>
|
</SectionTitle>
|
||||||
{/if}
|
{/if}
|
||||||
{#if data.communities}
|
{#if data.communities}
|
||||||
{@const sliced = data.communities.slice((data.query ?? '' != '') ? 3 : 0)}
|
{@const sliced = data.communities.slice(showTop ? 3 : 0)}
|
||||||
<div class="-mx-4 sm:-mx-6 h-full" bind:this={virtualList}>
|
<div class="-mx-4 sm:-mx-6 h-full" bind:this={virtualList}>
|
||||||
{#each sliced as community}
|
{#each sliced as community, index (community.community.id)}
|
||||||
<div
|
<div
|
||||||
class="px-6 hover:bg-slate-50 hover:dark:bg-zinc-900 transition-colors @container
|
class="px-6 hover:bg-slate-50 hover:dark:bg-zinc-900 transition-colors @container
|
||||||
border-b border-slate-100 dark:border-zinc-800"
|
border-b border-slate-100 dark:border-zinc-800"
|
||||||
|
in:fly|global={{
|
||||||
|
duration: 1000,
|
||||||
|
easing: expoOut,
|
||||||
|
delay: index < 20 ? index * 35 : 0,
|
||||||
|
y: 16,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<CommunityItem {community} showCounts={false} class="py-3" />
|
<CommunityItem {community} showCounts={false} class="py-3" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
<script>
|
|
||||||
import { page } from '$app/stores'
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="text-center">
|
|
||||||
<h1 class="text-4xl font-black">{$page.status}</h1>
|
|
||||||
<span>The search timed out. This is an issue on the server's side.</span>
|
|
||||||
</div>
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/stores'
|
import { navigating, page } from '$app/stores'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
|
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
|
||||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||||
@@ -43,12 +43,19 @@
|
|||||||
export let data
|
export let data
|
||||||
|
|
||||||
let query = data.query || ''
|
let query = data.query || ''
|
||||||
|
let searchElement: HTMLInputElement
|
||||||
|
|
||||||
let pageNum = data.page
|
let pageNum = data.page
|
||||||
|
|
||||||
let moreOptions = false
|
let moreOptions = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:window
|
||||||
|
on:keydown={(e) => {
|
||||||
|
if (e.target == document.body) searchElement?.focus()
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>{$t('routes.search.title')}</title>
|
<title>{$t('routes.search.title')}</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
@@ -68,19 +75,21 @@
|
|||||||
>
|
>
|
||||||
<TextInput
|
<TextInput
|
||||||
bind:value={query}
|
bind:value={query}
|
||||||
|
bind:element={searchElement}
|
||||||
aria-label={$t('routes.search.query')}
|
aria-label={$t('routes.search.query')}
|
||||||
size="lg"
|
size="lg"
|
||||||
class="flex-1 !rounded-full h-full !text-base"
|
class="flex-1 !rounded-full h-full !text-base"
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
submit
|
submit
|
||||||
color="secondary"
|
color="primary"
|
||||||
size="custom"
|
size="custom"
|
||||||
class="flex-shrink-0 h-full aspect-square"
|
class="flex-shrink-0 h-full aspect-square"
|
||||||
title="Search"
|
title="Search"
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
|
loading={$navigating != null}
|
||||||
>
|
>
|
||||||
<Icon src={MagnifyingGlass} size="16" mini />
|
<Icon src={MagnifyingGlass} size="16" micro slot="prefix" />
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|||||||
Reference in new issue
Block a user