1- import { FileText } from ' lucide-react' ;
1+ import { FileText } from " lucide-react" ;
22import Project from "@/types/ProjectType" ;
33import ProjectEditPopover from "@/components/project-card/project-card-components/ProjectEditPopover" ;
44import { useState , useRef , useEffect } from "react" ;
55
66export default function ProjectCard ( { project } : { project : Project } ) {
7- const [ isEditing , setIsEditing ] = useState ( false ) ;
8- const [ editedTitle , setEditedTitle ] = useState ( project . title ) ;
9- const inputRef = useRef < HTMLInputElement > ( null ) ;
7+ const [ isEditing , setIsEditing ] = useState ( false ) ;
8+ const [ editedTitle , setEditedTitle ] = useState ( project . title ) ;
9+ const inputRef = useRef < HTMLInputElement > ( null ) ;
1010
11- useEffect ( ( ) => {
12- if ( ! isEditing ) return ;
11+ useEffect ( ( ) => {
12+ if ( ! isEditing ) return ;
1313
14- const handleClickOutside = ( event : MouseEvent ) => {
15- if ( inputRef . current && ! inputRef . current . contains ( event . target as Node ) ) {
16- handleSave ( ) ;
17- }
18- } ;
14+ const handleClickOutside = ( event : MouseEvent ) => {
15+ if (
16+ inputRef . current &&
17+ ! inputRef . current . contains ( event . target as Node )
18+ ) {
19+ handleSave ( ) ;
20+ }
21+ } ;
1922
20- document . addEventListener ( ' mousedown' , handleClickOutside ) ;
21- return ( ) => document . removeEventListener ( ' mousedown' , handleClickOutside ) ;
22- } , [ isEditing , editedTitle ] ) ;
23+ document . addEventListener ( " mousedown" , handleClickOutside ) ;
24+ return ( ) => document . removeEventListener ( " mousedown" , handleClickOutside ) ;
25+ } , [ isEditing , editedTitle ] ) ;
2326
24- useEffect ( ( ) => {
25- if ( isEditing && inputRef . current ) {
26- inputRef . current . focus ( ) ;
27- inputRef . current . select ( ) ;
28- }
29- } , [ isEditing ] ) ;
27+ useEffect ( ( ) => {
28+ if ( isEditing && inputRef . current ) {
29+ inputRef . current . focus ( ) ;
30+ inputRef . current . select ( ) ;
31+ }
32+ } , [ isEditing ] ) ;
3033
31- const handleRename = ( ) => {
32- setIsEditing ( true ) ;
33- setEditedTitle ( project . title ) ;
34- } ;
34+ const handleRename = ( ) => {
35+ setIsEditing ( true ) ;
36+ setEditedTitle ( project . title ) ;
37+ } ;
3538
36- const handleSave = ( ) => {
37- project . title = editedTitle . trim ( ) || project . title ;
38- setIsEditing ( false ) ;
39- } ;
39+ const handleSave = ( ) => {
40+ project . title = editedTitle . trim ( ) || project . title ;
41+ setIsEditing ( false ) ;
42+ } ;
4043
41- const handleKeyDown = ( e : React . KeyboardEvent ) => {
42- if ( e . key === ' Enter' ) {
43- handleSave ( ) ;
44- } else if ( e . key === ' Escape' ) {
45- setEditedTitle ( project . title ) ;
46- setIsEditing ( false ) ;
47- }
48- } ;
44+ const handleKeyDown = ( e : React . KeyboardEvent ) => {
45+ if ( e . key === " Enter" ) {
46+ handleSave ( ) ;
47+ } else if ( e . key === " Escape" ) {
48+ setEditedTitle ( project . title ) ;
49+ setIsEditing ( false ) ;
50+ }
51+ } ;
4952
50- return (
51- < div className = "group relative bg-white rounded-lg border-2 border-gray-200 hover:border-gray-300 transition-all duration-200 cursor-pointer hover:shadow-md" >
52- < div className = "aspect-video p-4 flex items-center justify-center bg-gray-50 rounded-t-lg" >
53- { /*theoretically the img of the white board*/ }
54- < div className = "w-full h-full bg-gray-100 rounded flex items-center justify-center" >
55- < FileText className = "w-8 h-8 text-gray-400" />
56- </ div >
57- </ div >
58- < div className = "flex flex-row p-4 justify-between" >
59- < div className = "flex-1 mr-2 w-3/4" >
60- < div className = "flex items-center space-x-2 mb-1" >
61- { isEditing ? (
62- < input
63- ref = { inputRef }
64- type = "text"
65- value = { editedTitle }
66- onChange = { ( e ) => setEditedTitle ( e . target . value ) }
67- onKeyDown = { handleKeyDown }
68- className = "font-medium text-gray-900 bg-transparent border border-blue-500 rounded px-1 py-0.5 outline-none focus:ring-1 focus:ring-blue-500 w-full"
69- onClick = { ( e ) => e . stopPropagation ( ) }
70- />
71- ) : (
72- < h3 className = "font-medium text-gray-900 truncate" > { project . title } </ h3 >
73- ) }
74- </ div >
75- < p className = "text-sm text-gray-500" > { project . lastEdited } </ p >
76- </ div >
77- < ProjectEditPopover onRename = { handleRename } />
78- </ div >
53+ return (
54+ < div className = "group relative bg-white rounded-lg border-2 border-gray-200 hover:border-gray-300 transition-all duration-200 cursor-pointer hover:shadow-md" >
55+ < div className = "aspect-video p-4 flex items-center justify-center bg-gray-50 rounded-t-lg" >
56+ { /*theoretically the img of the white board*/ }
57+ < div className = "w-full h-full bg-gray-100 rounded flex items-center justify-center" >
58+ < FileText className = "w-8 h-8 text-gray-400" />
59+ </ div >
60+ </ div >
61+ < div className = "flex flex-row p-4 justify-between" >
62+ < div className = "flex-1 mr-2 w-3/4" >
63+ < div className = "flex items-center space-x-2 mb-1" >
64+ { isEditing ? (
65+ < input
66+ ref = { inputRef }
67+ type = "text"
68+ value = { editedTitle }
69+ onChange = { ( e ) => setEditedTitle ( e . target . value ) }
70+ onKeyDown = { handleKeyDown }
71+ className = "font-medium text-gray-900 bg-transparent border border-blue-500 rounded px-1 py-0.5 outline-none focus:ring-1 focus:ring-blue-500 w-full"
72+ onClick = { ( e ) => e . stopPropagation ( ) }
73+ />
74+ ) : (
75+ < h3 className = "font-medium text-gray-900 truncate" >
76+ { project . title }
77+ </ h3 >
78+ ) }
79+ </ div >
80+ < p className = "text-sm text-gray-500" > { project . lastEdited } </ p >
7981 </ div >
80- ) ;
81- }
82+ < ProjectEditPopover onRename = { handleRename } />
83+ </ div >
84+ </ div >
85+ ) ;
86+ }
0 commit comments