add share page options enable filtering and enforce theme
This commit is contained in:
1 parent
5ccfb6d0a5
commit
9b099408c2
75 files changed
+450
-172
No files matched your search
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
import { useShareTokenQuery } from '@/components/hooks';
|
||||
import { ENTITY_TYPE } from '@/lib/constants';
|
||||
import type { WhiteLabel } from '@/lib/types';
|
||||
import type { ShareParameters, WhiteLabel } from '@/lib/types';
|
||||
import { Loading } from '@umami/react-zen';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { createContext, type ReactNode, useEffect } from 'react';
|
||||
@@ -15,7 +15,7 @@ export interface ShareData {
|
||||
boardId?: string;
|
||||
pixelId?: string;
|
||||
linkId?: string;
|
||||
parameters: any;
|
||||
parameters: ShareParameters;
|
||||
token: string;
|
||||
whiteLabel?: WhiteLabel;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useMessages, useNavigation, useShare } from '@/components/hooks';
|
||||
import { AlignEndHorizontal, Clock, Eye, PanelLeft, Sheet, Tag, User } from '@/components/icons';
|
||||
import { LanguageButton } from '@/components/input/LanguageButton';
|
||||
import { PreferencesButton } from '@/components/input/PreferencesButton';
|
||||
import { allowShareFilter, excludeShareFilterParam, getShareTheme } from '@/lib/share';
|
||||
import { Funnel, Gauge, Lightning, Magnet, Money, Network, Path, Target } from '@/components/svg';
|
||||
import { buildPath } from '@/lib/url';
|
||||
import {
|
||||
@@ -32,12 +33,19 @@ export function ShareNav({
|
||||
const { t, labels } = useMessages();
|
||||
const { pathname, query } = useNavigation();
|
||||
const { slug, parameters } = share;
|
||||
const allowFilter = allowShareFilter(parameters);
|
||||
const shareTheme = getShareTheme(parameters);
|
||||
|
||||
const renderPath = (path: string) =>
|
||||
buildPath(`/share/${slug}${path}`, {
|
||||
...query,
|
||||
...Object.fromEntries(
|
||||
Object.entries(query).filter(([key]) => {
|
||||
return allowFilter || !excludeShareFilterParam(key);
|
||||
}),
|
||||
),
|
||||
event: undefined,
|
||||
compare: undefined,
|
||||
theme: undefined,
|
||||
view: undefined,
|
||||
unit: undefined,
|
||||
excludeBounce: undefined,
|
||||
@@ -202,13 +210,13 @@ export function ShareNav({
|
||||
>
|
||||
{collapsed ? (
|
||||
<Column gap="2" alignItems="center">
|
||||
<ThemeButton />
|
||||
{!shareTheme && <ThemeButton />}
|
||||
<LanguageButton />
|
||||
<PreferencesButton />
|
||||
</Column>
|
||||
) : (
|
||||
<Row>
|
||||
<ThemeButton />
|
||||
{!shareTheme && <ThemeButton />}
|
||||
<LanguageButton />
|
||||
<PreferencesButton />
|
||||
</Row>
|
||||
|
||||
@@ -22,6 +22,7 @@ import { PageBody } from '@/components/common/PageBody';
|
||||
import { useShare } from '@/components/hooks';
|
||||
import { MobileMenuButton } from '@/components/input/MobileMenuButton';
|
||||
import { ENTITY_TYPE } from '@/lib/constants';
|
||||
import { getShareTheme } from '@/lib/share';
|
||||
import { Column, Grid, Row, useTheme } from '@umami/react-zen';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
@@ -68,20 +69,20 @@ export function SharePage() {
|
||||
setNavCollapsed(value);
|
||||
};
|
||||
const share = useShare();
|
||||
const { setTheme } = useTheme();
|
||||
const { initTheme } = useTheme();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const path = getSharePath(pathname);
|
||||
const { slug, websiteId, boardId, pixelId, linkId, parameters = {}, shareType } = share;
|
||||
const shareTheme = getShareTheme(parameters);
|
||||
|
||||
useEffect(() => {
|
||||
const url = new URL(window?.location?.href);
|
||||
const theme = url.searchParams.get('theme');
|
||||
initTheme(shareTheme, 'system');
|
||||
|
||||
if (theme === 'light' || theme === 'dark') {
|
||||
setTheme(theme);
|
||||
}
|
||||
}, [setTheme]);
|
||||
return () => {
|
||||
initTheme(undefined, 'system');
|
||||
};
|
||||
}, [shareTheme, initTheme]);
|
||||
|
||||
// Check if the requested path is allowed
|
||||
const pageKey = path || '';
|
||||
|
||||
Reference in new issue
Block a user