Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Commit 1c7ace6

Browse files
committed
Providers drop down in search users
1 parent 5147625 commit 1c7ace6

1 file changed

Lines changed: 125 additions & 3 deletions

File tree

‎src/lib/components/UserSearchPickerWidget.svelte‎

Lines changed: 125 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,31 @@
3939
let searchType = $state<"email" | "userid" | "username">("username");
4040
let debounceTimer: number | null = null;
4141
42+
// Provider dropdown state
43+
let providers = $state<string[]>([]);
44+
let selectedProvider = $state("");
45+
let isLoadingProviders = $state(false);
46+
47+
// Fetch providers on mount
48+
$effect(() => {
49+
fetchProviders();
50+
});
51+
52+
async function fetchProviders() {
53+
isLoadingProviders = true;
54+
try {
55+
const response = await trackedFetch("/api/users/providers");
56+
if (response.ok) {
57+
const data = await response.json();
58+
providers = data.providers || [];
59+
}
60+
} catch (error) {
61+
console.error("Failed to fetch providers:", error);
62+
} finally {
63+
isLoadingProviders = false;
64+
}
65+
}
66+
4267
// Detect search type based on input
4368
function detectSearchType(input: string): "email" | "userid" | "username" {
4469
if (input.includes("@") && input.includes(".")) {
@@ -80,10 +105,15 @@
80105
81106
try {
82107
let url: string;
108+
let usesProviderEndpoint = false;
83109
if (type === "email") {
84110
url = `/api/users/search-by-email?email=${encodeURIComponent(trimmed)}`;
85111
} else if (type === "userid") {
86112
url = `/api/users/search-by-userid?user_id=${encodeURIComponent(trimmed)}`;
113+
} else if (selectedProvider) {
114+
// Use provider+username endpoint when a provider is selected
115+
url = `/api/users/search-by-provider-username?provider=${encodeURIComponent(selectedProvider)}&username=${encodeURIComponent(trimmed)}`;
116+
usesProviderEndpoint = true;
87117
} else {
88118
url = `/api/users/search?q=${encodeURIComponent(trimmed)}`;
89119
}
@@ -103,9 +133,9 @@
103133
104134
const data = await response.json();
105135
106-
// Normalize response: userid endpoint returns {user: {...}}, others return {users: [...]}
136+
// Normalize response: provider and userid endpoints return {user: {...}}, others return {users: [...]}
107137
let users: UserResult[];
108-
if (type === "userid") {
138+
if (type === "userid" || usesProviderEndpoint) {
109139
users = data.user ? [data.user] : [];
110140
} else {
111141
users = data.users || [];
@@ -176,6 +206,7 @@
176206
searchResults = [];
177207
showResults = false;
178208
searchError = "";
209+
selectedProvider = "";
179210
}
180211
181212
function handleBlur() {
@@ -188,6 +219,30 @@
188219

189220
<div class="user-search-widget">
190221
<div class="search-container">
222+
<div class="provider-row">
223+
<label class="provider-label" for="provider-select">Provider</label>
224+
<select
225+
id="provider-select"
226+
class="provider-select"
227+
bind:value={selectedProvider}
228+
{disabled}
229+
onchange={() => {
230+
// Re-trigger search if there's already a query
231+
if (searchQuery.trim()) {
232+
searchUsers(searchQuery);
233+
}
234+
}}
235+
>
236+
<option value="">Any provider</option>
237+
{#each providers as provider}
238+
<option value={provider}>{provider}</option>
239+
{/each}
240+
</select>
241+
{#if isLoadingProviders}
242+
<span class="provider-loading">Loading...</span>
243+
{/if}
244+
</div>
245+
191246
<div class="search-input-wrapper">
192247
<Search class="search-icon" size={18} />
193248
<input
@@ -219,7 +274,11 @@
219274

220275
{#if searchQuery.trim() && !selectedUserId}
221276
<div class="search-type-indicator">
222-
{searchTypeLabels[searchType]}
277+
{#if selectedProvider && searchType === "username"}
278+
Searching by provider ({selectedProvider}) + username
279+
{:else}
280+
{searchTypeLabels[searchType]}
281+
{/if}
223282
</div>
224283
{/if}
225284

@@ -280,6 +339,69 @@
280339
flex-direction: column;
281340
}
282341
342+
.provider-row {
343+
display: flex;
344+
align-items: center;
345+
gap: 0.5rem;
346+
margin-bottom: 0.5rem;
347+
}
348+
349+
.provider-label {
350+
font-size: 0.75rem;
351+
font-weight: 600;
352+
color: #6b7280;
353+
white-space: nowrap;
354+
}
355+
356+
:global([data-mode="dark"]) .provider-label {
357+
color: var(--color-surface-400);
358+
}
359+
360+
.provider-select {
361+
flex: 1;
362+
padding: 0.5rem 0.75rem;
363+
border: 1px solid #d1d5db;
364+
border-radius: 6px;
365+
font-size: 0.8rem;
366+
background: white;
367+
color: #374151;
368+
transition: all 0.2s;
369+
cursor: pointer;
370+
}
371+
372+
.provider-select:focus {
373+
outline: none;
374+
border-color: #667eea;
375+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
376+
}
377+
378+
.provider-select:disabled {
379+
background: #f9fafb;
380+
cursor: not-allowed;
381+
opacity: 0.6;
382+
}
383+
384+
:global([data-mode="dark"]) .provider-select {
385+
background: rgb(var(--color-surface-700));
386+
border-color: rgb(var(--color-surface-600));
387+
color: var(--color-surface-100);
388+
}
389+
390+
:global([data-mode="dark"]) .provider-select:focus {
391+
border-color: rgb(var(--color-primary-500));
392+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
393+
}
394+
395+
:global([data-mode="dark"]) .provider-select:disabled {
396+
background: rgb(var(--color-surface-800));
397+
}
398+
399+
.provider-loading {
400+
font-size: 0.7rem;
401+
color: #9ca3af;
402+
font-style: italic;
403+
}
404+
283405
.search-input-wrapper {
284406
position: relative;
285407
display: flex;

0 commit comments

Comments
 (0)