Skip to content

Commit

Permalink
Rename element/entity to item in ListModel
Browse files Browse the repository at this point in the history
  • Loading branch information
paw-hub committed Jan 10, 2025
1 parent 1098c4b commit 3707808
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 132 deletions.
12 changes: 6 additions & 6 deletions src/common/misc/ListElementListModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { OperationType } from "../api/common/TutanotaConstants"
import Stream from "mithril/stream"
import { ListLoadingState, ListState } from "../gui/base/List"

export type ListElementListModelConfig<ElementType> = Omit<ListModelConfig<ElementType, Id>, "getElementId" | "isSameId">
export type ListElementListModelConfig<ElementType> = Omit<ListModelConfig<ElementType, Id>, "getItemId" | "isSameId">

export class ListElementListModel<ElementType extends ListElement> {
private readonly listModel: ListModel<ElementType, Id>
Expand All @@ -25,7 +25,7 @@ export class ListElementListModel<ElementType extends ListElement> {
constructor(config: ListElementListModelConfig<ElementType>) {
this.config = Object.assign({}, config, {
isSameId,
getElementId,
getItemId: getElementId,
})
this.listModel = new ListModel(this.config)
}
Expand All @@ -45,12 +45,12 @@ export class ListElementListModel<ElementType extends ListElement> {
this.listModel.addToLoadedEntities(entity)
}
} else if (operation === OperationType.UPDATE) {
this.listModel.updateLoadedEntity(entity)
this.listModel.updateLoadedItem(entity)
}
})
} else if (operation === OperationType.DELETE) {
// await this.swipeHandler?.animating
await this.listModel.deleteLoadedEntity(elementId)
await this.listModel.deleteLoadedItem(elementId)
}
}

Expand All @@ -60,14 +60,14 @@ export class ListElementListModel<ElementType extends ListElement> {
}

// new element is in the loaded range or newer than the first element
const lastElement = this.listModel.getLastElement()
const lastElement = this.listModel.getLastItem()
return lastElement != null && this.config.sortCompare(entity, lastElement) < 0
}

async loadAndSelect(
itemId: Id,
shouldStop: () => boolean,
finder: (a: ElementType) => boolean = (item) => this.config.isSameId(this.config.getElementId(item), itemId),
finder: (a: ElementType) => boolean = (item) => this.config.isSameId(this.config.getItemId(item), itemId),
): Promise<ElementType | null> {
return this.listModel.loadAndSelect(itemId, shouldStop, finder)
}
Expand Down
Loading

0 comments on commit 3707808

Please sign in to comment.