Skip to content

Commit

Permalink
feat: 后台编辑器增加保存快捷键提示
Browse files Browse the repository at this point in the history
  • Loading branch information
Mereithhh committed Mar 22, 2023
1 parent dec024b commit 70a6895
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/admin/src/components/SaveTip/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isMac, isMobileByScreenSize } from "@/services/van-blog/ua"
import { useMemo } from "react"

export const SaveTip = () => {
const text = useMemo(() => {
if (isMobileByScreenSize()) {
return "保存"
} else {
if (isMac()) {
return "保存 ⌘ + S"
} else {
return "保存 Ctrl + S"
}
}

}, [])
return <span>{text}</span>
}
3 changes: 2 additions & 1 deletion packages/admin/src/pages/Editor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import EditorProfileModal from '@/components/EditorProfileModal';
import PublishDraftModal from '@/components/PublishDraftModal';
import Tags from '@/components/Tags';
import UpdateModal from '@/components/UpdateModal';
import { SaveTip } from "@/components/SaveTip";
import {
deleteArticle,
deleteDraft,
Expand Down Expand Up @@ -405,7 +406,7 @@ export default function () {
),
extra: [
<Button key="extraSaveBtn" type="primary" onClick={handleSave}>
保存
{<SaveTip />}
</Button>,
<Button
key="backBtn"
Expand Down
6 changes: 6 additions & 0 deletions packages/admin/src/services/van-blog/ua.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const isMac = (): boolean =>
typeof navigator !== "undefined" &&
Boolean(navigator.userAgent?.toLowerCase().includes("mac"));
export const isMobileByScreenSize = (): boolean =>
typeof matchMedia !== "undefined" &&
!matchMedia(`(min-width: 768px)`)?.matches;

0 comments on commit 70a6895

Please sign in to comment.