Skip to content

Commit

Permalink
Merge pull request #8 from slotDumpling/reader-menu
Browse files Browse the repository at this point in the history
feat: move reader menu to top-right for desktop
  • Loading branch information
slotDumpling authored Aug 1, 2024
2 parents d850ed2 + 1210ae1 commit 2e5906c
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 75 deletions.
2 changes: 2 additions & 0 deletions src/pages/reader/Header/Right.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { useAsideOpen } from "lib/hooks";
import { sortBy } from "lodash";
import IconFont from "component/IconFont";
import { useDrawCtrl, useUpdateDrawCtrl } from "lib/draw/DrawCtrl";
import { OptionButton } from "../Options";

export const HeaderRight: FC<{
instantSave: () => Promise<void> | undefined;
Expand All @@ -58,6 +59,7 @@ export const HeaderRight: FC<{
<div className="right">
{teamOn ? <RoomInfo /> : <JoinRoom instantSave={instantSave} />}
<PageNavButton />
<OptionButton placement="bottomRight" />
</div>
);
};
Expand Down
7 changes: 6 additions & 1 deletion src/pages/reader/Header/header.sass
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
grid-column: span 3
@include for-desktop
height: $header-low-height
> .left, > .right
> .left
grid-template-columns: repeat(2, 1fr)
> .right
grid-template-columns: repeat(3, 1fr)
> .middle
grid-template-columns: repeat(7, 1fr)
.redo-btn
Expand Down Expand Up @@ -73,6 +75,9 @@
max-width: 200px
&[data-show=false]
display: none
> .right .reader-option-btn
@include for-phone
display: none

.team-title
display: flex
Expand Down
54 changes: 54 additions & 0 deletions src/pages/reader/Options/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { FC } from "react";
import { Button, Popover, Switch } from "antd";
import { TooltipPlacement } from "antd/lib/tooltip";
import { useForceLight } from "lib/Dark";
import { useDrawCtrl, useUpdateDrawCtrl } from "lib/draw/DrawCtrl";
import { useMediaQuery } from "react-responsive";
import { MoreOutlined } from "@ant-design/icons";
import "./options.sass";

export const OptionButton: FC<{
placement?: TooltipPlacement;
}> = ({ placement }) => {
const { finger } = useDrawCtrl();
const updateDrawCtrl = useUpdateDrawCtrl();
const [forceLight, setForceLight] = useForceLight();
const isLight = useMediaQuery({ query: "(prefers-color-scheme: light)" });

const options = (
<div className="reader-options">
<div className="other-option">
<span>Pencil only</span>
<Switch
size="small"
checked={!finger}
onChange={(v) => updateDrawCtrl({ finger: !v })}
/>
</div>
<div className="other-option">
<span>Light mode</span>
<Switch
size="small"
checked={forceLight || isLight}
disabled={isLight}
onChange={setForceLight}
/>
</div>
</div>
);

return (
<Popover
getPopupContainer={(e) => e.parentElement!}
trigger="click"
content={options}
placement={placement}
>
<Button
type="text"
icon={<MoreOutlined />}
className="reader-option-btn"
/>
</Popover>
);
};
15 changes: 15 additions & 0 deletions src/pages/reader/Options/options.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@import ../../../sass/_mixins
@import ../../../sass/_var

.reader-options .other-option
width: 120px
display: flex
justify-content: space-between
align-items: center
padding-bottom: 10px
&:last-of-type
padding: 0
.ant-switch
box-shadow: 0 0 0 1px #eee
.ant-switch-handle::before
border: $default-border
63 changes: 3 additions & 60 deletions src/pages/reader/PageNav/PageNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@ import {
DropResult,
DragDropContext,
} from "react-beautiful-dnd";
import {
Avatar,
Button,
Menu,
Pagination,
Popover,
Select,
Switch,
Tabs,
} from "antd";
import { Avatar, Button, Menu, Pagination, Popover, Select, Tabs } from "antd";
import {
Setter,
useActiveKey,
Expand All @@ -47,9 +38,7 @@ import { NotePage } from "lib/note/note";
import { TeamState } from "lib/draw/TeamState";
import { AddPageButton } from "../tools/AddButton";
import { CSSTransition } from "react-transition-group";
import { useForceLight } from "lib/Dark";
import { useDrawCtrl, useUpdateDrawCtrl } from "lib/draw/DrawCtrl";
import { useMediaQuery } from "react-responsive";
import { OptionButton } from "../Options";

type PreviewProps = ReaderMethods & ReaderStates;
export const PageNav: FC<PreviewProps> = (props) => {
Expand Down Expand Up @@ -444,7 +433,6 @@ const PreviewFooter: FC<PreviewProps> = ({
{pageIndex} / {pageOrder.length}
</Button>
</Popover>
<FooterOptions />
<Select
className="size-select"
popupClassName="size-drop"
Expand All @@ -461,52 +449,7 @@ const PreviewFooter: FC<PreviewProps> = ({
placement="topRight"
getPopupContainer={(e) => e.parentElement!}
/>
<OptionButton placement="topRight" />
</footer>
);
};

const FooterOptions = () => {
const { finger } = useDrawCtrl();
const updateDrawCtrl = useUpdateDrawCtrl();
const [forceLight, setForceLight] = useForceLight();
const isLight = useMediaQuery({ query: "(prefers-color-scheme: light)" });

const options = (
<>
<div className="footer-option">
<span>Pencil only</span>
<Switch
size="small"
checked={!finger}
onChange={(v) => updateDrawCtrl({ finger: !v })}
/>
</div>
<div className="footer-option">
<span>Light mode</span>
<Switch
size="small"
checked={forceLight || isLight}
disabled={isLight}
onChange={setForceLight}
/>
</div>
</>
);

return (
<Popover
getPopupContainer={(e) => e.parentElement!}
trigger="click"
content={options}
placement="topRight"
>
<Button
className="option-btn"
size="small"
type="text"
shape="circle"
icon={<MoreOutlined />}
/>
</Popover>
);
};
19 changes: 5 additions & 14 deletions src/pages/reader/PageNav/page-nav.sass
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ $card-width: 200px
@include for-phone
padding: $header-high-height+10px 10px calc(10px + $safe-bottom) 10px

@media (hover: none)
main[data-finger=true] ~ .preview-drop
main[data-finger=true] ~ .preview-drop
@media (hover: none)
right: 30px

body.ant-scrolling-effect .preview-drop
Expand Down Expand Up @@ -173,18 +173,9 @@ body.ant-scrolling-effect .preview-drop
.size-select
@include for-phone
display: none
.footer-option
width: 120px
display: flex
justify-content: space-between
align-items: center
padding-bottom: 10px
&:last-of-type
padding: 0
.ant-switch
box-shadow: 0 0 0 1px #eee
.ant-switch-handle::before
border: $default-border
.reader-option-btn
@include for-desktop
display: none

.preview-avatar
box-sizing: content-box
Expand Down

0 comments on commit 2e5906c

Please sign in to comment.