Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default ordering on OnlineModView #1303

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading