Skip to content

Commit 706b278

Browse files
committed
fixup!
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent d6bf698 commit 706b278

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

apps/settings/src/components/AppNavigationGroupList.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
</template>
6363

6464
<script setup lang="ts">
65-
import type CancelablePromise from 'cancelable-promise'
6665
import type { IGroup } from '../views/user-types.d.ts'
6766
6867
import { mdiAccountGroupOutline, mdiPlus } from '@mdi/js'
@@ -154,8 +153,8 @@ watch(groupsSearchQuery, async () => {
154153
await loadGroups()
155154
})
156155
157-
/** Cancelable promise for search groups request */
158-
const promise = ref<CancelablePromise<IGroup[]>>()
156+
let abortController: AbortController = new AbortController()
157+
const promise = ref<Promise<IGroup[]>>()
159158
160159
/**
161160
* Load groups
@@ -166,14 +165,17 @@ async function loadGroups() {
166165
}
167166
168167
if (promise.value) {
169-
promise.value.cancel()
168+
abortController.abort()
170169
}
170+
171171
loadingGroups.value = true
172172
try {
173+
abortController = new AbortController()
173174
promise.value = searchGroups({
174175
search: groupsSearchQuery.value,
175176
offset: offset.value,
176177
limit: 25,
178+
signal: abortController.signal,
177179
})
178180
const groups = await promise.value
179181
if (groups.length > 0) {

apps/settings/src/components/Users/NewUserDialog.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export default {
199199
// TRANSLATORS This string describes a manager in the context of an organization
200200
managerLabel: t('settings', 'Set line manager'),
201201
// Cancelable promise for search groups request
202+
controller: new AbortController(),
202203
promise: null,
203204
}
204205
},
@@ -296,14 +297,16 @@ export default {
296297
}
297298
298299
if (this.promise) {
299-
this.promise.cancel()
300+
this.controller.abort()
300301
}
301302
toggleLoading(true)
302303
try {
304+
this.controller = new AbortController()
303305
this.promise = searchGroups({
304306
search: query,
305307
offset: 0,
306308
limit: 25,
309+
signal: this.controller.signal,
307310
})
308311
const groups = await this.promise
309312
// Populate store from server request

apps/settings/src/components/Users/UserRow.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ export default {
416416
editedPassword: '',
417417
editedMail: this.user.email ?? '',
418418
// Cancelable promise for search groups request
419+
controller: new AbortController(),
419420
promise: null,
420421
}
421422
},
@@ -654,14 +655,16 @@ export default {
654655
return // Prevent unexpected search behaviour e.g. on option:created
655656
}
656657
if (this.promise) {
657-
this.promise.cancel()
658+
this.controller.abort()
658659
}
659660
toggleLoading(true)
660661
try {
662+
this.controller = new AbortController()
661663
this.promise = await searchGroups({
662664
search: query,
663665
offset: 0,
664666
limit: 25,
667+
signal: this.controller.signal,
665668
})
666669
const groups = await this.promise
667670
// Populate store from server request

apps/settings/src/service/groups.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { IGroup } from '../views/user-types.d.ts'
77

88
import axios from '@nextcloud/axios'
99
import { generateOcsUrl } from '@nextcloud/router'
10-
import { CancelablePromise } from 'cancelable-promise'
1110

1211
interface Group {
1312
id: string
@@ -33,29 +32,29 @@ function formatGroup(group: Group): Required<IGroup> {
3332
}
3433
}
3534

35+
interface SearchGroupOptions {
36+
search: string
37+
offset: number
38+
limit: number
39+
signal?: AbortSignal
40+
}
41+
3642
/**
3743
* Search groups
3844
*
3945
* @param options Options
4046
* @param options.search Search query
4147
* @param options.offset Offset
4248
* @param options.limit Limit
49+
* @param options.signal Abort signal
4350
*/
44-
export function searchGroups({ search, offset, limit }): CancelablePromise<Required<IGroup>[]> {
45-
const controller = new AbortController()
46-
return new CancelablePromise(async (resolve, reject, onCancel) => {
47-
onCancel(() => controller.abort())
48-
try {
49-
const { data } = await axios.get(generateOcsUrl('/cloud/groups/details?search={search}&offset={offset}&limit={limit}', { search, offset, limit }), {
50-
signal: controller.signal,
51-
})
52-
const groups: Group[] = data.ocs?.data?.groups ?? []
53-
const formattedGroups = groups.map(formatGroup)
54-
resolve(formattedGroups)
55-
} catch (error) {
56-
reject(error)
57-
}
51+
export async function searchGroups({ search, offset, limit, signal }: SearchGroupOptions): Promise<Required<IGroup>[]> {
52+
const { data } = await axios.get(generateOcsUrl('/cloud/groups/details?search={search}&offset={offset}&limit={limit}', { search, offset, limit }), {
53+
signal,
5854
})
55+
const groups: Group[] = data.ocs?.data?.groups ?? []
56+
const formattedGroups = groups.map(formatGroup)
57+
return formattedGroups
5958
}
6059

6160
/**

0 commit comments

Comments
 (0)