trendingStatusesController: sort a simpler way
This commit is contained in:
parent
45d9a113c3
commit
a911e36a7e
|
@ -1,3 +1,4 @@
|
||||||
|
import { NostrEvent } from '@nostrify/nostrify';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { type AppController } from '@/app.ts';
|
import { type AppController } from '@/app.ts';
|
||||||
|
@ -92,12 +93,13 @@ const trendingStatusesController: AppController = async (c) => {
|
||||||
return c.json([]);
|
return c.json([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const events = await store.query([{ ids }])
|
const results = await store.query([{ ids }])
|
||||||
.then((events) => hydrateEvents({ events, store }));
|
.then((events) => hydrateEvents({ events, store }));
|
||||||
|
|
||||||
// Sort events in the order they appear in the label.
|
// Sort events in the order they appear in the label.
|
||||||
const indexes = ids.reduce<Record<string, number>>((acc, id, index) => ({ ...acc, [id]: index }), {});
|
const events = ids
|
||||||
events.sort((a, b) => indexes[a.id] - indexes[b.id]);
|
.map((id) => results.find((event) => event.id === id))
|
||||||
|
.filter((event): event is NostrEvent => !!event);
|
||||||
|
|
||||||
const statuses = await Promise.all(
|
const statuses = await Promise.all(
|
||||||
events.map((event) => renderStatus(event, {})),
|
events.map((event) => renderStatus(event, {})),
|
||||||
|
|
Loading…
Reference in New Issue