Skip to content

Commit

Permalink
fix(viewer): context viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
immccn123 committed Oct 29, 2023
1 parent d80e743 commit 9fbdf33
Show file tree
Hide file tree
Showing 20 changed files with 338 additions and 552 deletions.
1 change: 0 additions & 1 deletion packages/viewer/src/app/[id]/[page]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { selectReply } from "@/lib/reply";
import { selectPost } from "@/lib/post";
import { checkExists } from "@/lib/utils";
import savedInLegacyList from "../saved-in-legacy.json";
// import serializeReply from "@/lib/serialize-reply";

const REPLIES_PER_PAGE = parseInt(process.env.REPLIES_PER_PAGE ?? "10", 10);

Expand Down
1 change: 0 additions & 1 deletion packages/viewer/src/app/[id]/context/[user]/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NextRequest, NextResponse } from "next/server";
import { selectReply } from "@/lib/reply";
import prisma from "@/lib/prisma";
// import serializeReply from "@/lib/serialize-reply";

export async function GET(
request: NextRequest,
Expand Down
1 change: 0 additions & 1 deletion packages/viewer/src/app/[id]/replies/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { NextRequest, NextResponse } from "next/server";
import prisma from "@/lib/prisma";
// import serializeReply from "@/lib/serialize-reply";

import { selectReply } from "@/lib/reply";

Expand Down
16 changes: 16 additions & 0 deletions packages/viewer/src/app/[id]/statistics/[user]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NextRequest, NextResponse } from "next/server";
import prisma from "@/lib/prisma";

export async function GET(
request: NextRequest,
{ params }: { params: { id: string; user: string } },
) {
const postId = parseInt(params.id, 10);
const authorId = parseInt(params.user, 10);

const numReplies = await prisma.replySnapshot.count({
where: { authorId, reply: { postId } },
});

return NextResponse.json({ numReplies });
}
5 changes: 1 addition & 4 deletions packages/viewer/src/app/r/[rid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import stringifyTime from "@/lib/time";
import getReplyRaw from "./get-reply-raw";
import savedInLegacyList from "../saved-in-legacy.json";

// import serializeReply from "@/lib/serialize-reply";

export const metadata = { title: "金玉良言 - 洛谷帖子保存站" };

const REPLIES_PER_PAGE = parseInt(process.env.REPLIES_PER_PAGE ?? "10", 10);
Expand Down Expand Up @@ -61,9 +59,8 @@ export default async function Page({ params }: { params: { rid: string } }) {
<div className="rounded-4 shadow-bssb">
<div className="px-md-4x px-4 pt-md-3x pt-2x pb-md-4x pb-4 position-relative">
<Content
// discussionAuthor={reply.post.snapshots[0].authorId}
discussionAuthor={reply.post.snapshots[0].author.id}
content={reply.snapshots[0].content}
// usersMetioned={reply.usersMetioned}
/>
<span
className="text-end text-body-tertiary d-block d-md-none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import useSWRInfinite from "swr/infinite";
import InfiniteScroll from "react-infinite-scroll-component";
import type { PostWithLatestContent } from "@/lib/post";
// import type { UserMetioned } from "@/lib/serialize-reply";
import Content from "@/components/replies/Content";
import fetcher from "@/lib/fetcher";
import Spinner from "@/components/Spinner";
Expand Down Expand Up @@ -63,7 +62,7 @@ export default function UserDiscussions({ uid }: { uid: string }) {
}
>
<Content
// discussionAuthor={discussion.snapshots[0].author.id}
discussionAuthor={discussion.snapshots[0].author.id}
content={discussion.snapshots[0].content}
// usersMetioned={discussion.usersMetioned}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NextResponse, type NextRequest } from "next/server";
import prisma from "@/lib/prisma";
import { getPost } from "@/lib/post";
// import serializeReply from "@/lib/serialize-reply";
import { NUM_PER_PAGE } from "../../constants";

export async function GET(
Expand Down
17 changes: 17 additions & 0 deletions packages/viewer/src/app/user/[uid]/info/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NextResponse, type NextRequest } from "next/server";
import prisma from "@/lib/prisma";
import { selectUser } from "@/lib/user";
import { notFound } from "next/navigation";

export async function GET(
request: NextRequest,
{ params }: { params: { uid: string } },
) {
const uid = parseInt(params.uid, 10);
const user =
(await prisma.user.findUnique({
where: { id: uid },
select: selectUser.withLatest,
})) ?? notFound();
return NextResponse.json(user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Link from "next/link";
import useSWRInfinite from "swr/infinite";
import InfiniteScroll from "react-infinite-scroll-component";
import type { PostWithLatestContent } from "@/lib/post";
// import type { UserMetioned } from "@/lib/serialize-reply";
import UserAvatar from "@/components/UserAvatar";
import UserInfo from "@/components/UserInfo";
import Content from "@/components/replies/Content";
Expand Down Expand Up @@ -115,7 +114,7 @@ export default function UserParticipated({
</span>
</summary>
<Content
// discussionAuthor={discussion.snapshots[0].author.id}
discussionAuthor={discussion.snapshots[0].author.id}
content={discussion.snapshots[0].content}
// usersMetioned={discussion.usersMetioned}
/>
Expand Down Expand Up @@ -181,9 +180,9 @@ export default function UserParticipated({
</div>
<div className="px-4 py-2 position-relative">
<Content
// discussionAuthor={
// discussion.snapshots[0].author.id
// }
discussionAuthor={
discussion.snapshots[0].author.id
}
content={reply.snapshots[0].content}
// usersMetioned={reply.usersMetioned}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NextResponse, type NextRequest } from "next/server";
import prisma from "@/lib/prisma";
import { getPost } from "@/lib/post";
// import serializeReply from "@/lib/serialize-reply";
import { getReply } from "@/lib/reply";
import { NUM_PER_PAGE } from "../../constants";

Expand Down
2 changes: 0 additions & 2 deletions packages/viewer/src/app/user/[uid]/replies/UserReplies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import Link from "next/link";
import useSWRInfinite from "swr/infinite";
import InfiniteScroll from "react-infinite-scroll-component";
// import type { User } from "@prisma/client";
// import type { UserMetioned } from "@/lib/serialize-reply";
import fetcher from "@/lib/fetcher";
import Reply from "@/components/replies/Reply";
import Spinner from "@/components/Spinner";
Expand Down
1 change: 0 additions & 1 deletion packages/viewer/src/app/user/[uid]/replies/data/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NextResponse, type NextRequest } from "next/server";
import { getReply, selectReply } from "@/lib/reply";
import prisma from "@/lib/prisma";
// import serializeReply from "@/lib/serialize-reply";
import { NUM_PER_PAGE } from "../../constants";

export async function GET(
Expand Down
9 changes: 9 additions & 0 deletions packages/viewer/src/components/markdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,12 @@
margin-left: auto;
margin-right: auto;
} */

.markdown .lfm-user-mention {
text-decoration: none;
}

.markdown .lfm-user-mention:focus {
background-color: var(--bs-primary);
color: white;
}
Loading

0 comments on commit 9fbdf33

Please sign in to comment.