fixes #4104
This commit is contained in:
@@ -12,9 +12,10 @@ import useStores from "~/hooks/useStores";
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
collection: Collection;
|
collection: Collection;
|
||||||
|
limit?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const MembershipPreview = ({ collection }: Props) => {
|
const MembershipPreview = ({ collection, limit = 8 }: Props) => {
|
||||||
const [isLoading, setIsLoading] = React.useState(false);
|
const [isLoading, setIsLoading] = React.useState(false);
|
||||||
const [totalMemberships, setTotalMemberships] = React.useState(0);
|
const [totalMemberships, setTotalMemberships] = React.useState(0);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -32,7 +33,7 @@ const MembershipPreview = ({ collection }: Props) => {
|
|||||||
try {
|
try {
|
||||||
const options = {
|
const options = {
|
||||||
id: collection.id,
|
id: collection.id,
|
||||||
limit: 8,
|
limit,
|
||||||
};
|
};
|
||||||
const [users, groups] = await Promise.all([
|
const [users, groups] = await Promise.all([
|
||||||
memberships.fetchPage(options),
|
memberships.fetchPage(options),
|
||||||
@@ -52,6 +53,7 @@ const MembershipPreview = ({ collection }: Props) => {
|
|||||||
collection.id,
|
collection.id,
|
||||||
collectionGroupMemberships,
|
collectionGroupMemberships,
|
||||||
memberships,
|
memberships,
|
||||||
|
limit,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (isLoading || collection.permission) {
|
if (isLoading || collection.permission) {
|
||||||
@@ -72,7 +74,7 @@ const MembershipPreview = ({ collection }: Props) => {
|
|||||||
height="auto"
|
height="auto"
|
||||||
>
|
>
|
||||||
<Fade>
|
<Fade>
|
||||||
<Facepile users={collectionUsers} overflow={overflow} />
|
<Facepile users={collectionUsers} overflow={overflow} limit={limit} />
|
||||||
</Fade>
|
</Fade>
|
||||||
</NudeButton>
|
</NudeButton>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -316,21 +316,25 @@ router.post(
|
|||||||
where = { ...where, permission };
|
where = { ...where, permission };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
where,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Group,
|
||||||
|
as: "group",
|
||||||
|
where: groupWhere,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
const [total, memberships] = await Promise.all([
|
const [total, memberships] = await Promise.all([
|
||||||
CollectionGroup.count({ where }),
|
CollectionGroup.count(options),
|
||||||
CollectionGroup.findAll({
|
CollectionGroup.findAll({
|
||||||
where,
|
...options,
|
||||||
order: [["createdAt", "DESC"]],
|
order: [["createdAt", "DESC"]],
|
||||||
offset: ctx.state.pagination.offset,
|
offset: ctx.state.pagination.offset,
|
||||||
limit: ctx.state.pagination.limit,
|
limit: ctx.state.pagination.limit,
|
||||||
include: [
|
|
||||||
{
|
|
||||||
model: Group,
|
|
||||||
as: "group",
|
|
||||||
where: groupWhere,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -461,21 +465,25 @@ router.post("collections.memberships", auth(), pagination(), async (ctx) => {
|
|||||||
where = { ...where, permission };
|
where = { ...where, permission };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
where,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: User,
|
||||||
|
as: "user",
|
||||||
|
where: userWhere,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
const [total, memberships] = await Promise.all([
|
const [total, memberships] = await Promise.all([
|
||||||
CollectionUser.count({ where }),
|
CollectionUser.count(options),
|
||||||
CollectionUser.findAll({
|
CollectionUser.findAll({
|
||||||
where,
|
...options,
|
||||||
order: [["createdAt", "DESC"]],
|
order: [["createdAt", "DESC"]],
|
||||||
offset: ctx.state.pagination.offset,
|
offset: ctx.state.pagination.offset,
|
||||||
limit: ctx.state.pagination.limit,
|
limit: ctx.state.pagination.limit,
|
||||||
include: [
|
|
||||||
{
|
|
||||||
model: User,
|
|
||||||
as: "user",
|
|
||||||
where: userWhere,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user