mirror of
https://github.com/umami-software/umami.git
synced 2026-02-15 18:15:35 +01:00
Move website selector into top navigation
This commit is contained in:
parent
400a35d7af
commit
dd2d6bca45
4 changed files with 71 additions and 64 deletions
|
|
@ -4,8 +4,8 @@ import Script from 'next/script';
|
|||
import { useEffect } from 'react';
|
||||
import { MobileNav } from '@/app/(main)/MobileNav';
|
||||
import { SideNav } from '@/app/(main)/SideNav';
|
||||
import { TopNav } from '@/app/(main)/TopNav';
|
||||
import { useConfig, useLoginQuery, useNavigation } from '@/components/hooks';
|
||||
import { TeamsButton } from '@/components/input/TeamsButton';
|
||||
import { LAST_TEAM_CONFIG } from '@/lib/constants';
|
||||
import { removeItem, setItem } from '@/lib/storage';
|
||||
import { UpdateNotice } from './UpdateNotice';
|
||||
|
|
@ -51,18 +51,7 @@ export function App({ children }) {
|
|||
<SideNav />
|
||||
</Column>
|
||||
<Column overflowX="hidden" position="relative">
|
||||
<Row
|
||||
position="sticky"
|
||||
top="0"
|
||||
alignItems="center"
|
||||
justifyContent="space-between"
|
||||
paddingY="2"
|
||||
zIndex={100}
|
||||
>
|
||||
<Row backgroundColor="surface-raised">
|
||||
<TeamsButton />
|
||||
</Row>
|
||||
</Row>
|
||||
<TopNav />
|
||||
<Column alignItems="center">{children}</Column>
|
||||
</Column>
|
||||
<UpdateNotice user={user} config={config} />
|
||||
|
|
|
|||
|
|
@ -1,30 +1,47 @@
|
|||
import { Row, ThemeButton } from '@umami/react-zen';
|
||||
import { LanguageButton } from '@/components/input/LanguageButton';
|
||||
import { ProfileButton } from '@/components/input/ProfileButton';
|
||||
'use client';
|
||||
import { Icon, Row } from '@umami/react-zen';
|
||||
import { useNavigation } from '@/components/hooks';
|
||||
import { Slash } from '@/components/icons';
|
||||
import { TeamsButton } from '@/components/input/TeamsButton';
|
||||
import { WebsiteSelect } from '@/components/input/WebsiteSelect';
|
||||
|
||||
export function TopNav() {
|
||||
const { websiteId, teamId, router, renderUrl } = useNavigation();
|
||||
|
||||
const handleWebsiteChange = (value: string) => {
|
||||
router.push(renderUrl(`/websites/${value}`));
|
||||
};
|
||||
|
||||
return (
|
||||
<Row
|
||||
position="absolute"
|
||||
position="sticky"
|
||||
top="0"
|
||||
alignItems="center"
|
||||
justifyContent="flex-end"
|
||||
justifyContent="flex-start"
|
||||
paddingY="2"
|
||||
paddingX="3"
|
||||
paddingRight="5"
|
||||
width="100%"
|
||||
style={{ position: 'sticky', top: 0 }}
|
||||
zIndex={1}
|
||||
zIndex={100}
|
||||
>
|
||||
<Row
|
||||
alignItems="center"
|
||||
justifyContent="flex-end"
|
||||
backgroundColor="surface-raised"
|
||||
borderRadius
|
||||
>
|
||||
<ThemeButton />
|
||||
<LanguageButton />
|
||||
<ProfileButton />
|
||||
<Row alignItems="center" backgroundColor="surface-raised" borderRadius>
|
||||
<TeamsButton />
|
||||
{websiteId && (
|
||||
<>
|
||||
<Icon size="sm" color="muted" style={{ opacity: 0.7, margin: '0 6px' }}>
|
||||
<Slash />
|
||||
</Icon>
|
||||
<WebsiteSelect
|
||||
websiteId={websiteId}
|
||||
teamId={teamId}
|
||||
onChange={handleWebsiteChange}
|
||||
buttonProps={{
|
||||
variant: 'quiet',
|
||||
style: { minHeight: 40, minWidth: 200, maxWidth: 200 },
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Row>
|
||||
</Row>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,19 +1,8 @@
|
|||
import {
|
||||
Box,
|
||||
Column,
|
||||
Focusable,
|
||||
Label,
|
||||
Row,
|
||||
Text,
|
||||
Tooltip,
|
||||
TooltipTrigger,
|
||||
} from '@umami/react-zen';
|
||||
import { Column, Focusable, Row, Text, Tooltip, TooltipTrigger } from '@umami/react-zen';
|
||||
import Link from 'next/link';
|
||||
import { IconLabel } from '@/components/common/IconLabel';
|
||||
import { NavMenu } from '@/components/common/NavMenu';
|
||||
import { useMessages, useNavigation, useWebsiteNavItems } from '@/components/hooks';
|
||||
import { ArrowLeft } from '@/components/icons';
|
||||
import { WebsiteSelect } from '@/components/input/WebsiteSelect';
|
||||
|
||||
export function WebsiteNav({
|
||||
websiteId,
|
||||
|
|
@ -25,16 +14,12 @@ export function WebsiteNav({
|
|||
onItemClick?: () => void;
|
||||
}) {
|
||||
const { t, labels } = useMessages();
|
||||
const { teamId, router, renderUrl } = useNavigation();
|
||||
const { renderUrl } = useNavigation();
|
||||
const { items, selectedKey } = useWebsiteNavItems(websiteId);
|
||||
|
||||
const handleChange = (value: string) => {
|
||||
router.push(renderUrl(`/websites/${value}`));
|
||||
};
|
||||
|
||||
return (
|
||||
<Column gap="2">
|
||||
<Link href={renderUrl('/websites', false)} role="button">
|
||||
<Link href={renderUrl('/websites', false)} role="button" onClick={onItemClick}>
|
||||
<TooltipTrigger isDisabled={!isCollapsed} delay={0}>
|
||||
<Focusable>
|
||||
<Row
|
||||
|
|
@ -49,15 +34,6 @@ export function WebsiteNav({
|
|||
<Tooltip placement="right">{t(labels.back)}</Tooltip>
|
||||
</TooltipTrigger>
|
||||
</Link>
|
||||
<Box marginBottom="2">
|
||||
<WebsiteSelect
|
||||
websiteId={websiteId}
|
||||
teamId={teamId}
|
||||
onChange={handleChange}
|
||||
buttonProps={{ style: { outline: 'none' } }}
|
||||
isCollapsed={isCollapsed}
|
||||
/>
|
||||
</Box>
|
||||
{items.map(({ label: sectionLabel, items: sectionItems }, index) => (
|
||||
<Column key={`${sectionLabel}${index}`} gap="1" marginBottom="1">
|
||||
{!isCollapsed && (
|
||||
|
|
@ -68,7 +44,7 @@ export function WebsiteNav({
|
|||
{sectionItems.map(({ id, path, label, icon }) => {
|
||||
const isSelected = selectedKey === id;
|
||||
return (
|
||||
<Link key={id} href={path} role="button">
|
||||
<Link key={id} href={path} role="button" onClick={onItemClick}>
|
||||
<TooltipTrigger isDisabled={!isCollapsed} delay={0}>
|
||||
<Focusable>
|
||||
<Row
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue