activities: fix updateExistingElements, rename
forgot to wipe this._ordering, so search was attempting to run on non-existent items. Also renamed the two functions to appendNewItems and replaceWithNewItems, this makes more sense to me.
This commit is contained in:
@@ -925,7 +925,7 @@ export class accountsList extends PaginatedList {
|
||||
getPageEndpoint: "/users",
|
||||
itemsPerPage: 40,
|
||||
maxItemsLoadedForSearch: 200,
|
||||
newElementsFromPage: (resp: paginatedDTO) => {
|
||||
appendNewItems: (resp: paginatedDTO) => {
|
||||
for (let u of ((resp as UsersDTO).users || [])) {
|
||||
if (u.id in this.users) {
|
||||
this.users[u.id].update(u);
|
||||
@@ -940,7 +940,7 @@ export class accountsList extends PaginatedList {
|
||||
this._search.ascending
|
||||
);
|
||||
},
|
||||
updateExistingElementsFromPage: (resp: paginatedDTO) => {
|
||||
replaceWithNewItems: (resp: paginatedDTO) => {
|
||||
let accountsOnDOM: { [id: string]: boolean } = {};
|
||||
|
||||
for (let id of Object.keys(this.users)) { accountsOnDOM[id] = true; }
|
||||
|
||||
@@ -503,7 +503,7 @@ export class activityList extends PaginatedList {
|
||||
getPageEndpoint: "/activity",
|
||||
itemsPerPage: 20,
|
||||
maxItemsLoadedForSearch: 200,
|
||||
newElementsFromPage: (resp: paginatedDTO) => {
|
||||
appendNewItems: (resp: paginatedDTO) => {
|
||||
let ordering: string[] = this._search.ordering;
|
||||
for (let act of ((resp as ActivitiesDTO).activities || [])) {
|
||||
this.activities[act.id] = new Activity(act);
|
||||
@@ -511,12 +511,16 @@ export class activityList extends PaginatedList {
|
||||
}
|
||||
this._search.setOrdering(ordering, this._c.defaultSortField, this.ascending);
|
||||
},
|
||||
updateExistingElementsFromPage: (resp: paginatedDTO) => {
|
||||
replaceWithNewItems: (resp: paginatedDTO) => {
|
||||
// FIXME: Implement updates to existing elements, rather than just wiping each time.
|
||||
|
||||
// Remove existing items
|
||||
for (let id of Object.keys(this.activities)) {
|
||||
delete this.activities[id];
|
||||
}
|
||||
this._c.newElementsFromPage(resp);
|
||||
// And wipe their ordering
|
||||
this._search.setOrdering([], this._c.defaultSortField, this.ascending);
|
||||
this._c.appendNewItems(resp);
|
||||
},
|
||||
defaultSortField: ACTIVITY_DEFAULT_SORT_FIELD,
|
||||
defaultSortAscending: ACTIVITY_DEFAULT_SORT_ASCENDING,
|
||||
|
||||
+5
-5
@@ -85,8 +85,8 @@ export interface PaginatedListConfig {
|
||||
getPageEndpoint: string;
|
||||
itemsPerPage: number;
|
||||
maxItemsLoadedForSearch: number;
|
||||
newElementsFromPage: (resp: paginatedDTO) => void;
|
||||
updateExistingElementsFromPage: (resp: paginatedDTO) => void;
|
||||
appendNewItems: (resp: paginatedDTO) => void;
|
||||
replaceWithNewItems: (resp: paginatedDTO) => void;
|
||||
defaultSortField: string;
|
||||
defaultSortAscending: boolean;
|
||||
pageLoadCallback?: (req: XMLHttpRequest) => void;
|
||||
@@ -238,7 +238,7 @@ export abstract class PaginatedList {
|
||||
let timer = this._search.timeSearches ? performance.now() : null;
|
||||
if (visible) this._visible = elements;
|
||||
else this._visible = this._search.ordering.filter(v => !elements.includes(v));
|
||||
console.log(elements.length, visible, this._visible.length);
|
||||
// console.log(elements.length, visible, this._visible.length);
|
||||
this._counter.shown = this._visible.length;
|
||||
if (this._visible.length == 0) {
|
||||
this._container.textContent = ``;
|
||||
@@ -341,7 +341,7 @@ export abstract class PaginatedList {
|
||||
|
||||
this.lastPage = resp.last_page;
|
||||
|
||||
this._c.updateExistingElementsFromPage(resp);
|
||||
this._c.replaceWithNewItems(resp);
|
||||
|
||||
this._counter.loaded = this._search.ordering.length;
|
||||
|
||||
@@ -397,7 +397,7 @@ export abstract class PaginatedList {
|
||||
|
||||
this.lastPage = resp.last_page;
|
||||
|
||||
this._c.newElementsFromPage(resp);
|
||||
this._c.appendNewItems(resp);
|
||||
|
||||
this._counter.loaded = this._search.ordering.length;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user