diff --git a/apps/web/src/pages/catalog-page.tsx b/apps/web/src/pages/catalog-page.tsx index abb211b..aff925c 100644 --- a/apps/web/src/pages/catalog-page.tsx +++ b/apps/web/src/pages/catalog-page.tsx @@ -1,80 +1,105 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useQuery } from '@tanstack/react-query'; -import { Link } from 'react-router-dom'; +import { Link, useSearchParams } from 'react-router-dom'; +import { ArrowLeft, Shield, AlertCircle } from 'lucide-react'; import type { RiskLevel } from '@zeavis/shared'; import { Button } from '@/components/ui/button'; -import { Card } from '@/components/ui/card'; -import { DiseaseCard } from '@/components/disease-card'; +import { Card, CardContent } from '@/components/ui/card'; +import { RiskBadge } from '@/components/risk-badge'; import { apiClient } from '@/lib/api-client'; export function CatalogPage() { + const [searchParams, setSearchParams] = useSearchParams(); + const initialRisk = searchParams.get('risk') as RiskLevel | null; + const [searchQuery, setSearchQuery] = useState(''); - const [riskFilter, setRiskFilter] = useState('all'); + const [riskFilter, setRiskFilter] = useState(initialRisk ?? 'all'); + + // Sync URL params with state + useEffect(() => { + if (initialRisk && initialRisk !== riskFilter) { + setRiskFilter(initialRisk); + } + }, [initialRisk]); const { data: diseases, isLoading, error } = useQuery({ queryKey: ['diseases'], queryFn: () => apiClient.getDiseases(), }); - const filteredDiseases = (diseases || []).filter((disease) => { - const matchesSearch = - disease.commonName.toLowerCase().includes(searchQuery.toLowerCase()) || - disease.label.toLowerCase().includes(searchQuery.toLowerCase()) || - disease.summary.toLowerCase().includes(searchQuery.toLowerCase()); + const filteredDiseases = (diseases || []) + .sort((a, b) => a.displayOrder - b.displayOrder) + .filter((disease) => { + const matchesSearch = + disease.commonName.toLowerCase().includes(searchQuery.toLowerCase()) || + disease.label.toLowerCase().includes(searchQuery.toLowerCase()) || + disease.summary.toLowerCase().includes(searchQuery.toLowerCase()) || + disease.symptoms.some((s) => s.toLowerCase().includes(searchQuery.toLowerCase())); - const matchesRisk = riskFilter === 'all' || disease.riskLevel === riskFilter; + const matchesRisk = riskFilter === 'all' || disease.riskLevel === riskFilter; - return matchesSearch && matchesRisk; - }); + return matchesSearch && matchesRisk; + }); return ( -
+
-
-

Katalog Penyakit

-

- Pelajari tentang penyakit daun jagung dan cara penanganannya -

+
+ +
+

Edukasi Penyakit

+

Katalog Penyakit

+
-
-
-
-
- + {/* Filters */} +
+
+ +
+ setSearchQuery(e.target.value)} - className="w-full rounded-md border border-border bg-background px-3 py-2 text-sm" + className="w-full rounded-md border border-border bg-background pl-10 pr-3 py-2 text-sm" />
-
- - -
+
+
+ +
@@ -97,9 +122,59 @@ export function CatalogPage() { )} {!isLoading && !error && filteredDiseases.length > 0 && ( -
+
{filteredDiseases.map((disease) => ( - + + + +
+
+

+ {disease.commonName} +

+

+ {disease.label} +

+
+ +
+ +

+ {disease.summary} +

+ + {disease.symptoms.length > 0 && ( +
+

+ Gejala: +

+
    + {disease.symptoms.slice(0, 2).map((symptom, index) => ( +
  • + + {symptom} +
  • + ))} +
+
+ )} + +
+
+ + Lihat detail → + +
+ + + ))}
)} diff --git a/apps/web/src/pages/dashboard-page.tsx b/apps/web/src/pages/dashboard-page.tsx index 432fd27..88d8913 100644 --- a/apps/web/src/pages/dashboard-page.tsx +++ b/apps/web/src/pages/dashboard-page.tsx @@ -30,6 +30,7 @@ export function DashboardPage() { name: d.commonName, sci: d.label, color: d.accentColor, + slug: d.slug, })), [diseases] ); @@ -156,26 +157,12 @@ export function DashboardPage() { perkembangan dan hasil deteksi penyakit daun jagung

- - - - Total Penyakit - - - -
- {summary.diseaseCount} -
- - Lihat daftar - -
-
+ {/* Total Diagnoses — the actual count from diagnoses table */} - Total Diagnosis + Total Diagnosa @@ -188,6 +175,7 @@ export function DashboardPage() { + {/* Menunggu Review */} @@ -204,18 +192,36 @@ export function DashboardPage() { + {/* Diagnosa Gagal */} - Risiko Tinggi + Gagal + + + +
+ — +
+ + Lihat daftar + +
+
+ + {/* Risiko Tinggi — catalog count, link to catalog filtered */} + + + + Kategori Risiko Tinggi
{summary.riskDistribution.high}
- - Lihat daftar + + Lihat pustaka
@@ -262,7 +268,7 @@ export function DashboardPage() {
- {/* Diseases quick access - now API-driven */} + {/* Diseases quick access - now clickable, link to catalog/:slug */}
@@ -288,27 +294,28 @@ export function DashboardPage() { ) : (
{diseasesQuick.map((d) => ( - - -
-
-
-
- {d.name} -
-
- {d.sci} + + + +
+
+
+
+ {d.name} +
+
+ {d.sci} +
-
-
-
+ + + ))}
)}