1+ 'use client' ;
2+ import { useState } from "react" ;
3+ import Link from "next/link" ;
4+
5+ // Define the type for an item
6+ type Item = {
7+ id : number ;
8+ name : string ;
9+ description : string ;
10+ lastSeenPlace : string ;
11+ contactInfo : string ;
12+ status : "lost" | "found" ;
13+ } ;
14+
15+ export default function LostFound ( ) {
16+ const [ status , setStatus ] = useState < "lost" | "found" > ( "lost" ) ;
17+ const [ items , setItems ] = useState < Item [ ] > ( [
18+ {
19+ id : 1 ,
20+ name : "Watch" ,
21+ description : "Lorem ipsum dolor sit amet, consectetur adipiscing elit." ,
22+ lastSeenPlace : "College Ground" ,
23+ contactInfo : "contact@example.com" ,
24+ status : "lost" ,
25+ } ,
26+ {
27+ id : 2 ,
28+ name : "Water Bottle" ,
29+ description : "Lorem ipsum dolor sit amet, consectetur adipiscing elit." ,
30+ lastSeenPlace : "Library" ,
31+ contactInfo : "contact@example.com" ,
32+ status : "found" ,
33+ } ,
34+ ] ) ;
35+
36+ // Toggle item status between "lost" and "found"
37+ const toggleItemStatus = ( id : number ) => {
38+ setItems ( ( prevItems ) =>
39+ prevItems . map ( ( item ) =>
40+ item . id === id
41+ ? { ...item , status : item . status === "lost" ? "found" : "lost" }
42+ : item
43+ )
44+ ) ;
45+ } ;
46+
47+ // Filter items based on the selected status
48+ const filteredItems = items . filter ( ( item ) => item . status === status ) ;
49+
50+ return (
51+ < div className = "p-4 max-w-md mx-auto relative" >
52+ < h1 className = "text-2xl font-bold mb-4" > Lost And Found</ h1 >
53+
54+ { /* Toggle Buttons */ }
55+ < div className = "flex mb-4" >
56+ < button
57+ className = { `flex-1 py-2 text-center ${
58+ status === "lost" ? "bg-gray-800 text-white" : "bg-gray-200"
59+ } `}
60+ onClick = { ( ) => setStatus ( "lost" ) }
61+ >
62+ Lost
63+ </ button >
64+ < button
65+ className = { `flex-1 py-2 text-center ${
66+ status === "found" ? "bg-gray-800 text-white" : "bg-gray-200"
67+ } `}
68+ onClick = { ( ) => setStatus ( "found" ) }
69+ >
70+ Found
71+ </ button >
72+ </ div >
73+
74+ { /* List of Items */ }
75+ { filteredItems . map ( ( item ) => (
76+ < div key = { item . id } className = "mb-4 border p-4 rounded-lg shadow-md" >
77+ < div className = "flex flex-col items-center" >
78+ < div className = "w-20 h-20 bg-gray-300 mb-2" > </ div >
79+ < h2 className = "text-lg font-semibold" > { item . name } </ h2 >
80+ < p className = "text-sm font-medium text-gray-600" >
81+ Last Seen Place: { item . lastSeenPlace }
82+ </ p >
83+ < p className = "text-sm text-gray-500 mt-1" > { item . description } </ p >
84+ < p className = "text-sm text-gray-500 mt-1" >
85+ Contact: { item . contactInfo }
86+ </ p >
87+ < div className = "flex gap-2 mt-3" >
88+ < button className = "text-blue-600" > Report</ button >
89+ < button className = "border px-3 py-1 rounded" > Edit</ button >
90+ < button
91+ className = "border px-3 py-1 rounded bg-green-600 text-white"
92+ onClick = { ( ) => toggleItemStatus ( item . id ) }
93+ >
94+ { item . status === "lost" ? "Mark as Found" : "Mark as Lost" }
95+ </ button >
96+ </ div >
97+ </ div >
98+ </ div >
99+ ) ) }
100+
101+ { /* Floating "+" Button */ }
102+ < Link href = "/lost-found/add" >
103+ < button className = "fixed bottom-6 right-6 bg-blue-600 text-white w-12 h-12 rounded-full flex items-center justify-center shadow-lg hover:bg-blue-700 transition-colors" >
104+ +
105+ </ button >
106+ </ Link >
107+ </ div >
108+ ) ;
109+ }
0 commit comments