take shorturl data

This commit is contained in:
2025-04-07 23:20:48 +08:00
parent ed327ad3f0
commit d0e83f697b
6 changed files with 153 additions and 3 deletions

View File

@@ -5,6 +5,8 @@ import { getSupabaseClient } from '../utils/supabase';
import { AuthChangeEvent } from '@supabase/supabase-js';
import { Loader2, ExternalLink, Search } from 'lucide-react';
import { TeamSelector } from '@/app/components/ui/TeamSelector';
import { useRouter } from 'next/navigation';
import { useShortUrlStore, ShortUrlData } from '@/app/utils/store';
// Define attribute type to avoid using 'any'
interface LinkAttributes {
@@ -108,7 +110,37 @@ export default function LinksPage() {
const [totalLinks, setTotalLinks] = useState(0);
const [totalPages, setTotalPages] = useState(0);
const [searchDebounce, setSearchDebounce] = useState<NodeJS.Timeout | null>(null);
const router = useRouter();
// 使用 Zustand store
const { setSelectedShortUrl } = useShortUrlStore();
// 处理链接记录点击
const handleLinkClick = (shortUrl: string, link: ShortLink, metadata: any) => {
// 编码 shortUrl 以确保 URL 安全
const encodedShortUrl = encodeURIComponent(shortUrl);
// 创建完整的 ShortUrlData 对象
const shortUrlData: ShortUrlData = {
id: link.id,
slug: metadata.slug,
originalUrl: metadata.originalUrl,
title: metadata.title,
shortUrl: shortUrl,
teams: metadata.teamNames,
tags: metadata.tagNames,
projects: metadata.projectNames,
createdAt: metadata.createdAt,
domain: metadata.domain
};
// 使用 Zustand store 保存数据
setSelectedShortUrl(shortUrlData);
// 导航到 analytics 页面并带上参数
router.push(`/analytics?shorturl=${encodedShortUrl}`);
};
// Extract link metadata from attributes
const getLinkMetadata = (link: ShortLink) => {
try {
@@ -391,7 +423,7 @@ export default function LinksPage() {
const shortUrl = `https://${metadata.domain}/${metadata.slug}`;
return (
<tr key={link.id} className="hover:bg-gray-50">
<tr key={link.id} className="hover:bg-gray-50 cursor-pointer" onClick={() => handleLinkClick(shortUrl, link, metadata)}>
<td className="px-6 py-4">
<div className="flex flex-col space-y-1">
<span className="font-medium text-gray-900">{metadata.title}</span>