|
1 | | -import { CloseButton, GridItem, Heading, HStack, Text } from "@chakra-ui/react"; |
| 1 | +import { |
| 2 | + CloseButton, |
| 3 | + GridItem, |
| 4 | + Heading, |
| 5 | + HStack, |
| 6 | + IconButton, |
| 7 | + Text, |
| 8 | +} from "@chakra-ui/react"; |
2 | 9 | import { ReactNode } from "react"; |
3 | 10 | import { ProjectEntry } from "./project-list-db"; |
4 | 11 | import { timeAgo } from "./utils"; |
| 12 | +import { RiEditFill, RiHistoryFill } from "react-icons/ri"; |
5 | 13 |
|
6 | 14 | interface ProjectItemProps { |
7 | | - project: ProjectEntry; |
8 | | - loadProject: (projectId: string) => void; |
9 | | - deleteProject: (projectId: string) => void; |
| 15 | + project: ProjectEntry; |
| 16 | + showHistory: (projectId: string) => void; |
| 17 | + loadProject: (projectId: string) => void; |
| 18 | + deleteProject: (projectId: string) => void; |
| 19 | + renameProject: (projectId: string) => void; |
10 | 20 | } |
11 | 21 |
|
12 | 22 | interface ProjectItemBaseProps { |
@@ -37,38 +47,68 @@ const ProjectItemBase = ({ onClick, children }: ProjectItemBaseProps) => ( |
37 | 47 | </GridItem> |
38 | 48 | ); |
39 | 49 |
|
40 | | -export const ProjectItem = ({project, loadProject, deleteProject}: ProjectItemProps) => ( |
41 | | - <ProjectItemBase onClick={() => loadProject(project.id)}> |
42 | | - <HStack justifyContent="space-between" w="100%"> |
43 | | - <Heading as="h2" isTruncated> |
44 | | - {project.projectName} |
45 | | - </Heading> |
46 | | - </HStack> |
47 | | - <Text size="lg">{timeAgo(new Date(project.modifiedDate))}</Text> |
| 50 | +export const ProjectItem = ({ |
| 51 | + project, |
| 52 | + loadProject, |
| 53 | + deleteProject, |
| 54 | + renameProject, |
| 55 | + showHistory, |
| 56 | +}: ProjectItemProps) => ( |
| 57 | + <ProjectItemBase onClick={() => loadProject(project.id)}> |
| 58 | + <HStack justifyContent="space-between" w="100%"> |
| 59 | + <Heading as="h2" isTruncated> |
| 60 | + {project.projectName} |
| 61 | + </Heading> |
| 62 | + </HStack> |
| 63 | + <Text size="lg">{timeAgo(new Date(project.modifiedDate))}</Text> |
48 | 64 |
|
49 | | - <CloseButton |
50 | | - position="absolute" |
51 | | - right={4} |
52 | | - top={4} |
53 | | - onClick={(e) => { |
54 | | - deleteProject(project.id); |
55 | | - e.stopPropagation(); |
56 | | - e.preventDefault(); |
57 | | - }} |
58 | | - /> |
59 | | - </ProjectItemBase> |
60 | | -) |
| 65 | + <IconButton |
| 66 | + aria-label="Project history" |
| 67 | + icon={<RiHistoryFill />} |
| 68 | + mr="2" |
| 69 | + onClick={(e) => { |
| 70 | + showHistory(project.id); |
| 71 | + e.stopPropagation(); |
| 72 | + e.preventDefault(); |
| 73 | + }} |
| 74 | + size="lg" |
| 75 | + title="Project history" |
| 76 | + variant="outline" |
| 77 | + /> |
| 78 | + <IconButton |
| 79 | + aria-label="Rename" |
| 80 | + icon={<RiEditFill />} |
| 81 | + onClick={(e) => { |
| 82 | + renameProject(project.id); |
| 83 | + e.stopPropagation(); |
| 84 | + e.preventDefault(); |
| 85 | + }} |
| 86 | + size="lg" |
| 87 | + title="Rename" |
| 88 | + variant="outline" |
| 89 | + /> |
| 90 | + <CloseButton |
| 91 | + position="absolute" |
| 92 | + right={4} |
| 93 | + top={4} |
| 94 | + onClick={(e) => { |
| 95 | + deleteProject(project.id); |
| 96 | + e.stopPropagation(); |
| 97 | + e.preventDefault(); |
| 98 | + }} |
| 99 | + /> |
| 100 | + </ProjectItemBase> |
| 101 | +); |
61 | 102 |
|
62 | 103 | interface AddProjectItemProps { |
63 | | - newProject: () => void; |
| 104 | + newProject: () => void; |
64 | 105 | } |
65 | 106 |
|
66 | | -export const AddProjectItem = ({newProject}: AddProjectItemProps) => |
67 | | - <ProjectItemBase |
68 | | - onClick={newProject} |
69 | | - > |
70 | | - <HStack justifyContent="space-between" w="100%"> |
71 | | - <Heading as="h2">New project</Heading> |
72 | | - </HStack> |
73 | | - <Text size="lg">Click to create</Text> |
74 | | - </ProjectItemBase> |
| 107 | +export const AddProjectItem = ({ newProject }: AddProjectItemProps) => ( |
| 108 | + <ProjectItemBase onClick={newProject}> |
| 109 | + <HStack justifyContent="space-between" w="100%"> |
| 110 | + <Heading as="h2">New project</Heading> |
| 111 | + </HStack> |
| 112 | + <Text size="lg">Click to create</Text> |
| 113 | + </ProjectItemBase> |
| 114 | +); |
0 commit comments