Skip to content

Commit

Permalink
Bump version of Next.js and typescript-eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
wxh06 committed Aug 31, 2023
1 parent 51aee7c commit 0728dd2
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 187 deletions.
4 changes: 2 additions & 2 deletions packages/archive/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module.exports = {
files: ["*.ts", "*.tsx"],
extends: [
"airbnb-typescript/base",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:prettier/recommended",
],
parserOptions: {
Expand Down
2 changes: 1 addition & 1 deletion packages/archive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"devDependencies": {
"@types/jsdom": "^21.1.2",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"eslint": "^8.48.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"typescript": "^5.2.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/viewer/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module.exports = {
files: ["*.ts", "*.tsx"],
extends: [
"airbnb-typescript",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:prettier/recommended",
],
settings: {
Expand Down
8 changes: 4 additions & 4 deletions packages/viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"highlight.js": "^11.8.0",
"jsdom": "^22.1.0",
"katex": "^0.16.8",
"next": "^13.4.9",
"next": "^13.4.19",
"puppeteer": "^21.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -24,18 +24,18 @@
"swr": "^2.2.2"
},
"devDependencies": {
"@next/bundle-analyzer": "^13.4.9",
"@next/bundle-analyzer": "^13.4.19",
"@types/bootstrap": "^5.2.6",
"@types/jsdom": "^21.1.2",
"@types/katex": "^0.16.2",
"@types/node": "^20.5.7",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"eslint": "^8.48.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-next": "^13.4.9",
"eslint-config-next": "^13.4.19",
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-react": "^7.33.2",
Expand Down
6 changes: 5 additions & 1 deletion packages/viewer/src/app/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import UpdateButton from "@/components/UpdateButton";
export default function Page() {
const pathname = usePathname();
const params = useParams();
const { id } = params;
return (
<div className="my-screen-middle">
<div className="mx-auto" style={{ width: "max-content" }}>
Expand Down Expand Up @@ -62,7 +63,10 @@ export default function Page() {
</div>
{Number.isNaN(parseInt(pathname.slice(1), 10)) || (
<div className="mt-2x mb-1">
<UpdateButton className="w-100" target={params.id}>
<UpdateButton
className="w-100"
target={typeof id === "string" ? id : id[0]}
>
立即保存帖子
</UpdateButton>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/viewer/src/components/UpdateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default function UpdateButton({
onClick={() => {
setDisabled(true);
if (Number.isNaN(id) || !socketRef.current?.connected)
// eslint-disable-next-line @typescript-eslint/no-floating-promises
fetch(`${process.env.NEXT_PUBLIC_ARCHIVE_HOST ?? ""}/${target}`)
.then(() => router.refresh())
.finally(() => setDisabled(false));
Expand Down
6 changes: 3 additions & 3 deletions packages/viewer/src/components/replies/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ export default function Content({
const userRefs = useRef<Record<number, HTMLDivElement | null>>({});

useEffect(() => {
renderMathInElement(contentRef.current as HTMLDivElement, {
renderMathInElement(contentRef.current!, {
delimiters: [
{ left: "$$", right: "$$", display: true },
{ left: "$", right: "$", display: false },
],
});

contentRef.current?.querySelectorAll("a[data-uid]").forEach((element) => {
const uid = parseInt(element.getAttribute("data-uid") as string, 10);
const tooltip = userRefs.current[uid] as HTMLDivElement;
const uid = parseInt(element.getAttribute("data-uid")!, 10);
const tooltip = userRefs.current[uid]!;
if (!tooltip) return;

function update() {
Expand Down
14 changes: 7 additions & 7 deletions packages/viewer/src/components/replies/ContextViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import UserInfo from "@/components/UserInfo";
import type { UserMetioned } from "@/lib/serialize-reply";
import Content from "./Content";

type Data = {
interface Data {
id: number;
discussionId: number;
authorId: number;
time: string;
content: string;
usersMetioned: UserMetioned[];
};
}

export default function ContextViewer({
discussionAuthor,
Expand Down Expand Up @@ -58,27 +58,27 @@ export default function ContextViewer({
className="text-body-secondary"
style={{ fontSize: ".8em" }}
>
推测的上文,发布于 {(data as Data).time}
推测的上文,发布于 {data!.time}
</span>
) : pageIndex < 0 ? (
<span
className="text-body-tertiary"
style={{ fontSize: ".8em" }}
>
可能的上文,发布于 {(data as Data).time}
可能的上文,发布于 {data!.time}
</span>
) : (
<span
className="text-body-tertiary"
style={{ fontSize: ".8em" }}
>
本层后发布,发布于 {(data as Data).time}
本层后发布,发布于 {data!.time}
</span>
)}
<Content
discussionAuthor={discussionAuthor}
content={(data as Data).content}
usersMetioned={(data as Data).usersMetioned}
content={data!.content}
usersMetioned={data!.usersMetioned}
/>
</div>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Spinner from "@/components/Spinner";
import PageButtons from "./PageButtons";
import Reply from "./Reply";

type PageData = {
interface PageData {
data: {
id: number;
time: string;
Expand All @@ -19,7 +19,7 @@ type PageData = {
usersMetioned: UserMetioned[];
}[];
nextCursor: number;
};
}

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

Expand Down
1 change: 1 addition & 0 deletions packages/viewer/src/lib/luogu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function getDiscussionId(s: string) {
const url = new URL(s);
if (!isLuoguUrl(url)) return NaN;
return parseInt(
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
(url.pathname === "/discuss/show" && url.searchParams.get("postid")) ||
((url.pathname.startsWith("/discuss/") &&
url.pathname.split("/")[2]) as string),
Expand Down
22 changes: 10 additions & 12 deletions packages/viewer/src/lib/serialize-reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import stringifyTime from "@/lib/time";
export type UserMetioned = User & { numReplies?: number };

function getMentionedUser(element: Element) {
const href = element.getAttribute("href") as string;
const href = element.getAttribute("href")!;
return (
element.previousSibling?.nodeType === element.TEXT_NODE &&
element.previousSibling.nodeValue?.endsWith("@") &&
Expand Down Expand Up @@ -78,7 +78,7 @@ export default async function serializeReply(
element.setAttribute("rel", "noopener noreferrer");
try {
const urlAbsolute = new URL(
element.getAttribute("href") as string,
element.getAttribute("href")!,
"https://www.luogu.com.cn/discuss/",
);
element.setAttribute("href", urlAbsolute.href);
Expand Down Expand Up @@ -132,7 +132,7 @@ export default async function serializeReply(
.then((r) => Object.fromEntries(r.map((u) => [u.authorId, u._count]))),
prisma.user.findMany({ where: { id: { in: users } } }),
]);
const indUsersMetioned: { [k: number]: User } = {};
const indUsersMetioned: Record<number, User> = {};
// eslint-disable-next-line no-return-assign
usersMetioned.forEach((el) => (indUsersMetioned[el.id] = el));
// eslint-disable-next-line no-restricted-syntax
Expand All @@ -149,7 +149,7 @@ export default async function serializeReply(
const discussionsMetioned = await prisma.discussion.findMany({
where: { id: { in: discussions } },
});
const indDiscussionsMetioned: { [k: number]: Discussion } = {};
const indDiscussionsMetioned: Record<number, Discussion> = {};
// eslint-disable-next-line no-return-assign
discussionsMetioned.forEach((el) => (indDiscussionsMetioned[el.id] = el));
// eslint-disable-next-line no-restricted-syntax
Expand Down Expand Up @@ -189,7 +189,7 @@ export async function serializeReplyNoninteractive({
}) {
const users: number[] = [];
const userElements: { ele: Element; user: number }[] = [];
const links: Set<string> = new Set();
const links = new Set<string>();
const linkElements: { ele: Element; link: string }[] = [];

const { document } = new JSDOM(takedown ? getHtmlTookdown(takedown) : content)
Expand All @@ -200,7 +200,7 @@ export async function serializeReplyNoninteractive({
let flagLinkUnhandled = true;
try {
const urlAbsolute = new URL(
element.getAttribute("href") as string,
element.getAttribute("href")!,
"https://www.luogu.com.cn/discuss/",
);
element.setAttribute("href", urlAbsolute.href);
Expand All @@ -215,10 +215,8 @@ export async function serializeReplyNoninteractive({
} else {
flagLinkUnhandled = false;
if (
new URL(
element.textContent as string,
"https://www.luogu.com.cn/discuss/",
).href !== urlAbsolute.href
new URL(element.textContent!, "https://www.luogu.com.cn/discuss/")
.href !== urlAbsolute.href
) {
links.add(urlAbsolute.href);
linkElements.push({
Expand All @@ -244,7 +242,7 @@ export async function serializeReplyNoninteractive({
const usersMetioned = await prisma.user.findMany({
where: { id: { in: users } },
});
const indUsersMetioned: { [k: number]: User } = {};
const indUsersMetioned: Record<number, User> = {};
// eslint-disable-next-line no-return-assign
usersMetioned.forEach((el) => (indUsersMetioned[el.id] = el));
// eslint-disable-next-line no-restricted-syntax
Expand All @@ -253,7 +251,7 @@ export async function serializeReplyNoninteractive({
ue.ele.classList.add(`lg-fg-${indUsersMetioned[ue.user].color}`);
}
}
const indLinks: { [k: string]: number } = {};
const indLinks: Record<string, number> = {};
// eslint-disable-next-line no-return-assign
[...links].map((link, i) => (indLinks[link] = i + 1));
// eslint-disable-next-line no-restricted-syntax
Expand Down
Loading

0 comments on commit 0728dd2

Please sign in to comment.