mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
web: show exclusive titlebar in tablet/mobile mode
This commit is contained in:
committed by
Abdullah Atta
parent
69e6263d34
commit
202c9135c2
@@ -5,7 +5,8 @@
|
|||||||
|
|
||||||
.tabsScroll,
|
.tabsScroll,
|
||||||
.titlebarLogo,
|
.titlebarLogo,
|
||||||
.theme-scope-titleBar {
|
.theme-scope-titleBar,
|
||||||
|
.route-container-header {
|
||||||
-webkit-app-region: drag;
|
-webkit-app-region: drag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,11 +41,7 @@ import {
|
|||||||
TableOfContents,
|
TableOfContents,
|
||||||
Trash,
|
Trash,
|
||||||
Undo,
|
Undo,
|
||||||
Unlock,
|
Unlock
|
||||||
WindowClose,
|
|
||||||
WindowMaximize,
|
|
||||||
WindowMinimize,
|
|
||||||
WindowRestore
|
|
||||||
} from "../icons";
|
} from "../icons";
|
||||||
import { ScrollContainer } from "@notesnook/ui";
|
import { ScrollContainer } from "@notesnook/ui";
|
||||||
import {
|
import {
|
||||||
@@ -83,8 +79,8 @@ import { showPublishView } from "../publish-view";
|
|||||||
import { restrictToHorizontalAxis } from "@dnd-kit/modifiers";
|
import { restrictToHorizontalAxis } from "@dnd-kit/modifiers";
|
||||||
import useMobile from "../../hooks/use-mobile";
|
import useMobile from "../../hooks/use-mobile";
|
||||||
import { strings } from "@notesnook/intl";
|
import { strings } from "@notesnook/intl";
|
||||||
import { TITLE_BAR_HEIGHT } from "../title-bar";
|
import { TITLE_BAR_HEIGHT, getWindowControls } from "../title-bar";
|
||||||
import { desktop } from "../../common/desktop-bridge";
|
import useTablet from "../../hooks/use-tablet";
|
||||||
|
|
||||||
export function EditorActionBar() {
|
export function EditorActionBar() {
|
||||||
const { isMaximized, isFullscreen, hasNativeWindowControls } =
|
const { isMaximized, isFullscreen, hasNativeWindowControls } =
|
||||||
@@ -102,6 +98,7 @@ export function EditorActionBar() {
|
|||||||
const isNotePublished =
|
const isNotePublished =
|
||||||
activeSession && db.monographs.isPublished(activeSession.id);
|
activeSession && db.monographs.isPublished(activeSession.id);
|
||||||
const isMobile = useMobile();
|
const isMobile = useMobile();
|
||||||
|
const isTablet = useTablet();
|
||||||
|
|
||||||
const tools = [
|
const tools = [
|
||||||
{
|
{
|
||||||
@@ -202,31 +199,13 @@ export function EditorActionBar() {
|
|||||||
!isFocusMode,
|
!isFocusMode,
|
||||||
onClick: () => useEditorStore.getState().toggleProperties()
|
onClick: () => useEditorStore.getState().toggleProperties()
|
||||||
},
|
},
|
||||||
|
...getWindowControls(
|
||||||
{
|
hasNativeWindowControls,
|
||||||
title: strings.minimize(),
|
isFullscreen,
|
||||||
icon: WindowMinimize,
|
isMaximized,
|
||||||
hidden: hasNativeWindowControls || isFullscreen,
|
isTablet,
|
||||||
enabled: true,
|
isMobile
|
||||||
onClick: () => desktop?.window.minimze.mutate()
|
)
|
||||||
},
|
|
||||||
{
|
|
||||||
title: isMaximized ? strings.restore() : strings.maximize(),
|
|
||||||
icon: isMaximized ? WindowRestore : WindowMaximize,
|
|
||||||
enabled: true,
|
|
||||||
hidden: hasNativeWindowControls || isFullscreen,
|
|
||||||
onClick: () =>
|
|
||||||
isMaximized
|
|
||||||
? desktop?.window.restore.mutate()
|
|
||||||
: desktop?.window.maximize.mutate()
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: strings.close(),
|
|
||||||
icon: WindowClose,
|
|
||||||
hidden: hasNativeWindowControls || isFullscreen,
|
|
||||||
enabled: true,
|
|
||||||
onClick: () => window.close()
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -263,7 +242,7 @@ export function EditorActionBar() {
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
bg: "transparent",
|
bg: "transparent",
|
||||||
display: [
|
display: [
|
||||||
tool.hideOnMobile ? "none" : "flex",
|
"hideOnMobile" in tool && tool.hideOnMobile ? "none" : "flex",
|
||||||
tool.hidden ? "none" : "flex"
|
tool.hidden ? "none" : "flex"
|
||||||
],
|
],
|
||||||
borderRadius: 0,
|
borderRadius: 0,
|
||||||
@@ -475,12 +454,12 @@ function Tab(props: TabProps) {
|
|||||||
? Lock
|
? Lock
|
||||||
: Unlock
|
: Unlock
|
||||||
: type === "readonly"
|
: type === "readonly"
|
||||||
? Readonly
|
? Readonly
|
||||||
: type === "deleted"
|
: type === "deleted"
|
||||||
? Trash
|
? Trash
|
||||||
: isUnsaved
|
: isUnsaved
|
||||||
? NoteRemove
|
? NoteRemove
|
||||||
: Note;
|
: Note;
|
||||||
const { attributes, listeners, setNodeRef, transform, transition, active } =
|
const { attributes, listeners, setNodeRef, transform, transition, active } =
|
||||||
useSortable({ id });
|
useSortable({ id });
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ function Header(props: RouteContainerProps) {
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
height: TITLE_BAR_HEIGHT,
|
height: TITLE_BAR_HEIGHT,
|
||||||
zIndex: 2
|
zIndex: 2,
|
||||||
|
px: 1
|
||||||
}}
|
}}
|
||||||
className="route-container-header search-container"
|
className="route-container-header search-container"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -20,12 +20,71 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
import { useWindowControls } from "../../hooks/use-window-controls";
|
import { useWindowControls } from "../../hooks/use-window-controls";
|
||||||
import { isMac } from "../../utils/platform";
|
import { isMac } from "../../utils/platform";
|
||||||
import { BaseThemeProvider } from "../theme-provider";
|
import { BaseThemeProvider } from "../theme-provider";
|
||||||
|
import { strings } from "@notesnook/intl";
|
||||||
|
import { desktop } from "../../common/desktop-bridge";
|
||||||
|
import {
|
||||||
|
WindowClose,
|
||||||
|
WindowMaximize,
|
||||||
|
WindowMinimize,
|
||||||
|
WindowRestore
|
||||||
|
} from "../icons";
|
||||||
|
import { Button, Flex } from "@theme-ui/components";
|
||||||
|
import useMobile from "../../hooks/use-mobile";
|
||||||
|
import useTablet from "../../hooks/use-tablet";
|
||||||
|
|
||||||
|
export function getWindowControls(
|
||||||
|
hasNativeWindowControls: boolean,
|
||||||
|
isFullscreen?: boolean,
|
||||||
|
isMaximized?: boolean,
|
||||||
|
isTablet?: boolean,
|
||||||
|
isMobile?: boolean
|
||||||
|
) {
|
||||||
|
if (isMobile || isTablet) return [];
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
title: strings.minimize(),
|
||||||
|
icon: WindowMinimize,
|
||||||
|
hidden: hasNativeWindowControls || isFullscreen,
|
||||||
|
enabled: true,
|
||||||
|
onClick: () => desktop?.window.minimze.mutate()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: isMaximized ? strings.restore() : strings.maximize(),
|
||||||
|
icon: isMaximized ? WindowRestore : WindowMaximize,
|
||||||
|
enabled: true,
|
||||||
|
hidden: hasNativeWindowControls || isFullscreen,
|
||||||
|
onClick: () =>
|
||||||
|
isMaximized
|
||||||
|
? desktop?.window.restore.mutate()
|
||||||
|
: desktop?.window.maximize.mutate()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: strings.close(),
|
||||||
|
icon: WindowClose,
|
||||||
|
hidden: hasNativeWindowControls || isFullscreen,
|
||||||
|
enabled: true,
|
||||||
|
onClick: () => window.close()
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
export const TITLE_BAR_HEIGHT = 37;
|
export const TITLE_BAR_HEIGHT = 37;
|
||||||
export function TitleBar() {
|
export function TitleBar({ isUnderlay = isMac() }: { isUnderlay?: boolean }) {
|
||||||
const { isFullscreen } = useWindowControls();
|
const { isFullscreen, hasNativeWindowControls, isMaximized } =
|
||||||
|
useWindowControls();
|
||||||
|
const isTablet = useTablet();
|
||||||
|
const isMobile = useMobile();
|
||||||
|
if (
|
||||||
|
(!isMobile && !isTablet) ||
|
||||||
|
hasNativeWindowControls ||
|
||||||
|
(isFullscreen && isMac())
|
||||||
|
)
|
||||||
|
return null;
|
||||||
|
|
||||||
if (isFullscreen || !IS_DESKTOP_APP || !isMac()) return null;
|
const tools = getWindowControls(
|
||||||
|
hasNativeWindowControls,
|
||||||
|
isFullscreen,
|
||||||
|
isMaximized
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<BaseThemeProvider
|
<BaseThemeProvider
|
||||||
scope="titleBar"
|
scope="titleBar"
|
||||||
@@ -36,14 +95,62 @@ export function TitleBar() {
|
|||||||
minHeight: TITLE_BAR_HEIGHT,
|
minHeight: TITLE_BAR_HEIGHT,
|
||||||
maxHeight: TITLE_BAR_HEIGHT,
|
maxHeight: TITLE_BAR_HEIGHT,
|
||||||
display: "flex",
|
display: "flex",
|
||||||
|
justifyContent: "space-between",
|
||||||
flexShrink: 0,
|
flexShrink: 0,
|
||||||
position: "absolute",
|
|
||||||
top: 0,
|
|
||||||
width: "100%",
|
width: "100%",
|
||||||
zIndex: 1,
|
zIndex: 1,
|
||||||
borderBottom: "1px solid var(--border)"
|
borderBottom: "1px solid var(--border)",
|
||||||
|
...(isUnderlay
|
||||||
|
? {
|
||||||
|
position: "absolute",
|
||||||
|
top: 0
|
||||||
|
}
|
||||||
|
: {})
|
||||||
}}
|
}}
|
||||||
injectCssVars
|
injectCssVars
|
||||||
></BaseThemeProvider>
|
>
|
||||||
|
{tools.length > 0 ? (
|
||||||
|
<svg
|
||||||
|
className="titlebarLogo"
|
||||||
|
style={{
|
||||||
|
alignSelf: "center",
|
||||||
|
height: 16,
|
||||||
|
width: 12,
|
||||||
|
marginRight: 10,
|
||||||
|
marginLeft: 10
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<use href="#themed-logo" />
|
||||||
|
</svg>
|
||||||
|
) : null}
|
||||||
|
<Flex sx={{ alignItems: "center" }}>
|
||||||
|
{tools.map((tool) => (
|
||||||
|
<Button
|
||||||
|
data-test-id={tool.title}
|
||||||
|
disabled={!tool.enabled}
|
||||||
|
variant={tool.title === "Close" ? "error" : "secondary"}
|
||||||
|
title={tool.title}
|
||||||
|
key={tool.title}
|
||||||
|
sx={{
|
||||||
|
height: "100%",
|
||||||
|
alignItems: "center",
|
||||||
|
bg: "transparent",
|
||||||
|
display: tool.hidden ? "none" : "flex",
|
||||||
|
borderRadius: 0,
|
||||||
|
flexShrink: 0,
|
||||||
|
"&:hover svg path": {
|
||||||
|
fill:
|
||||||
|
tool.title === "Close"
|
||||||
|
? "var(--accentForeground-error) !important"
|
||||||
|
: "var(--icon)"
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onClick={tool.onClick}
|
||||||
|
>
|
||||||
|
<tool.icon size={18} />
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</Flex>
|
||||||
|
</BaseThemeProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export async function startApp() {
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
root.render(
|
root.render(
|
||||||
<>
|
<>
|
||||||
<TitleBar />
|
<TitleBar isUnderlay={false} />
|
||||||
<ErrorComponent
|
<ErrorComponent
|
||||||
error={e}
|
error={e}
|
||||||
resetErrorBoundary={() => window.location.reload()}
|
resetErrorBoundary={() => window.location.reload()}
|
||||||
|
|||||||
Reference in New Issue
Block a user