feat: improve mobile board experience
This commit is contained in:
1 parent
bc57f9579d
commit
7c0e98c55b
46 files changed
+1455
-130
No files matched your search
@@ -44,6 +44,7 @@ export const createBoardContentPage = <TParams extends Record<string, unknown>>(
|
||||
headerActions: <BoardContentHeaderActions demoReadOnly={env.DEMO_MODE && env.DEMO_READ_ONLY} />,
|
||||
getInitialBoardAsync: getInitialBoard,
|
||||
withTour: true,
|
||||
mobileProfileInActions: true,
|
||||
}),
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
page: async ({ params }: { params: Promise<TParams> }) => {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect } from "react";
|
||||
import { useCallback, useEffect, useMemo } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { OnboardingTour } from "@gfazioli/mantine-onboarding-tour";
|
||||
import { Box, Group, Menu, ScrollArea } from "@mantine/core";
|
||||
import { useHotkeys } from "@mantine/hooks";
|
||||
import { Box, Button, Divider, Drawer, Group, Menu, ScrollArea, Stack, Text } from "@mantine/core";
|
||||
import { useDisclosure, useHotkeys, useReducedMotion } from "@mantine/hooks";
|
||||
import {
|
||||
IconBox,
|
||||
IconBoxAlignTop,
|
||||
@@ -17,11 +17,18 @@ import {
|
||||
IconReplace,
|
||||
IconResize,
|
||||
IconSettings,
|
||||
IconDotsVertical,
|
||||
IconHome,
|
||||
IconLogin,
|
||||
IconList,
|
||||
IconLogout,
|
||||
IconTool,
|
||||
IconUser,
|
||||
} from "@tabler/icons-react";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useSession } from "@homarr/auth/client";
|
||||
import { useRequiredBoard } from "@homarr/boards/context";
|
||||
import { signOut, useSession } from "@homarr/auth/client";
|
||||
import { getDesktopLayout, useRequiredBoard } from "@homarr/boards/context";
|
||||
import { useEditMode } from "@homarr/boards/edit-mode";
|
||||
import { revalidatePathActionAsync } from "@homarr/common/client";
|
||||
import { env } from "@homarr/common/env";
|
||||
@@ -32,14 +39,18 @@ import { showErrorNotification, showSuccessNotification } from "@homarr/notifica
|
||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||
import { Link } from "@homarr/ui";
|
||||
|
||||
import { useAuthContext } from "~/app/[locale]/_client-providers/session";
|
||||
import { useItemActions } from "~/components/board/items/item-actions";
|
||||
import { ItemSelectModal } from "~/components/board/items/item-select-modal";
|
||||
import { useBoardPermissions } from "~/components/board/permissions/client";
|
||||
import { useCategoryActions } from "~/components/board/sections/category/category-actions";
|
||||
import { CategoryEditModal } from "~/components/board/sections/category/category-edit-modal";
|
||||
import { useDynamicSectionActions } from "~/components/board/sections/dynamic/dynamic-actions";
|
||||
import { createMobileBoardElements } from "~/components/board/mobile/mobile-layout";
|
||||
import { useIsMobileBoard } from "~/components/board/use-mobile-board";
|
||||
import { IntegrationSelectModal } from "~/components/integration/integration-select-modal";
|
||||
import { CurrentColorSchemeCombobox } from "~/components/color-scheme/current-color-scheme-combobox";
|
||||
import { CurrentLanguageCombobox } from "~/components/language/current-language-combobox";
|
||||
import { HeaderButton } from "~/components/layout/header/button";
|
||||
|
||||
export const BoardContentHeaderActions = ({ demoReadOnly }: { demoReadOnly: boolean }) => {
|
||||
@@ -47,6 +58,11 @@ export const BoardContentHeaderActions = ({ demoReadOnly }: { demoReadOnly: bool
|
||||
const board = useRequiredBoard();
|
||||
const { hasChangeAccess } = useBoardPermissions(board);
|
||||
const isMobile = useIsMobileBoard();
|
||||
const t = useI18n();
|
||||
|
||||
if (isMobile) {
|
||||
return <MobileMoreMenu showSettings={hasChangeAccess && !demoReadOnly} />;
|
||||
}
|
||||
|
||||
if (!hasChangeAccess) {
|
||||
return <SelectBoardsMenu />;
|
||||
@@ -60,7 +76,7 @@ export const BoardContentHeaderActions = ({ demoReadOnly }: { demoReadOnly: bool
|
||||
|
||||
{!demoReadOnly && (
|
||||
<OnboardingTour.Target id="board-settings">
|
||||
<HeaderButton href={`/boards/${board.name}/settings`}>
|
||||
<HeaderButton href={`/boards/${board.name}/settings`} aria-label={t("item.menu.label.settings")}>
|
||||
<IconSettings stroke={1.5} />
|
||||
</HeaderButton>
|
||||
</OnboardingTour.Target>
|
||||
@@ -125,7 +141,7 @@ const AddMenu = () => {
|
||||
return (
|
||||
<Menu position="bottom-end">
|
||||
<Menu.Target>
|
||||
<HeaderButton w="auto" px={4}>
|
||||
<HeaderButton w="auto" px={4} aria-label={t("common.action.add")}>
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<IconPlus stroke={1.5} />
|
||||
<IconChevronDown color="gray" size={16} />
|
||||
@@ -164,6 +180,7 @@ const EditModeMenu = ({ demoReadOnly, hidden }: { demoReadOnly: boolean; hidden:
|
||||
const board = useRequiredBoard();
|
||||
const utils = clientApi.useUtils();
|
||||
const t = useScopedI18n("board.action.edit");
|
||||
const tItem = useScopedI18n("item");
|
||||
const { mutate: saveBoard, isPending } = clientApi.board.saveBoard.useMutation({
|
||||
onSuccess() {
|
||||
showSuccessNotification({
|
||||
@@ -203,7 +220,7 @@ const EditModeMenu = ({ demoReadOnly, hidden }: { demoReadOnly: boolean; hidden:
|
||||
|
||||
return (
|
||||
<OnboardingTour.Target id="board-edit-mode">
|
||||
<HeaderButton onClick={toggle} loading={isPending}>
|
||||
<HeaderButton onClick={toggle} loading={isPending} aria-label={tItem("action.edit")}>
|
||||
{isEditMode ? <IconPencilOff stroke={1.5} /> : <IconPencil stroke={1.5} />}
|
||||
</HeaderButton>
|
||||
</OnboardingTour.Target>
|
||||
@@ -212,13 +229,14 @@ const EditModeMenu = ({ demoReadOnly, hidden }: { demoReadOnly: boolean; hidden:
|
||||
|
||||
const SelectBoardsMenu = () => {
|
||||
const { data: boards = [] } = clientApi.board.getAllBoards.useQuery();
|
||||
const t = useI18n();
|
||||
|
||||
return (
|
||||
<OnboardingTour.Target id="board-switcher">
|
||||
<Box>
|
||||
<Menu position="bottom-end">
|
||||
<Menu.Target>
|
||||
<HeaderButton w="auto" px={4}>
|
||||
<HeaderButton w="auto" px={4} aria-label={t("board.mobile.currentBoard")}>
|
||||
<IconReplace stroke={1.5} />
|
||||
</HeaderButton>
|
||||
</Menu.Target>
|
||||
@@ -242,6 +260,145 @@ const SelectBoardsMenu = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const MobileMoreMenu = ({ showSettings }: { showSettings: boolean }) => {
|
||||
const board = useRequiredBoard();
|
||||
const { data: session } = useSession();
|
||||
const { logoutUrl } = useAuthContext();
|
||||
const t = useI18n();
|
||||
const tProfile = useScopedI18n("common.userAvatar.menu");
|
||||
const reduceMotion = useReducedMotion();
|
||||
const [opened, disclosure] = useDisclosure(false);
|
||||
const desktopLayout = getDesktopLayout(board);
|
||||
const sections = useMemo(
|
||||
() => createMobileBoardElements(board, desktopLayout.id).filter((element) => element.type === "sectionHeading"),
|
||||
[board, desktopLayout.id],
|
||||
);
|
||||
|
||||
const jumpToSection = (anchorId: string) => {
|
||||
disclosure.close();
|
||||
requestAnimationFrame(() => {
|
||||
const heading = document.getElementById(anchorId);
|
||||
heading?.scrollIntoView({ behavior: reduceMotion ? "auto" : "smooth", block: "start" });
|
||||
heading?.focus({ preventScroll: true });
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<HeaderButton onClick={disclosure.open} aria-label={t("board.mobile.more")}>
|
||||
<IconDotsVertical stroke={1.5} />
|
||||
</HeaderButton>
|
||||
<Drawer
|
||||
opened={opened}
|
||||
onClose={disclosure.close}
|
||||
title={t("board.mobile.more")}
|
||||
position="bottom"
|
||||
size="auto"
|
||||
padding="md"
|
||||
overlayProps={{ backgroundOpacity: 0.45, blur: 2 }}
|
||||
>
|
||||
<Stack gap="xs" pb="calc(var(--mantine-spacing-sm) + env(safe-area-inset-bottom))">
|
||||
<Button
|
||||
component={Link}
|
||||
href="/boards"
|
||||
variant="subtle"
|
||||
size="lg"
|
||||
justify="flex-start"
|
||||
leftSection={<IconHome size={20} />}
|
||||
>
|
||||
{tProfile("homeBoard")}
|
||||
</Button>
|
||||
<CurrentColorSchemeCombobox w="100%" />
|
||||
<CurrentLanguageCombobox width="100%" withinPortal={false} />
|
||||
{session ? (
|
||||
<>
|
||||
<Button
|
||||
component={Link}
|
||||
href={`/manage/users/${session.user.id}/general`}
|
||||
variant="subtle"
|
||||
size="lg"
|
||||
justify="flex-start"
|
||||
leftSection={<IconUser size={20} />}
|
||||
>
|
||||
{tProfile("preferences")}
|
||||
</Button>
|
||||
<Button
|
||||
component={Link}
|
||||
href="/manage"
|
||||
variant="subtle"
|
||||
size="lg"
|
||||
justify="flex-start"
|
||||
leftSection={<IconTool size={20} />}
|
||||
>
|
||||
{tProfile("management")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="subtle"
|
||||
color="red"
|
||||
size="lg"
|
||||
justify="flex-start"
|
||||
leftSection={<IconLogout size={20} />}
|
||||
onClick={() => {
|
||||
void signOut({ redirect: false }).then(() => {
|
||||
window.location.assign(logoutUrl ?? "/auth/login");
|
||||
});
|
||||
}}
|
||||
>
|
||||
{tProfile("logout")}
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<Button
|
||||
component={Link}
|
||||
href="/auth/login"
|
||||
variant="subtle"
|
||||
size="lg"
|
||||
justify="flex-start"
|
||||
leftSection={<IconLogin size={20} />}
|
||||
>
|
||||
{tProfile("login")}
|
||||
</Button>
|
||||
)}
|
||||
{showSettings && (
|
||||
<Button
|
||||
component={Link}
|
||||
href={`/boards/${board.name}/settings`}
|
||||
variant="subtle"
|
||||
size="lg"
|
||||
justify="flex-start"
|
||||
leftSection={<IconSettings size={20} />}
|
||||
>
|
||||
{t("item.menu.label.settings")}
|
||||
</Button>
|
||||
)}
|
||||
{sections.length >= 2 && (
|
||||
<>
|
||||
{showSettings && <Divider />}
|
||||
<Group gap="xs" px="sm" pt="xs">
|
||||
<IconList size={18} aria-hidden />
|
||||
<Text size="sm" fw={600}>
|
||||
{t("board.mobile.sections")}
|
||||
</Text>
|
||||
</Group>
|
||||
{sections.map((section) => (
|
||||
<Button
|
||||
key={section.id}
|
||||
variant="subtle"
|
||||
size="lg"
|
||||
justify="flex-start"
|
||||
onClick={() => jumpToSection(section.anchorId)}
|
||||
>
|
||||
{section.title}
|
||||
</Button>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
</Drawer>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const anchorSelector = "a[href]:not([target='_blank'])";
|
||||
const usePreventLeaveWithDirty = (isDirty: boolean) => {
|
||||
const t = useI18n();
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
"use client";
|
||||
|
||||
import { Group, Menu, ScrollArea, Text, UnstyledButton } from "@mantine/core";
|
||||
import { IconCheck, IconChevronDown, IconLayoutBoard } from "@tabler/icons-react";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useRequiredBoard } from "@homarr/boards/context";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { Link } from "@homarr/ui";
|
||||
|
||||
import { BoardLogo } from "~/components/layout/logo/board-logo";
|
||||
|
||||
export const BoardSwitcherLogo = () => {
|
||||
const board = useRequiredBoard();
|
||||
const { data: boards = [] } = clientApi.board.getAllBoards.useQuery();
|
||||
const t = useI18n();
|
||||
|
||||
return (
|
||||
<Menu position="bottom-start" width={280}>
|
||||
<Menu.Target>
|
||||
<UnstyledButton
|
||||
aria-label={`${t("board.mobile.currentBoard")}: ${board.name}`}
|
||||
maw="min(42vw, 20rem)"
|
||||
mih={44}
|
||||
px={4}
|
||||
>
|
||||
<Group gap="xs" wrap="nowrap">
|
||||
<BoardLogo size={28} />
|
||||
<Text fw={600} truncate>
|
||||
{board.name}
|
||||
</Text>
|
||||
<IconChevronDown size={16} aria-hidden />
|
||||
</Group>
|
||||
</UnstyledButton>
|
||||
</Menu.Target>
|
||||
<Menu.Dropdown>
|
||||
<Menu.Label>{t("board.mobile.currentBoard")}</Menu.Label>
|
||||
<ScrollArea.Autosize mah={320}>
|
||||
{boards.map((availableBoard) => {
|
||||
const isCurrent = availableBoard.id === board.id;
|
||||
return (
|
||||
<Menu.Item
|
||||
key={availableBoard.id}
|
||||
component={Link}
|
||||
href={`/boards/${availableBoard.name}`}
|
||||
leftSection={isCurrent ? <IconCheck size={20} /> : <IconLayoutBoard size={20} />}
|
||||
aria-current={isCurrent ? "page" : undefined}
|
||||
>
|
||||
{availableBoard.name}
|
||||
</Menu.Item>
|
||||
);
|
||||
})}
|
||||
</ScrollArea.Autosize>
|
||||
</Menu.Dropdown>
|
||||
</Menu>
|
||||
);
|
||||
};
|
||||
@@ -3,14 +3,16 @@
|
||||
import { IconLayoutBoard } from "@tabler/icons-react";
|
||||
|
||||
import { useRequiredBoard } from "@homarr/boards/context";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
import { HeaderButton } from "~/components/layout/header/button";
|
||||
|
||||
export const BoardOtherHeaderActions = () => {
|
||||
const board = useRequiredBoard();
|
||||
const t = useI18n();
|
||||
|
||||
return (
|
||||
<HeaderButton href={`/boards/${board.name}`}>
|
||||
<HeaderButton href={`/boards/${board.name}`} aria-label={t("common.userAvatar.menu.homeBoard")}>
|
||||
<IconLayoutBoard stroke={1.5} />
|
||||
</HeaderButton>
|
||||
);
|
||||
|
||||
@@ -10,9 +10,9 @@ import { EditModeProvider } from "@homarr/boards/edit-mode";
|
||||
import { userAgent } from "@homarr/common/server";
|
||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||
|
||||
import type { MobileBoardDeviceClass } from "~/components/board/use-mobile-board";
|
||||
import { MobileBoardViewportProvider } from "~/components/board/use-mobile-board";
|
||||
import { MainHeader } from "~/components/layout/header";
|
||||
import { BoardLogoWithTitle } from "~/components/layout/logo/board-logo";
|
||||
import { ClientShell } from "~/components/layout/shell";
|
||||
import { BoardTourProvider } from "~/components/onboarding/board-tour";
|
||||
import { getCurrentColorSchemeAsync } from "~/theme/color-scheme";
|
||||
@@ -21,6 +21,7 @@ import type { Params } from "./(content)/_creator";
|
||||
import { CustomCss } from "./(content)/_custom-css";
|
||||
import { BoardReadyProvider } from "./(content)/_ready-context";
|
||||
import { BoardMantineProvider } from "./(content)/_theme";
|
||||
import { BoardSwitcherLogo } from "./_board-switcher-logo";
|
||||
|
||||
const logger = createLogger({ module: "createBoardLayout" });
|
||||
|
||||
@@ -33,12 +34,14 @@ interface CreateBoardLayoutProps<TParams extends Params> {
|
||||
headerActions: JSX.Element;
|
||||
getInitialBoardAsync: (params: TParams) => Promise<Board>;
|
||||
withTour?: boolean;
|
||||
mobileProfileInActions?: boolean;
|
||||
}
|
||||
|
||||
export const createBoardLayout = <TParams extends Params>({
|
||||
headerActions,
|
||||
getInitialBoardAsync: getInitialBoard,
|
||||
withTour = false,
|
||||
mobileProfileInActions = false,
|
||||
}: CreateBoardLayoutProps<TParams>) => {
|
||||
const Layout = async ({
|
||||
params,
|
||||
@@ -65,23 +68,36 @@ export const createBoardLayout = <TParams extends Params>({
|
||||
throw error;
|
||||
});
|
||||
const [colorScheme, requestHeaders] = await Promise.all([getCurrentColorSchemeAsync(), headers()]);
|
||||
const initialIsMobile = userAgent(new Headers(requestHeaders)).device.type === "mobile";
|
||||
const deviceType = userAgent(new Headers(requestHeaders)).device.type;
|
||||
const initialDeviceClass: MobileBoardDeviceClass =
|
||||
deviceType === "mobile" ? "phone" : deviceType === "tablet" ? "tablet" : "desktop";
|
||||
|
||||
return (
|
||||
<MobileBoardViewportProvider initialIsMobile={initialIsMobile}>
|
||||
<MobileBoardViewportProvider initialDeviceClass={initialDeviceClass}>
|
||||
<BoardProvider initialBoard={initialBoard}>
|
||||
<BoardReadyProvider>
|
||||
<EditModeProvider>
|
||||
<BoardMantineProvider defaultColorScheme={colorScheme}>
|
||||
<CustomCss />
|
||||
<BoardTourWrapper hasSession={withTour && !!session}>
|
||||
<ClientShell hasNavigation={false}>
|
||||
<ClientShell hasNavigation={false} withSafeArea>
|
||||
<MainHeader
|
||||
logo={<BoardLogoWithTitle size="md" hideTitleOnMobile />}
|
||||
logo={<BoardSwitcherLogo />}
|
||||
logoHref={null}
|
||||
actions={headerActions}
|
||||
hasNavigation={false}
|
||||
withSafeArea
|
||||
hideUserOnMobileBoard={mobileProfileInActions}
|
||||
/>
|
||||
<AppShellMain>{children}</AppShellMain>
|
||||
<AppShellMain
|
||||
style={{
|
||||
paddingRight: "calc(var(--mantine-spacing-md) + env(safe-area-inset-right))",
|
||||
paddingBottom: "calc(var(--mantine-spacing-md) + env(safe-area-inset-bottom))",
|
||||
paddingLeft: "calc(var(--mantine-spacing-md) + env(safe-area-inset-left))",
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</AppShellMain>
|
||||
</ClientShell>
|
||||
</BoardTourWrapper>
|
||||
</BoardMantineProvider>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { PropsWithChildren } from "react";
|
||||
import type { Viewport } from "next";
|
||||
|
||||
export const viewport: Viewport = {
|
||||
viewportFit: "cover",
|
||||
};
|
||||
|
||||
export default function BoardsLayout({ children }: PropsWithChildren) {
|
||||
return children;
|
||||
}
|
||||
Reference in new issue
Block a user