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 6, 2024
1 parent 0e07caa commit d45645e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 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,7 @@ 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
10 changes: 8 additions & 2 deletions frontend/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const groupBy = function <K extends string, T>(
arr: T[],
func: (el: T) => K,
func: (el: T) => K
) {
return arr.reduce(
(acc, x) => {
Expand All @@ -9,11 +9,17 @@ export const groupBy = function <K extends string, T>(
},
{} as {
[key: string]: T[];
},
}
);
};

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 d45645e

Please sign in to comment.