File size: 911 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
// @flow
import { createReadQuery, db } from 'shared/db';
import type { DBCommunity } from 'shared/types';
export const getCommunityById = createReadQuery((id: string) => ({
query: db.table('communities').get(id),
tags: (community: ?DBCommunity) => (community ? [community.id] : []),
}));
export const getCommunitiesById = createReadQuery((ids: Array<string>) => ({
query: db.table('communities').getAll(...ids),
tags: (communities: ?Array<DBCommunity>) =>
communities ? communities.map(({ id }) => id) : [],
}));
export const getTopCommunitiesByMemberCount = createReadQuery(
(amount: number) => ({
query: db
.table('communities')
.orderBy({ index: db.desc('memberCount') })
.filter(community => community.hasFields('deletedAt').not())
.limit(amount),
tags: (communities: Array<DBCommunity>) =>
communities ? communities.map(({ id }) => id) : [],
})
);
|