|
12 | 12 | Table |
13 | 13 | } from '@sveltestrap/sveltestrap'; |
14 | 14 | import { _ } from 'svelte-i18n'; |
15 | | - import lodash from "lodash"; |
16 | 15 | import HeadTitle from "$lib/common/HeadTitle.svelte"; |
17 | 16 | import Breadcrumb from '$lib/common/Breadcrumb.svelte'; |
18 | 17 | import TablePagination from '$lib/common/TablePagination.svelte'; |
|
39 | 38 | /** @type {import('$userTypes').UserFilter} */ |
40 | 39 | let filter = { ... initPager }; |
41 | 40 |
|
42 | | - /** @type {import('$commonTypes').PagedItems<import('$userTypes').UserModel>} */ |
43 | | - let users = { count: 0, items: [] }; |
| 41 | + /** @type {import('$userTypes').UserModel[]} */ |
| 42 | + let userItems = []; |
44 | 43 |
|
45 | 44 | /** @type {import('$commonTypes').IdName[]} */ |
46 | 45 | let agents = []; |
|
53 | 52 | }; |
54 | 53 |
|
55 | 54 | onMount(async () => { |
56 | | - await getPagedAgents(); |
57 | | - await getPagedUsers(); |
| 55 | + isLoading = true; |
| 56 | + getPagedAgents().then(() => { |
| 57 | + getPagedUsers().then(() => { |
| 58 | + isLoading = false; |
| 59 | + }); |
| 60 | + }); |
58 | 61 | }); |
59 | 62 |
|
60 | | - async function getPagedUsers() { |
| 63 | + function getPagedUsers() { |
| 64 | + userItems = []; |
61 | 65 | isLoading = true; |
62 | 66 | return new Promise((resolve, reject) => { |
63 | 67 | getUsers(filter).then(res => { |
64 | | - users = res; |
65 | | - refresh(); |
| 68 | + refresh(res); |
66 | 69 | resolve(res); |
67 | 70 | }).finally(() => { |
68 | | - setTimeout(() => { |
69 | | - isLoading = false; |
70 | | - }, 200); |
| 71 | + isLoading = false; |
71 | 72 | }); |
72 | 73 | }); |
73 | 74 | } |
74 | 75 |
|
75 | | - async function getPagedAgents() { |
76 | | - const response = await getAgents({ pager: { page: 1, size: 100, count: 0 } }); |
77 | | - agents = response?.items?.map(x => { |
| 76 | + function getPagedAgents() { |
| 77 | + return new Promise((resolve, reject) => { |
| 78 | + getAgents({ pager: { page: 1, size: 100, count: 0 } }).then(res => { |
| 79 | + agents = res?.items?.map(x => { |
78 | 80 | return { |
79 | 81 | id: x.id, |
80 | 82 | name: x.name |
81 | 83 | }; |
82 | 84 | })?.sort((a, b) => a.name.localeCompare(b.name)) || []; |
| 85 | + resolve(agents); |
| 86 | + }); |
| 87 | + }); |
83 | 88 | } |
84 | 89 |
|
85 | | - function refresh() { |
86 | | - refreshUsers(); |
| 90 | + /** @param {import('$commonTypes').PagedItems<import('$userTypes').UserModel>} users */ |
| 91 | + function refresh(users) { |
| 92 | + refreshUsers(users); |
87 | 93 | refreshPager(users.count, filter.page, filter.size); |
88 | 94 | } |
89 | 95 |
|
90 | | - function refreshUsers() { |
91 | | - users = { |
92 | | - items: users?.items?.map(t => ({ ...t, open_detail: false })) || [], |
93 | | - count: users?.count || 0 |
94 | | - }; |
| 96 | + /** @param {import('$commonTypes').PagedItems<import('$userTypes').UserModel>} users */ |
| 97 | + function refreshUsers(users) { |
| 98 | + userItems = [ ...users.items ]; |
95 | 99 | } |
96 | 100 |
|
97 | 101 | /** @param {number} totalItemsCount */ |
|
157 | 161 |
|
158 | 162 | /** @param {import('$userTypes').UserModel} data */ |
159 | 163 | function postUpdateUser(data) { |
160 | | - const newItems = users?.items?.map(x => { |
| 164 | + userItems = userItems?.map(x => { |
161 | 165 | if (x.id === data.id) { |
162 | 166 | return { ...data, open_detail: true }; |
163 | 167 | } |
164 | 168 | return x; |
165 | 169 | }) || []; |
166 | | - users = { |
167 | | - ...users, |
168 | | - items: newItems |
169 | | - }; |
170 | 170 | } |
171 | 171 | </script> |
172 | 172 |
|
|
239 | 239 | </tr> |
240 | 240 | </thead> |
241 | 241 | <tbody> |
242 | | - {#each users.items as item, idx (idx)} |
| 242 | + {#each userItems as item, idx (idx)} |
243 | 243 | <UserItem |
244 | 244 | item={item} |
245 | 245 | agents={agents} |
|
0 commit comments