* Add next suggestions and remove console logs * Add pomodoro timer * Add pomodoro switch in settings * Fix pomodoro setting * Add timezones to settings * Fix an issue with password reset * Cleanup * Sort tags alphabetically * Clean up today's view * Add an indicator for repeatedly added to today * Refactor tags * Add due date today item * Move recurrence to the subtitle area * Fix today layout * Add a badge to Inbox items * Move inbox badge to sidebar * Add quotes and progress bar * Add translations for quotes * Fix test issues * Add helper script for docker local * Set up overdue tasks * Add linux/arm/v7 build to deploy script * Add linux/arm/v7 build to deploy script pt2 * Fix an issue with helmet and SSL * Add volume db persistence * Fix cog icon issues
166 lines
5.5 KiB
TypeScript
166 lines
5.5 KiB
TypeScript
import React from "react";
|
|
import { Link } from "react-router-dom";
|
|
import { EllipsisVerticalIcon } from "@heroicons/react/24/solid";
|
|
import { Project } from "../../entities/Project";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
interface ProjectItemProps {
|
|
project: Project;
|
|
viewMode: "cards" | "list";
|
|
color: string;
|
|
getCompletionPercentage: () => number;
|
|
activeDropdown: number | null;
|
|
setActiveDropdown: React.Dispatch<React.SetStateAction<number | null>>;
|
|
handleEditProject: (project: Project) => void;
|
|
setProjectToDelete: React.Dispatch<React.SetStateAction<Project | null>>;
|
|
setIsConfirmDialogOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
}
|
|
|
|
const getProjectInitials = (name: string) => {
|
|
const words = name
|
|
.trim()
|
|
.split(" ")
|
|
.filter((word) => word.length > 0);
|
|
if (words.length === 1) {
|
|
return name.toUpperCase();
|
|
}
|
|
return words.map((word) => word[0].toUpperCase()).join("");
|
|
};
|
|
|
|
const ProjectItem: React.FC<ProjectItemProps> = ({
|
|
project,
|
|
viewMode,
|
|
color,
|
|
getCompletionPercentage,
|
|
activeDropdown,
|
|
setActiveDropdown,
|
|
handleEditProject,
|
|
setProjectToDelete,
|
|
setIsConfirmDialogOpen,
|
|
}) => {
|
|
const { t } = useTranslation();
|
|
return (
|
|
<div
|
|
className={`${
|
|
viewMode === "cards"
|
|
? "bg-gray-50 dark:bg-gray-900 rounded-lg shadow-md relative flex flex-col"
|
|
: "bg-gray-50 dark:bg-gray-900 rounded-lg shadow-md relative flex flex-row items-center p-4"
|
|
}`}
|
|
style={{
|
|
minHeight: viewMode === "cards" ? "250px" : "auto",
|
|
maxHeight: viewMode === "cards" ? "250px" : "auto",
|
|
}}
|
|
>
|
|
{viewMode === "cards" && (
|
|
<div
|
|
className="bg-gray-200 dark:bg-gray-700 flex items-center justify-center overflow-hidden rounded-t-lg relative"
|
|
style={{ height: "140px" }}
|
|
>
|
|
{project.image_url ? (
|
|
<img
|
|
src={project.image_url}
|
|
alt={project.name}
|
|
className="w-full h-full object-cover"
|
|
/>
|
|
) : (
|
|
<span
|
|
className="text-2xl font-extrabold text-gray-500 dark:text-gray-400 opacity-20"
|
|
aria-label={t("projectItem.projectInitials")}
|
|
>
|
|
{getProjectInitials(project.name)}
|
|
</span>
|
|
)}
|
|
<div
|
|
className={`absolute top-2 left-2 w-3 h-3 rounded-full ${color}`}
|
|
></div>
|
|
</div>
|
|
)}
|
|
|
|
{viewMode === "list" && project.image_url && (
|
|
<div className="w-16 h-16 mr-4 flex-shrink-0">
|
|
<img
|
|
src={project.image_url}
|
|
alt={project.name}
|
|
className="w-full h-full object-cover rounded-md"
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
<div
|
|
className={`flex justify-between items-start ${
|
|
viewMode === "cards" ? "p-4 flex-1" : "flex-1"
|
|
}`}
|
|
>
|
|
<div className="flex items-center">
|
|
{viewMode === "list" && !project.image_url && (
|
|
<div className={`w-3 h-3 rounded-full ${color} mr-3 flex-shrink-0`}></div>
|
|
)}
|
|
<Link
|
|
to={`/project/${project.id}`}
|
|
className={`${
|
|
viewMode === "cards"
|
|
? "text-lg font-semibold text-gray-900 dark:text-gray-100 hover:underline line-clamp-2"
|
|
: "text-md font-semibold text-gray-900 dark:text-gray-100 hover:underline"
|
|
}`}
|
|
>
|
|
{project.name}
|
|
</Link>
|
|
</div>
|
|
<div className="relative">
|
|
<button
|
|
className="text-gray-500 hover:text-gray-700 dark:text-gray-300 dark:hover:text-gray-400 focus:outline-none"
|
|
onClick={() =>
|
|
setActiveDropdown(
|
|
activeDropdown === project.id ? null : project.id ?? null
|
|
)
|
|
}
|
|
aria-label={t("projectItem.toggleDropdownMenu")}
|
|
>
|
|
<EllipsisVerticalIcon className="h-5 w-5" />
|
|
</button>
|
|
|
|
{activeDropdown === project.id && (
|
|
<div className="absolute right-0 mt-2 w-28 bg-white dark:bg-gray-700 shadow-lg rounded-md z-10">
|
|
<button
|
|
onClick={() => handleEditProject(project)}
|
|
className="block px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-600 w-full text-left"
|
|
>
|
|
{t("projectItem.edit")}
|
|
</button>
|
|
<button
|
|
onClick={() => {
|
|
setProjectToDelete(project);
|
|
setIsConfirmDialogOpen(true);
|
|
setActiveDropdown(null);
|
|
}}
|
|
className="block px-4 py-2 text-sm text-red-500 dark:text-red-300 hover:bg-gray-100 dark:hover:bg-gray-600 w-full text-left"
|
|
>
|
|
{t("projectItem.delete")}
|
|
</button>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{viewMode === "cards" && (
|
|
<div className="absolute bottom-4 left-0 right-0 px-4">
|
|
<div className="flex items-center space-x-2">
|
|
<div
|
|
className="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2"
|
|
title={t("projectItem.completionPercentage", { percentage: getCompletionPercentage() })}
|
|
>
|
|
<div
|
|
className="bg-blue-500 h-2 rounded-full"
|
|
style={{
|
|
width: `${getCompletionPercentage()}%`,
|
|
}}
|
|
></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default ProjectItem;
|