Fix sorting on my addons

Fix latest file selection
This commit is contained in:
john liddell
2020-09-27 09:09:44 -05:00
parent ba79afea51
commit b495cb7731
4 changed files with 19 additions and 12 deletions

View File

@@ -106,6 +106,7 @@
"@angular/platform-browser": "~10.1.1",
"@angular/platform-browser-dynamic": "~10.1.1",
"@angular/router": "~10.1.1",
"@types/lodash": "4.14.161",
"adm-zip": "0.4.16",
"compare-versions": "3.6.0",
"conf": "7.1.1",

View File

@@ -1,6 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { PotentialAddonStatusColumnComponent } from 'app/components/potential-addon-status-column/potential-addon-status-column.component';
import { PotentialAddonTableColumnComponent } from 'app/components/potential-addon-table-column/potential-addon-table-column.component';
import { WowClientType } from 'app/models/warcraft/wow-client-type';
import { ColumnState } from 'app/models/wowup/column-state';
import { PotentialAddon } from 'app/models/wowup/potential-addon';

View File

@@ -68,17 +68,23 @@ export class MyAddonsComponent implements OnInit, OnDestroy {
this.addonService.addonInstalled$.subscribe((evt) => {
console.log('UPDATE')
const addons: MyAddonsListItem[] = [].concat(this._displayAddonsSrc.value);
const listItemIdx = addons.findIndex(li => li.addon.id === evt.addon.id);
let listItems: MyAddonsListItem[] = [].concat(this._displayAddonsSrc.value);
const listItemIdx = listItems.findIndex(li => li.addon.id === evt.addon.id);
const listItem = this.createAddonListItem(evt.addon);
listItem.isInstalling = evt.installState === AddonInstallState.Installing || evt.installState === AddonInstallState.Downloading;
listItem.statusText = this.getInstallStateText(evt.installState);
listItem.installProgress = evt.progress;
console.log(listItem);
addons[listItemIdx] = listItem;
if (listItemIdx === -1) {
listItems.push(listItem);
} else {
listItems[listItemIdx] = listItem;
}
listItems = this.sortListItems(listItems);
this._ngZone.run(() => {
this._displayAddonsSrc.next(addons);
this._displayAddonsSrc.next(listItems);
});
});
@@ -234,7 +240,11 @@ export class MyAddonsComponent implements OnInit, OnDestroy {
private formatAddons(addons: Addon[]): MyAddonsListItem[] {
const listItems = addons.map(addon => this.createAddonListItem(addon));
return _.sortBy(listItems, ['displayState', 'name']);
return this.sortListItems(listItems);
}
private sortListItems(listItems: MyAddonsListItem[]) {
return _.orderBy(listItems, ['displayState', 'addon.name']);
}
private createAddonListItem(addon: Addon) {

View File

@@ -337,10 +337,8 @@ export class AddonService {
}
private getLatestFile(searchResult: AddonSearchResult, channelType: AddonChannelType): AddonSearchResultFile {
return _.flow(
_.filter((f: AddonSearchResultFile) => f.channelType <= channelType),
_.first
)(searchResult.files);
let files = _.filter(searchResult.files, (f: AddonSearchResultFile) => f.channelType <= channelType);
return _.first(files);
}
private createAddon(