Compare commits
No commits in common. "6ea8861da237d19c23a7babf03f29cef1ecefc69" and "6c7a26c73a134ebbeb6ede3f1c4d20626e5dd5d0" have entirely different histories.
6ea8861da2
...
6c7a26c73a
3 changed files with 119 additions and 151 deletions
|
@ -27,7 +27,7 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
|
|||
IEnumerable<Member> members =
|
||||
renderMembers ? await db.Members.Where(m => m.UserId == user.Id).ToListAsync(ct) : [];
|
||||
// Unless the user is requesting their own members AND the token can read hidden members, we filter out unlisted members.
|
||||
if (!(isSelfUser && tokenCanReadHiddenMembers)) members = members.Where(m => !m.Unlisted);
|
||||
if (!(isSelfUser && tokenCanReadHiddenMembers)) members = members.Where(m => m.Unlisted);
|
||||
|
||||
var authMethods = renderAuthMethods
|
||||
? await db.AuthMethods
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Link, redirect, useLoaderData, useRouteLoaderData } from "@remix-run/re
|
|||
import { UserWithMembers } from "~/lib/api/user";
|
||||
import serverRequest from "~/lib/request.server";
|
||||
import { loader as rootLoader } from "~/root";
|
||||
import { Alert, Button, Pagination } from "react-bootstrap";
|
||||
import { Alert, Button } from "react-bootstrap";
|
||||
import { Trans, useTranslation } from "react-i18next";
|
||||
import { renderMarkdown } from "~/lib/markdown";
|
||||
import ProfileLink from "~/components/ProfileLink";
|
||||
|
@ -11,7 +11,6 @@ import ProfileField from "~/components/ProfileField";
|
|||
import { PersonPlusFill } from "react-bootstrap-icons";
|
||||
import { defaultAvatarUrl } from "~/lib/utils";
|
||||
import MemberCard from "~/routes/$username/MemberCard";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
const { user } = data!;
|
||||
|
@ -35,44 +34,17 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
|||
memberPage = 0;
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(members));
|
||||
|
||||
return json({ user, members, currentPage: memberPage, pageCount });
|
||||
};
|
||||
|
||||
export default function UserPage() {
|
||||
const { t } = useTranslation();
|
||||
const { user, members, currentPage, pageCount } = useLoaderData<typeof loader>();
|
||||
const { user } = useLoaderData<typeof loader>();
|
||||
const { meUser } = useRouteLoaderData<typeof rootLoader>("root") || { meUser: undefined };
|
||||
|
||||
const isMeUser = meUser && meUser.id === user.id;
|
||||
const bio = renderMarkdown(user.bio);
|
||||
|
||||
const paginationItems: ReactNode[] = [];
|
||||
for (let i = 0; i < pageCount; i++) {
|
||||
paginationItems.push(
|
||||
<Pagination.Item key={i} as={Link} to={`/@${user.username}?page=${i}`}>
|
||||
{i + 1}
|
||||
</Pagination.Item>,
|
||||
);
|
||||
}
|
||||
|
||||
const pagination = (
|
||||
<Pagination className="justify-content-center">
|
||||
<Pagination.Prev
|
||||
as={Link}
|
||||
to={`/@${user.username}?page=${currentPage - 1}`}
|
||||
disabled={currentPage === 0}
|
||||
/>
|
||||
{paginationItems}
|
||||
<Pagination.Next
|
||||
as={Link}
|
||||
to={`/@${user.username}?page=${currentPage + 1}`}
|
||||
disabled={currentPage === pageCount - 1}
|
||||
/>
|
||||
</Pagination>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
{isMeUser && (
|
||||
|
@ -148,27 +120,24 @@ export default function UserPage() {
|
|||
))}
|
||||
</div>
|
||||
</div>
|
||||
{(members.length > 0 || isMeUser) && (
|
||||
{user.members.length > 0 ||
|
||||
(isMeUser && (
|
||||
<>
|
||||
<hr />
|
||||
<h2>
|
||||
{user.member_title || t("user.heading.members")}{" "}
|
||||
{isMeUser && (
|
||||
// @ts-expect-error using as=Link causes an error here, even though it runs completely fine
|
||||
{/* @ts-expect-error using as=Link causes an error here, even though it runs completely fine */}
|
||||
<Button as={Link} to="/settings/members/create" variant="success">
|
||||
<PersonPlusFill /> {t("user.create-member-button")}
|
||||
</Button>
|
||||
)}
|
||||
</h2>
|
||||
{pageCount > 1 && pagination}
|
||||
<div className="grid">
|
||||
{members.length === 0 ? (
|
||||
{user.members.length === 0 ? (
|
||||
<div>
|
||||
<Trans t={t} i18nKey="user.no-members-blurb">
|
||||
You don't have any members yet.
|
||||
<br />
|
||||
Members are sub-profiles that can have their own avatar, names, pronouns, and
|
||||
preferred terms.
|
||||
Members are sub-profiles that can have their own avatar, names, pronouns, and preferred terms.
|
||||
<br />
|
||||
You can create a new member with the "Create member" button above.{" "}
|
||||
<span className="text-muted">(only you can see this)</span>
|
||||
|
@ -176,15 +145,14 @@ export default function UserPage() {
|
|||
</div>
|
||||
) : (
|
||||
<div className="row row-cols-2 row-cols-md-3 row-cols-lg-4 row-cols-xl-5 text-center">
|
||||
{members.map((member, i) => (
|
||||
{user.members.map((member, i) => (
|
||||
<MemberCard user={user} member={member} key={i} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{pageCount > 1 && pagination}
|
||||
</>
|
||||
)}
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue