@@ -9,6 +9,7 @@ import { useQuery } from "@tanstack/react-query"
9
9
import { getTemplates , getUsers } from "api/api"
10
10
import { WorkspaceStatuses } from "api/typesGenerated"
11
11
import { getDisplayWorkspaceStatus } from "utils/workspace"
12
+ import { useMe } from "hooks"
12
13
13
14
type UseAutocompleteOptions < TOption extends BaseOption > = {
14
15
id : string
@@ -50,7 +51,7 @@ const useAutocomplete = <TOption extends BaseOption = BaseOption>({
50
51
} )
51
52
const selectedOption = selectedOptionQuery . data
52
53
const searchOptionsQuery = useQuery ( {
53
- queryKey : [ id , "autocomplete" , "search" ] ,
54
+ queryKey : [ id , "autocomplete" , "search" , query ] ,
54
55
queryFn : ( ) => getOptions ( query ) ,
55
56
enabled,
56
57
} )
@@ -114,8 +115,18 @@ export const useUsersAutocomplete = (
114
115
value : string | undefined ,
115
116
onChange : ( option : OwnerOption | undefined ) => void ,
116
117
enabled ?: boolean ,
117
- ) =>
118
- useAutocomplete ( {
118
+ ) => {
119
+ const me = useMe ( )
120
+
121
+ const addMeAsFirstOption = ( options : OwnerOption [ ] ) => {
122
+ options = options . filter ( ( option ) => option . value !== me . username )
123
+ return [
124
+ { label : me . username , value : me . username , avatarUrl : me . avatar_url } ,
125
+ ...options ,
126
+ ]
127
+ }
128
+
129
+ return useAutocomplete ( {
119
130
onChange,
120
131
enabled,
121
132
value,
@@ -134,13 +145,16 @@ export const useUsersAutocomplete = (
134
145
} ,
135
146
getOptions : async ( query ) => {
136
147
const usersRes = await getUsers ( { q : query , limit : 25 } )
137
- return usersRes . users . map ( ( user ) => ( {
148
+ let options : OwnerOption [ ] = usersRes . users . map ( ( user ) => ( {
138
149
label : user . username ,
139
150
value : user . username ,
140
151
avatarUrl : user . avatar_url ,
141
152
} ) )
153
+ options = addMeAsFirstOption ( options )
154
+ return options
142
155
} ,
143
156
} )
157
+ }
144
158
145
159
export type UsersAutocomplete = ReturnType < typeof useUsersAutocomplete >
146
160
0 commit comments