|
39 | 39 | let searchType = $state<"email" | "userid" | "username">("username"); |
40 | 40 | let debounceTimer: number | null = null; |
41 | 41 |
|
| 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 | +
|
42 | 67 | // Detect search type based on input |
43 | 68 | function detectSearchType(input: string): "email" | "userid" | "username" { |
44 | 69 | if (input.includes("@") && input.includes(".")) { |
|
80 | 105 |
|
81 | 106 | try { |
82 | 107 | let url: string; |
| 108 | + let usesProviderEndpoint = false; |
83 | 109 | if (type === "email") { |
84 | 110 | url = `/api/users/search-by-email?email=${encodeURIComponent(trimmed)}`; |
85 | 111 | } else if (type === "userid") { |
86 | 112 | 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; |
87 | 117 | } else { |
88 | 118 | url = `/api/users/search?q=${encodeURIComponent(trimmed)}`; |
89 | 119 | } |
|
103 | 133 |
|
104 | 134 | const data = await response.json(); |
105 | 135 |
|
106 | | - // Normalize response: userid endpoint returns {user: {...}}, others return {users: [...]} |
| 136 | + // Normalize response: provider and userid endpoints return {user: {...}}, others return {users: [...]} |
107 | 137 | let users: UserResult[]; |
108 | | - if (type === "userid") { |
| 138 | + if (type === "userid" || usesProviderEndpoint) { |
109 | 139 | users = data.user ? [data.user] : []; |
110 | 140 | } else { |
111 | 141 | users = data.users || []; |
|
176 | 206 | searchResults = []; |
177 | 207 | showResults = false; |
178 | 208 | searchError = ""; |
| 209 | + selectedProvider = ""; |
179 | 210 | } |
180 | 211 |
|
181 | 212 | function handleBlur() { |
|
188 | 219 |
|
189 | 220 | <div class="user-search-widget"> |
190 | 221 | <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 | + |
191 | 246 | <div class="search-input-wrapper"> |
192 | 247 | <Search class="search-icon" size={18} /> |
193 | 248 | <input |
|
219 | 274 |
|
220 | 275 | {#if searchQuery.trim() && !selectedUserId} |
221 | 276 | <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} |
223 | 282 | </div> |
224 | 283 | {/if} |
225 | 284 |
|
|
280 | 339 | flex-direction: column; |
281 | 340 | } |
282 | 341 |
|
| 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 | +
|
283 | 405 | .search-input-wrapper { |
284 | 406 | position: relative; |
285 | 407 | display: flex; |
|
0 commit comments