From 8c5273790a2c2da8128828da62e6b360152a61ca Mon Sep 17 00:00:00 2001 From: songtianlun Date: Thu, 3 Jul 2025 00:49:29 +0800 Subject: [PATCH] better layout --- src/app/zh-CN/page.tsx | 30 +++++++++++++++++++++------- src/components/ComparisonForm.tsx | 2 +- src/components/ComparisonHistory.tsx | 27 ++++++++++++++++++++----- src/utils/historyStorage.ts | 19 ++++++++++++++++++ 4 files changed, 65 insertions(+), 13 deletions(-) diff --git a/src/app/zh-CN/page.tsx b/src/app/zh-CN/page.tsx index f20ec51..2a0a488 100644 --- a/src/app/zh-CN/page.tsx +++ b/src/app/zh-CN/page.tsx @@ -5,7 +5,7 @@ import React from 'react'; import { HistoryItem } from '@/components/ComparisonHistory'; import AdBanner from '@/components/AdBanner'; import LanguageSwitcher from '@/components/LanguageSwitcher'; -import { saveToHistory } from '@/utils/historyStorage'; +import { saveToHistory, deleteHistoryItem } from '@/utils/historyStorage'; export default function HomePage() { const [comparisonResults, setComparisonResults] = useState(null); @@ -300,7 +300,7 @@ function ComparisonFormZH({ onSubmit, isLoading, selectedExample, onExampleUsed + {(item.description1 || item.description2) && (
diff --git a/src/components/ComparisonForm.tsx b/src/components/ComparisonForm.tsx index 8c13e18..92e9944 100644 --- a/src/components/ComparisonForm.tsx +++ b/src/components/ComparisonForm.tsx @@ -176,7 +176,7 @@ export default function ComparisonForm({ onSubmit, isLoading, selectedExample, o +
{(item.description1 || item.description2) && (
diff --git a/src/utils/historyStorage.ts b/src/utils/historyStorage.ts index 2846057..92d3422 100644 --- a/src/utils/historyStorage.ts +++ b/src/utils/historyStorage.ts @@ -51,4 +51,23 @@ export const getHistory = (): HistoryItem[] => { console.error('Error loading history:', error); return []; } +}; + +export const deleteHistoryItem = (id: string) => { + try { + const existing = localStorage.getItem('comparison-history'); + if (existing) { + const history: HistoryItem[] = JSON.parse(existing); + const updatedHistory = history.filter(item => item.id !== id); + localStorage.setItem('comparison-history', JSON.stringify(updatedHistory)); + + // Dispatch custom event for same-page updates + window.dispatchEvent(new Event('comparison-history-updated')); + return true; + } + return false; + } catch (error) { + console.error('Error deleting history item:', error); + return false; + } }; \ No newline at end of file