.
This commit is contained in:
parent
eb02b5832b
commit
7a12e6c09a
2 changed files with 10 additions and 21 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import { useState, useCallback, useEffect } from 'react';
|
import { useState, useCallback, useEffect } from 'react';
|
||||||
import type { AuthUser } from '../../hooks/useAuth';
|
import type { AuthUser } from '../../hooks/useAuth';
|
||||||
import { shortenUrl } from '../../lib/api';
|
import { shortenUrl } from '../../lib/api';
|
||||||
|
import { copyToClipboard } from '../../lib/clipboard';
|
||||||
import { DownloadIcon } from './icons/DownloadIcon';
|
import { DownloadIcon } from './icons/DownloadIcon';
|
||||||
import { BookmarkIcon } from './icons/BookmarkIcon';
|
import { BookmarkIcon } from './icons/BookmarkIcon';
|
||||||
import { LogoIcon } from './icons/LogoIcon';
|
import { LogoIcon } from './icons/LogoIcon';
|
||||||
|
|
@ -63,42 +64,29 @@ export default function Header({
|
||||||
if (!isMobile) setMenuOpen(false);
|
if (!isMobile) setMenuOpen(false);
|
||||||
}, [isMobile]);
|
}, [isMobile]);
|
||||||
|
|
||||||
const copyToClipboard = useCallback((text: string) => {
|
const doCopy = useCallback((text: string) => {
|
||||||
const onSuccess = () => {
|
copyToClipboard(text, () => {
|
||||||
setCopied(true);
|
setCopied(true);
|
||||||
setTimeout(() => setCopied(false), 2000);
|
setTimeout(() => setCopied(false), 2000);
|
||||||
};
|
});
|
||||||
if (navigator.clipboard?.writeText) {
|
|
||||||
navigator.clipboard.writeText(text).then(onSuccess);
|
|
||||||
} else {
|
|
||||||
const ta = document.createElement('textarea');
|
|
||||||
ta.value = text;
|
|
||||||
ta.style.position = 'fixed';
|
|
||||||
ta.style.opacity = '0';
|
|
||||||
document.body.appendChild(ta);
|
|
||||||
ta.select();
|
|
||||||
document.execCommand('copy');
|
|
||||||
document.body.removeChild(ta);
|
|
||||||
onSuccess();
|
|
||||||
}
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleShare = useCallback(async () => {
|
const handleShare = useCallback(async () => {
|
||||||
const params = window.location.search.replace(/^\?/, '');
|
const params = window.location.search.replace(/^\?/, '');
|
||||||
if (!params) {
|
if (!params) {
|
||||||
copyToClipboard(window.location.href);
|
doCopy(window.location.href);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSharing(true);
|
setSharing(true);
|
||||||
try {
|
try {
|
||||||
const shortUrl = await shortenUrl(params);
|
const shortUrl = await shortenUrl(params);
|
||||||
copyToClipboard(shortUrl);
|
doCopy(shortUrl);
|
||||||
} catch {
|
} catch {
|
||||||
copyToClipboard(window.location.href);
|
doCopy(window.location.href);
|
||||||
} finally {
|
} finally {
|
||||||
setSharing(false);
|
setSharing(false);
|
||||||
}
|
}
|
||||||
}, [copyToClipboard]);
|
}, [doCopy]);
|
||||||
|
|
||||||
const tabClass = (page: Page) =>
|
const tabClass = (page: Page) =>
|
||||||
`px-3 py-1.5 rounded text-sm font-medium transition-colors ${
|
`px-3 py-1.5 rounded text-sm font-medium transition-colors ${
|
||||||
|
|
|
||||||
|
|
@ -76,12 +76,13 @@ export function useMapData({
|
||||||
);
|
);
|
||||||
|
|
||||||
// Build the travel param string from entries with destinations
|
// Build the travel param string from entries with destinations
|
||||||
// Format: mode:slug|mode:slug or mode:slug:min:max|mode:slug
|
// Format: mode:slug|mode:slug:best or mode:slug:min:max|mode:slug:best:min:max
|
||||||
const travelParam = useMemo((): string => {
|
const travelParam = useMemo((): string => {
|
||||||
const segments: string[] = [];
|
const segments: string[] = [];
|
||||||
for (const entry of travelTimeEntries) {
|
for (const entry of travelTimeEntries) {
|
||||||
if (!entry.slug) continue;
|
if (!entry.slug) continue;
|
||||||
let seg = `${entry.mode}:${entry.slug}`;
|
let seg = `${entry.mode}:${entry.slug}`;
|
||||||
|
if (entry.useBest) seg += ':best';
|
||||||
if (entry.timeRange) {
|
if (entry.timeRange) {
|
||||||
seg += `:${entry.timeRange[0]}:${entry.timeRange[1]}`;
|
seg += `:${entry.timeRange[0]}:${entry.timeRange[1]}`;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue