diff --git a/src/components/views/DownloadModModal.vue b/src/components/views/DownloadModModal.vue
index 13cc32fdd..c3f638723 100644
--- a/src/components/views/DownloadModModal.vue
+++ b/src/components/views/DownloadModModal.vue
@@ -77,7 +77,7 @@
-
- {{mod.getName()}} will be updated to: {{mod.getLatestVersion().getVersionNumber().toString()}}
+ {{mod.getName()}} will be updated to: {{mod.getLatestVersion()}}
@@ -223,7 +223,7 @@ let assignId = 0;
async getModVersions() {
this.currentVersion = null;
if (this.thunderstoreMod !== null) {
- this.selectedVersion = this.thunderstoreMod.getLatestVersion().getVersionNumber().toString();
+ this.selectedVersion = this.thunderstoreMod.getLatestVersion();
this.recommendedVersion = null;
this.versionNumbers = await PackageDb.getPackageVersionNumbers(
diff --git a/src/components/views/OnlineModList.vue b/src/components/views/OnlineModList.vue
index 68cdb1c12..d978ba7f2 100644
--- a/src/components/views/OnlineModList.vue
+++ b/src/components/views/OnlineModList.vue
@@ -4,7 +4,7 @@
v-for='(key, index) in pagedModList' :key="`online-${key.getFullName()}-${index}-${settings.getContext().global.expandedCards}`"
:image="getImageUrl(key)"
:id="index"
- :description="key.getLatestVersion().getDescription()">
+ :description="key.getDescription()">
local.getName() === mod.getFullName()) != undefined;
}
- showDownloadModal(mod: any) {
- const modToDownload = new ThunderstoreMod().fromReactive(mod);
- this.$store.commit("openDownloadModModal", modToDownload);
+ showDownloadModal(mod: ThunderstoreMod) {
+ this.$store.commit("openDownloadModModal", mod);
}
getReadableDate(date: Date): string {
return valueToReadableDate(date);
}
- getReadableCategories(tsMod: ThunderstoreMod) {
- const mod = new ThunderstoreMod().fromReactive(tsMod);
+ getReadableCategories(mod: ThunderstoreMod) {
return mod.getCategories().join(", ");
}
- getImageUrl(tsMod: ThunderstoreMod): string {
- return CdnProvider.replaceCdnHost(
- tsMod.getLatestVersion().getIcon()
- );
+ getImageUrl(mod: ThunderstoreMod): string {
+ return CdnProvider.replaceCdnHost(mod.getIcon());
}
async created() {
diff --git a/src/components/views/OnlineModView.vue b/src/components/views/OnlineModView.vue
index effc2577d..ec0ce555a 100644
--- a/src/components/views/OnlineModView.vue
+++ b/src/components/views/OnlineModView.vue
@@ -147,7 +147,7 @@ export default class OnlineModView extends Vue {
const searchKeys = SearchUtils.makeKeys(this.thunderstoreSearchFilter);
if (searchKeys.length > 0) {
searchableList = this.sortedThunderstoreModList.filter((x: ThunderstoreMod) => {
- return SearchUtils.isSearched(searchKeys, x.getFullName(), x.getLatestVersion().getDescription())
+ return SearchUtils.isSearched(searchKeys, x.getFullName(), x.getDescription())
});
}
if (!allowNsfw) {
diff --git a/src/model/ThunderstoreMod.ts b/src/model/ThunderstoreMod.ts
index 852970576..a5f8e4125 100644
--- a/src/model/ThunderstoreMod.ts
+++ b/src/model/ThunderstoreMod.ts
@@ -1,8 +1,6 @@
import ThunderstoreVersion from './ThunderstoreVersion';
-import ReactiveObjectConverterInterface from './safety/ReactiveObjectConverter';
-export default class ThunderstoreMod extends ThunderstoreVersion implements ReactiveObjectConverterInterface {
- private versions: ThunderstoreVersion[] = [];
+export default class ThunderstoreMod extends ThunderstoreVersion {
private rating: number = 0;
private owner: string = '';
private packageUrl: string = '';
@@ -15,6 +13,7 @@ export default class ThunderstoreMod extends ThunderstoreVersion implements Reac
private categories: string[] = [];
private hasNsfwContent: boolean = false;
private donationLink: string | undefined;
+ private latestVersion: string = '';
public static parseFromThunderstoreData(data: any): ThunderstoreMod {
const mod = new ThunderstoreMod();
@@ -25,63 +24,33 @@ export default class ThunderstoreMod extends ThunderstoreVersion implements Reac
mod.setDateUpdated(data.date_updated);
mod.setDeprecatedStatus(data.is_deprecated);
mod.setPinnedStatus(data.is_pinned);
- const versions = [];
- for (const version of data.versions) {
- versions.push(new ThunderstoreVersion().make(version));
- }
- mod.setVersions(versions);
- mod.setDownloadCount(
- mod.versions
- .map(version => version.getDownloadCount())
- .reduce((x, y) => x + y)
- );
mod.setRating(data.rating_score);
mod.setTotalDownloads(
- mod.getVersions()
- .map(x => x.getDownloadCount())
- .reduce((x, y) => x + y)
+ data.versions.reduce(
+ (x: number, y: {downloads: number}) => x + y.downloads,
+ 0
+ )
);
mod.setPackageUrl(data.package_url);
mod.setCategories(data.categories);
mod.setNsfwFlag(data.has_nsfw_content);
mod.setDonationLink(data.donation_link);
+ mod.setLatestVersion(data.versions[0].version_number);
+ mod.setDescription(data.versions[0].description);
+ mod.setIcon(data.versions[0].icon);
return mod;
}
- public fromReactive(reactive: any): ThunderstoreMod {
- this.setName(reactive.name);
- this.setFullName(reactive.fullName);
- this.setOwner(reactive.owner);
- this.setPackageUrl(reactive.packageUrl);
- this.setDateCreated(reactive.dateCreated);
- this.setDateUpdated(reactive.dateUpdated);
- this.setDeprecatedStatus(reactive.deprecated);
- this.setPinnedStatus(reactive.pinned);
- this.setVersions(reactive.versions.map((x: ThunderstoreVersion) => new ThunderstoreVersion().fromReactive(x)));
- this.setDownloadCount(reactive.downloadCount);
- this.setRating(reactive.rating);
- this.setTotalDownloads(reactive.totalDownloads);
- this.setUuid4(reactive.uuid4);
- this.setCategories(reactive.categories);
- this.setNsfwFlag(reactive.hasNsfwContent);
- this.setDonationLink(reactive.donationUrl);
- return this;
- }
-
- public getVersions(): ThunderstoreVersion[] {
- return this.versions;
+ public getLatestVersion(): string {
+ return this.latestVersion;
}
- public setVersions(versions: ThunderstoreVersion[]) {
- this.versions = versions;
- }
-
- public getLatestVersion(): ThunderstoreVersion {
- return this.getVersions().reduce(reduceToNewestVersion);
+ public setLatestVersion(versionNumber: string) {
+ this.latestVersion = versionNumber;
}
public getLatestDependencyString(): string {
- return `${this.getFullName()}-${this.getLatestVersion().toString()}`;
+ return `${this.getFullName()}-${this.getLatestVersion()}`;
}
public getRating(): number {
@@ -180,7 +149,3 @@ export default class ThunderstoreMod extends ThunderstoreVersion implements Reac
this.donationLink = url;
}
}
-
-function reduceToNewestVersion(v1: ThunderstoreVersion, v2: ThunderstoreVersion) {
- return v1.getVersionNumber().isNewerThan(v2.getVersionNumber()) ? v1 : v2;
-};
diff --git a/src/model/ThunderstoreVersion.ts b/src/model/ThunderstoreVersion.ts
index c93f5fe0d..9af27287c 100644
--- a/src/model/ThunderstoreVersion.ts
+++ b/src/model/ThunderstoreVersion.ts
@@ -1,8 +1,7 @@
import VersionNumber from './VersionNumber';
-import ReactiveObjectConverterInterface from './safety/ReactiveObjectConverter';
import CdnProvider from '../providers/generic/connection/CdnProvider';
-export default class ThunderstoreVersion implements ReactiveObjectConverterInterface {
+export default class ThunderstoreVersion {
private name: string = '';
private versionNumber: VersionNumber = new VersionNumber('0.0.0');
@@ -32,19 +31,6 @@ export default class ThunderstoreVersion implements ReactiveObjectConverterInter
return this;
}
- public fromReactive(reactive: any): ThunderstoreVersion {
- this.setName(reactive.name);
- this.setVersionNumber(new VersionNumber('0.0.0').fromReactive(reactive.versionNumber));
- this.setDependencies(reactive.dependencies);
- this.setFullName(reactive.fullName);
- this.setDescription(reactive.description);
- this.setIcon(reactive.icon);
- this.enabled = reactive.enabled;
- this.setDownloadCount(reactive.downloadCount);
- this.setDownloadUrl(reactive.downloadUrl);
- return this;
- }
-
public getName(): string {
return this.name;
}
diff --git a/src/store/modules/TsModsModule.ts b/src/store/modules/TsModsModule.ts
index 14efabe05..5e2293d06 100644
--- a/src/store/modules/TsModsModule.ts
+++ b/src/store/modules/TsModsModule.ts
@@ -3,6 +3,7 @@ import { ActionTree, GetterTree, MutationTree } from 'vuex';
import { State as RootState } from '../index';
import ManifestV2 from '../../model/ManifestV2';
import ThunderstoreMod from '../../model/ThunderstoreMod';
+import VersionNumber from '../../model/VersionNumber';
import CdnProvider from '../../providers/generic/connection/CdnProvider';
import ConnectionProvider from '../../providers/generic/connection/ConnectionProvider';
import * as PackageDb from '../../r2mm/manager/PackageDexieStore';
@@ -80,7 +81,7 @@ export const TsModsModule = {
if (tsMod === undefined) {
state.cache.set(cacheKey, {tsMod: undefined, isLatest: true});
} else {
- const latestVersionNumber = tsMod.getLatestVersion().getVersionNumber();
+ const latestVersionNumber = new VersionNumber(tsMod.getLatestVersion());
const isLatest = mod.getVersionNumber().isEqualOrNewerThan(latestVersionNumber);
state.cache.set(cacheKey, {tsMod, isLatest});
}
diff --git a/test/jest/__tests__/utils/utils.getDeprecatedPackageMap.ts.spec.ts b/test/jest/__tests__/utils/utils.getDeprecatedPackageMap.ts.spec.ts
index 1e4616f38..501b8e063 100644
--- a/test/jest/__tests__/utils/utils.getDeprecatedPackageMap.ts.spec.ts
+++ b/test/jest/__tests__/utils/utils.getDeprecatedPackageMap.ts.spec.ts
@@ -227,10 +227,10 @@ const createStubMod = (
mod.setFullName(modName);
mod.setDeprecatedStatus(deprecated);
- const version = new ThunderstoreVersion();
- version.setFullName(`${mod}-1.0.0`);
- version.setDependencies(dependencyNames.map((depName) => `${depName}-1.0.0`));
- mod.setVersions([version]);
+ // const version = new ThunderstoreVersion();
+ // version.setFullName(`${mod}-1.0.0`);
+ // version.setDependencies(dependencyNames.map((depName) => `${depName}-1.0.0`));
+ // mod.setVersions([version]);
return mod;
}