Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions site/src/pages/WorkspacesPage/filter/autocompletes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useQuery } from "@tanstack/react-query"
import { getTemplates, getUsers } from "api/api"
import { WorkspaceStatuses } from "api/typesGenerated"
import { getDisplayWorkspaceStatus } from "utils/workspace"
import { useMe } from "hooks"

type UseAutocompleteOptions<TOption extends BaseOption> = {
id: string
Expand Down Expand Up @@ -50,7 +51,7 @@ const useAutocomplete = <TOption extends BaseOption = BaseOption>({
})
const selectedOption = selectedOptionQuery.data
const searchOptionsQuery = useQuery({
queryKey: [id, "autocomplete", "search"],
queryKey: [id, "autocomplete", "search", query],
queryFn: () => getOptions(query),
enabled,
})
Expand Down Expand Up @@ -114,8 +115,18 @@ export const useUsersAutocomplete = (
value: string | undefined,
onChange: (option: OwnerOption | undefined) => void,
enabled?: boolean,
) =>
useAutocomplete({
) => {
const me = useMe()

const addMeAsFirstOption = (options: OwnerOption[]) => {
options = options.filter((option) => option.value !== me.username)
return [
{ label: me.username, value: me.username, avatarUrl: me.avatar_url },
...options,
]
}

return useAutocomplete({
onChange,
enabled,
value,
Expand All @@ -134,13 +145,16 @@ export const useUsersAutocomplete = (
},
getOptions: async (query) => {
const usersRes = await getUsers({ q: query, limit: 25 })
return usersRes.users.map((user) => ({
let options: OwnerOption[] = usersRes.users.map((user) => ({
label: user.username,
value: user.username,
avatarUrl: user.avatar_url,
}))
options = addMeAsFirstOption(options)
return options
},
})
}

export type UsersAutocomplete = ReturnType<typeof useUsersAutocomplete>

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy