Skip to content

Commit

Permalink
refactor: disallow open comment panel on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
shaokeyibb committed Oct 7, 2024
1 parent e367246 commit 355de04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions frontend/lib/dom/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import iconInfoOutlineRounded from "iconify/info-outline-rounded";
import { Comment } from "../types";
import { getJWT, decodeJWT, logout, fetchGitHubMeta } from "../auth";
import { apiEndpoint } from "../const";
import { groupBy, dateTimeFormatter } from "../util";
import { groupBy, dateTimeFormatter, isReallyMobile } from "../util";

let selectedOffset: HTMLElement | null = null;

Expand Down Expand Up @@ -123,7 +123,10 @@ export const selectOffsetParagraph = async ({
selectedOffset = el;
}

if (selectedOffset?.dataset.reviewHasComments || forceOpenCommentsPanel) {
if (
(!isReallyMobile() && selectedOffset?.dataset.reviewHasComments) ||
forceOpenCommentsPanel
) {
delete selectedOffset.dataset.reviewFocused;
selectedOffset.dataset.reviewSelected = "true";
// 只有在点击评论按钮时才会 focus 到评论框,这里 forceOpenCommentsPanel === true 就等价于点击评论按钮
Expand Down
6 changes: 6 additions & 0 deletions frontend/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ export const dateTimeFormatter = new Intl.DateTimeFormat("zh-CN", {
dateStyle: "short",
timeStyle: "short",
});

export function isReallyMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent,
);
}

0 comments on commit 355de04

Please sign in to comment.