From da642a8a4c201b7d35d1e0a459643a96afb690ba Mon Sep 17 00:00:00 2001 From: shaokeyibb Date: Sun, 6 Oct 2024 15:13:58 +0800 Subject: [PATCH] refactor: disallow open comment panel on mobile --- frontend/lib/dom/comment.ts | 7 +++++-- frontend/lib/util.ts | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend/lib/dom/comment.ts b/frontend/lib/dom/comment.ts index 1dd8d4a5..84c827c1 100644 --- a/frontend/lib/dom/comment.ts +++ b/frontend/lib/dom/comment.ts @@ -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; @@ -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 就等价于点击评论按钮 diff --git a/frontend/lib/util.ts b/frontend/lib/util.ts index 462a5a4e..92d3dd5c 100644 --- a/frontend/lib/util.ts +++ b/frontend/lib/util.ts @@ -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, + ); +}