-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve source selection UX #6766
Changes from 3 commits
6615151
08a0416
f99fa3a
5ec31b8
60dc45e
9756b35
d6c1e93
838a16f
352f714
9feb0cc
dc1526f
8681c41
b0be967
94f2d51
8bbc7ed
5d24f01
8e7426d
d5dec81
e44d909
c9ed31a
bf95184
0397497
3cdad9e
a823d4f
216b9e9
c6689d0
b8c695a
81ca4a4
e64cf2b
f28633e
87d3b61
7f75408
59a64da
b6d8f54
1a98513
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,22 +1,30 @@ | ||||||
<script lang="ts"> | ||||||
import { Microphone, Upload, Video } from "@gradio/icons"; | ||||||
import { Microphone, Upload, Webcam, ImagePaste } from "@gradio/icons"; | ||||||
|
||||||
export let sources: string[]; | ||||||
export let active_source: string; | ||||||
type sources = "upload" | "microphone" | "webcam" | "clipboard" | null; | ||||||
|
||||||
export let sources: Partial<sources>[]; | ||||||
export let active_source: Partial<sources>; | ||||||
export let handle_clear: () => void = () => {}; | ||||||
export let handle_select: (source_type: Partial<sources>) => void = () => {}; | ||||||
|
||||||
let unique_sources = [...new Set(sources)]; | ||||||
hannahblair marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not reactive, right?
Suggested change
(not completely sure if this deduplication logic is even necessary tbh? no particular strong feelnig about it tho) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops! Thanks. Yeah it is needed - e.g. passing |
||||||
|
||||||
async function handle_select_source(source: Partial<sources>): Promise<void> { | ||||||
handle_clear(); | ||||||
active_source = source; | ||||||
handle_select(source); | ||||||
} | ||||||
</script> | ||||||
|
||||||
{#if sources.length > 1} | ||||||
{#if unique_sources.length > 1} | ||||||
<span class="source-selection" data-testid="source-select"> | ||||||
{#if sources.includes("upload")} | ||||||
<button | ||||||
class="icon" | ||||||
class:selected={active_source === "upload"} | ||||||
class:selected={active_source === "upload" || !active_source} | ||||||
aria-label="Upload file" | ||||||
on:click={() => { | ||||||
handle_clear(); | ||||||
active_source = "upload"; | ||||||
}}><Upload /></button | ||||||
on:click={() => handle_select_source("upload")}><Upload /></button | ||||||
> | ||||||
{/if} | ||||||
|
||||||
|
@@ -25,10 +33,8 @@ | |||||
class="icon" | ||||||
class:selected={active_source === "microphone"} | ||||||
aria-label="Record audio" | ||||||
on:click={() => { | ||||||
handle_clear(); | ||||||
active_source = "microphone"; | ||||||
}}><Microphone /></button | ||||||
on:click={() => handle_select_source("microphone")} | ||||||
><Microphone /></button | ||||||
> | ||||||
{/if} | ||||||
|
||||||
|
@@ -37,10 +43,16 @@ | |||||
class="icon" | ||||||
class:selected={active_source === "webcam"} | ||||||
aria-label="Record video" | ||||||
on:click={() => { | ||||||
handle_clear(); | ||||||
active_source = "webcam"; | ||||||
}}><Video /></button | ||||||
on:click={() => handle_select_source("webcam")}><Webcam /></button | ||||||
> | ||||||
{/if} | ||||||
{#if sources.includes("clipboard")} | ||||||
<button | ||||||
class="icon" | ||||||
class:selected={active_source === "clipboard"} | ||||||
aria-label="Paste from clipboard" | ||||||
on:click={() => handle_select_source("clipboard")} | ||||||
><ImagePaste /></button | ||||||
> | ||||||
{/if} | ||||||
</span> | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the use of Partial here and throughout this file? I don't believe it makes a difference in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also would name the type differently if we also have a variable called sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial is needed because the
SelectSource
is used in Video, Audio and Image andsources[]
isn't the same for them all - e.g.microphone
isn't used by Image