Skip to content

Commit

Permalink
Merge pull request #1303 from ebkr/fix-default-ordering
Browse files Browse the repository at this point in the history
Fix default ordering on OnlineModView
  • Loading branch information
anttimaki authored Apr 24, 2024
2 parents bfa6e80 + 5c87aa4 commit 3dc4a63
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/r2mm/manager/PackageDexieStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface DexiePackage {
// Extra fields not included in the API response
community: string;
date_fetched: Date; // When the entry was fetched from the API
default_order: number; // Entry's index when received from the API
}

class PackageDexieStore extends Dexie {
Expand All @@ -56,7 +57,11 @@ const db = new PackageDexieStore();
// TODO: user type guards to validate (part of) the data before operations?
export async function updateFromApiResponse(community: string, packages: any[]) {
const extra = {community, date_fetched: new Date()};
const newPackages: DexiePackage[] = packages.map((pkg) => ({...pkg, ...extra}));
const newPackages: DexiePackage[] = packages.map((pkg, i) => ({
...pkg,
...extra,
default_order: i
}));

await db.transaction(
'rw',
Expand Down Expand Up @@ -87,7 +92,7 @@ export async function updateFromApiResponse(community: string, packages: any[])
}

export async function getPackagesAsThunderstoreMods(community: string) {
const packages = await db.packages.where({community}).toArray();
const packages = await db.packages.where({community}).sortBy('default_order');
return packages.map(ThunderstoreMod.parseFromThunderstoreData);
}

Expand Down

0 comments on commit 3dc4a63

Please sign in to comment.