Files
umami/src/components/input/ExportButton.tsx
T
Mike CaoandClaude Opus 4.6 50edb71687 Simplify i18n: remove old react-intl artifacts, rename formatMessage to t, replace FormattedMessage with t.rich().
- Rewrite messages.ts to plain string key maps (remove MessageDescriptor)
- Rewrite useMessages hook to expose t from useTranslations() directly
- Rename formatMessage → t across 193 consumer files
- Replace custom FormattedMessage component with next-intl t.rich()
- Update 52 language files to use rich text tags (<b>, <a>)
- Remove all direct imports from @/components/messages in favor of useMessages()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 11:19:04 -08:00

65 lines
1.7 KiB
TypeScript

import { Icon, LoadingButton, Tooltip, TooltipTrigger } from '@umami/react-zen';
import { useSearchParams } from 'next/navigation';
import { useState } from 'react';
import { useApi, useMessages } from '@/components/hooks';
import { useDateParameters } from '@/components/hooks/useDateParameters';
import { useFilterParameters } from '@/components/hooks/useFilterParameters';
import { Download } from '@/components/icons';
export function ExportButton({ websiteId }: { websiteId: string }) {
const { t, labels } = useMessages();
const [isLoading, setIsLoading] = useState(false);
const date = useDateParameters();
const filters = useFilterParameters();
const searchParams = useSearchParams();
const { get } = useApi();
const handleClick = async () => {
setIsLoading(true);
const { zip } = await get(`/websites/${websiteId}/export`, {
...date,
...filters,
...searchParams,
format: 'json',
});
await loadZip(zip);
setIsLoading(false);
};
return (
<TooltipTrigger delay={0}>
<LoadingButton
variant="quiet"
showText={!isLoading}
isLoading={isLoading}
onClick={handleClick}
>
<Icon>
<Download />
</Icon>
</LoadingButton>
<Tooltip>{t(labels.download)}</Tooltip>
</TooltipTrigger>
);
}
async function loadZip(zip: string) {
const binary = atob(zip);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);
}
const blob = new Blob([bytes], { type: 'application/zip' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'download.zip';
a.click();
URL.revokeObjectURL(url);
}