fix some bug
This commit is contained in:
parent
eb9680395a
commit
98b486632d
@ -3,6 +3,8 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import ComparisonForm from '@/components/ComparisonForm';
|
import ComparisonForm from '@/components/ComparisonForm';
|
||||||
import ComparisonResults from '@/components/ComparisonResults';
|
import ComparisonResults from '@/components/ComparisonResults';
|
||||||
|
import ComparisonHistory, { HistoryItem } from '@/components/ComparisonHistory';
|
||||||
|
import { saveToHistory } from '@/utils/historyStorage';
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const [comparisonResults, setComparisonResults] = useState<string | null>(null);
|
const [comparisonResults, setComparisonResults] = useState<string | null>(null);
|
||||||
@ -10,6 +12,7 @@ export default function Home() {
|
|||||||
|
|
||||||
const handleComparison = async (item1: string, item2: string, description1: string, description2: string) => {
|
const handleComparison = async (item1: string, item2: string, description1: string, description2: string) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/compare', {
|
const response = await fetch('/api/compare', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -30,6 +33,9 @@ export default function Home() {
|
|||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setComparisonResults(data.comparison);
|
setComparisonResults(data.comparison);
|
||||||
|
|
||||||
|
// Save to history
|
||||||
|
saveToHistory(item1, item2, description1, description2, data.comparison);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
setComparisonResults('Error occurred while comparing items.');
|
setComparisonResults('Error occurred while comparing items.');
|
||||||
@ -37,6 +43,10 @@ export default function Home() {
|
|||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSelectHistory = (historyItem: HistoryItem) => {
|
||||||
|
setComparisonResults(historyItem.result);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 py-6 md:py-12">
|
<main className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 py-6 md:py-12">
|
||||||
@ -69,8 +79,12 @@ export default function Home() {
|
|||||||
<ComparisonForm onSubmit={handleComparison} isLoading={isLoading} />
|
<ComparisonForm onSubmit={handleComparison} isLoading={isLoading} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="mb-8">
|
||||||
|
<ComparisonHistory onSelectHistory={handleSelectHistory} />
|
||||||
|
</div>
|
||||||
|
|
||||||
{comparisonResults && (
|
{comparisonResults && (
|
||||||
<div className="bg-white rounded-xl shadow-lg p-8">
|
<div className="bg-white rounded-xl shadow-lg p-8 mt-8">
|
||||||
<ComparisonResults results={comparisonResults} />
|
<ComparisonResults results={comparisonResults} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
Loading…
Reference in New Issue
Block a user