Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: disallow open comment panel on mobile #139

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Enter-tainer marked this conversation as resolved.
Show resolved Hide resolved
navigator.userAgent,
);
}