fix(ui): stop the chat input attach menus from fetching twice on open (#27461)
This commit is contained in:
4 files changed
+25
-14
No files matched your search
@@ -25,11 +25,13 @@
|
|||||||
let itemsLoading = false;
|
let itemsLoading = false;
|
||||||
let allItemsLoaded = false;
|
let allItemsLoaded = false;
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
|
let searchedQuery = '';
|
||||||
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
||||||
let requestId = 0;
|
let requestId = 0;
|
||||||
|
|
||||||
$: if (initialized) {
|
// Only re-run the search when the query actually changes. Flipping `initialized`
|
||||||
query;
|
// after the initial load would otherwise trigger a second, identical request.
|
||||||
|
$: if (initialized && query !== searchedQuery) {
|
||||||
scheduleSearch();
|
scheduleSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +42,7 @@
|
|||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
requestId += 1;
|
requestId += 1;
|
||||||
|
searchedQuery = query;
|
||||||
page = 1;
|
page = 1;
|
||||||
items = [];
|
items = [];
|
||||||
selectedIdx = 0;
|
selectedIdx = 0;
|
||||||
|
|||||||
@@ -23,11 +23,13 @@
|
|||||||
let itemsLoading = false;
|
let itemsLoading = false;
|
||||||
let allItemsLoaded = false;
|
let allItemsLoaded = false;
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
|
let searchedQuery = '';
|
||||||
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
||||||
let requestId = 0;
|
let requestId = 0;
|
||||||
|
|
||||||
$: if (initialized) {
|
// Only re-run the search when the query actually changes. Flipping `initialized`
|
||||||
query;
|
// after the initial load would otherwise trigger a second, identical request.
|
||||||
|
$: if (initialized && query !== searchedQuery) {
|
||||||
scheduleSearch();
|
scheduleSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +40,7 @@
|
|||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
requestId += 1;
|
requestId += 1;
|
||||||
|
searchedQuery = query;
|
||||||
page = 0;
|
page = 0;
|
||||||
items = [];
|
items = [];
|
||||||
selectedIdx = 0;
|
selectedIdx = 0;
|
||||||
|
|||||||
@@ -100,11 +100,13 @@
|
|||||||
let itemsLoading = false;
|
let itemsLoading = false;
|
||||||
let allItemsLoaded = false;
|
let allItemsLoaded = false;
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
|
let searchedQuery = '';
|
||||||
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
||||||
let requestId = 0;
|
let requestId = 0;
|
||||||
|
|
||||||
$: if (initialized) {
|
// Only re-run the search when the query actually changes. Flipping `initialized`
|
||||||
query;
|
// after the initial load would otherwise trigger a second, identical request.
|
||||||
|
$: if (initialized && query !== searchedQuery) {
|
||||||
scheduleSearch();
|
scheduleSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,6 +117,7 @@
|
|||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
requestId += 1;
|
requestId += 1;
|
||||||
|
searchedQuery = query;
|
||||||
reset();
|
reset();
|
||||||
selectedItem = null;
|
selectedItem = null;
|
||||||
await tick();
|
await tick();
|
||||||
@@ -151,12 +154,6 @@
|
|||||||
total = res.total;
|
total = res.total;
|
||||||
const pageItems = res.items;
|
const pageItems = res.items;
|
||||||
|
|
||||||
if ((pageItems ?? []).length === 0) {
|
|
||||||
allItemsLoaded = true;
|
|
||||||
} else {
|
|
||||||
allItemsLoaded = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (items) {
|
if (items) {
|
||||||
const existingIds = new Set(items.map((item) => item.id));
|
const existingIds = new Set(items.map((item) => item.id));
|
||||||
const newItems = pageItems.filter((item) => !existingIds.has(item.id));
|
const newItems = pageItems.filter((item) => !existingIds.has(item.id));
|
||||||
@@ -164,6 +161,11 @@
|
|||||||
} else {
|
} else {
|
||||||
items = pageItems;
|
items = pageItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The response reports the full count, so the end of the list is known without
|
||||||
|
// probing for an empty page - otherwise a list shorter than one page would
|
||||||
|
// immediately request the next one.
|
||||||
|
allItemsLoaded = (pageItems ?? []).length === 0 || items.length >= (total ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
itemsLoading = false;
|
itemsLoading = false;
|
||||||
|
|||||||
@@ -25,11 +25,13 @@
|
|||||||
let itemsLoading = false;
|
let itemsLoading = false;
|
||||||
let allItemsLoaded = false;
|
let allItemsLoaded = false;
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
|
let searchedQuery = '';
|
||||||
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
||||||
let requestId = 0;
|
let requestId = 0;
|
||||||
|
|
||||||
$: if (initialized) {
|
// Only re-run the search when the query actually changes. Flipping `initialized`
|
||||||
query;
|
// after the initial load would otherwise trigger a second, identical request.
|
||||||
|
$: if (initialized && query !== searchedQuery) {
|
||||||
scheduleSearch();
|
scheduleSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +42,7 @@
|
|||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
requestId += 1;
|
requestId += 1;
|
||||||
|
searchedQuery = query;
|
||||||
page = 1;
|
page = 1;
|
||||||
items = [];
|
items = [];
|
||||||
selectedIdx = 0;
|
selectedIdx = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user