Skip to content

Commit

Permalink
Merge pull request #116 from aurelienrichard:privelte
Browse files Browse the repository at this point in the history
autofocus input fields on page load to improve ux
  • Loading branch information
aurelienrichard committed May 15, 2024
2 parents e935428 + 7cdd58f commit 991c863
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 55 deletions.
12 changes: 8 additions & 4 deletions apps/privelte/src/lib/components/Chat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@
</script>

<div class="absolute left-0 top-0 h-full w-full space-y-4 overflow-y-auto overflow-x-clip px-4">
<h1 class="h2 text-surface-600-300-token mb-3 text-center leading-snug md:mb-6">
You're all
<h1 class="h3 text-surface-600-300-token mb-3 text-center leading-snug md:mb-6">
Share the link
<span
class="dark:from-gradient-1-dark dark:to-gradient-2-dark from-gradient-1-light to-gradient-2-light bg-gradient-to-br box-decoration-clone bg-clip-text capitalize text-transparent"
>set</span
>below</span
>
to invite
<span
class="dark:from-gradient-1-dark dark:to-gradient-2-dark from-gradient-1-light to-gradient-2-light bg-gradient-to-br box-decoration-clone bg-clip-text capitalize text-transparent"
>participants</span
>.
</h1>
<p class="text-center text-lg md:text-xl">Share the link below to invite participants.</p>
<Clipboard url={$page.url} />
<hr class="my-4" />
<div class="text-surface-600-300-token">
Expand Down
8 changes: 2 additions & 6 deletions apps/privelte/src/lib/components/Chat.svelte.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import type { Payload, Presence } from '$lib/types/types'
describe('Chat component', () => {
const userId = '1'

test('should render', () => {
render(Chat, { userId, entries: [], subscribed: 'ok' })
})

test('should render share link message and clipboard component', () => {
const { getByText, getByRole } = render(Chat, { userId, entries: [], subscribed: 'ok' })
const { getByRole } = render(Chat, { userId, entries: [], subscribed: 'ok' })

expect(getByText('Share the link below to invite participants.')).toBeInTheDocument()
expect(getByRole('heading', { level: 1 })).toBeInTheDocument()
expect(getByRole('button', { name: 'Copy to clipboard.' })).toBeInTheDocument()
})

Expand Down
4 changes: 0 additions & 4 deletions apps/privelte/src/lib/components/Message.svelte.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ describe('Message component', () => {
id: '2'
}

test('should render', () => {
render(Message, { payload, status: 'success', isOwnMessage: false })
})

test('should display the message and username', () => {
const { getByText } = render(Message, { payload, status: 'success', isOwnMessage: false })

Expand Down
6 changes: 5 additions & 1 deletion apps/privelte/src/lib/components/NewMessageForm.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { createEventDispatcher, afterUpdate } from 'svelte'
import { createEventDispatcher, afterUpdate, onMount } from 'svelte'
import { nanoid } from 'nanoid'
export let roomId: string
Expand All @@ -18,6 +18,10 @@
}
}
onMount(() => {
textarea.focus()
})
afterUpdate(() => {
setHeight()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import NewMessageForm from './NewMessageForm.svelte'
describe('New message form component', () => {
const props = { roomId: '1' }

test('should render', () => {
render(NewMessageForm, props)
})

test('should display placeholder text', () => {
const { getByPlaceholderText } = render(NewMessageForm, props)

Expand Down
81 changes: 45 additions & 36 deletions apps/privelte/src/routes/room/[id]/join/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
<script lang="ts">
import { ProgressRadial } from '@skeletonlabs/skeleton'
import { onMount } from 'svelte'
import { enhance } from '$app/forms'
import type { SubmitFunction } from './$types'
let loading = false
let input: HTMLInputElement
const handleSubmit: SubmitFunction = () => {
loading = true
return async ({ update }) => {
await update()
loading = false
}
}
onMount(() => {
input.focus()
})
</script>

<div class="mb-8 text-center md:mb-12">
Expand All @@ -22,44 +29,46 @@
>username</span
>.
</h1>
<p class="md:text-xl">
It will be exclusive to this room and serve only as a display name for the messages you
send.
</p>
<p class="md:text-xl">Usernames are exclusive to each room.</p>
</div>

<form method="POST" use:enhance={handleSubmit}>
<label class="label capitalize">
<span>username</span>
<div
class="input-group input-group-divider [&_input]:bg-surface-100-800-token dark:focus-within:border-primary-500 grid-cols-[1fr_auto] focus-within:border-indigo-500"
<div
class="input-group input-group-divider [&_input]:bg-surface-100-800-token dark:focus-within:border-primary-500 grid-cols-[1fr_auto] focus-within:border-indigo-500"
>
<input
bind:this={input}
type="text"
name="username"
minlength="3"
maxlength="20"
placeholder="Username"
required
/>
<button
type="submit"
class="btn dark:variant-soft-tertiary variant-soft-surface rounded-l-none"
title="Let's chat!"
disabled={loading}
>
<input type="text" name="username" minlength="3" maxlength="20" required />
<button
type="submit"
class="btn dark:variant-soft-tertiary variant-soft-surface rounded-l-none"
title="Let's chat!"
disabled={loading}
>
{#if loading}
<ProgressRadial width="w-6" />
{:else}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m12.75 15 3-3m0 0-3-3m3 3h-7.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
/>
</svg>
{/if}
</button>
</div>
</label>
{#if loading}
<ProgressRadial width="w-6" />
{:else}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m12.75 15 3-3m0 0-3-3m3 3h-7.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
/>
</svg>
{/if}
</button>
</div>
</form>

0 comments on commit 991c863

Please sign in to comment.