Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvel committed Nov 21, 2024
1 parent 29c50da commit 71d0834
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/frontend/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const App: React.FC = () => {

useEffect(() => {
if (currentUser && location.pathname === "/") {
navigate("/today", { replace: true }); // Navigate to /today instead of /tasks?type=today
navigate("/today", { replace: true });
}
}, [currentUser, location.pathname, navigate]);

Expand Down
3 changes: 1 addition & 2 deletions app/frontend/components/Project/ProjectDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TrashIcon,
FolderIcon,
Squares2X2Icon,
} from "@heroicons/react/24/outline"; // Updated import
} from "@heroicons/react/24/outline";
import TaskList from "../Task/TaskList";
import ProjectModal from "../Project/ProjectModal";
import ConfirmDialog from "../Shared/ConfirmDialog";
Expand All @@ -28,7 +28,6 @@ const ProjectDetails: React.FC = () => {
const [isModalOpen, setIsModalOpen] = useState(false);
const [isConfirmDialogOpen, setIsConfirmDialogOpen] = useState(false);

// Removed location.state related code
const projectTitle = project?.name || "Project";

const [isCompletedOpen, setIsCompletedOpen] = useState(false);
Expand Down
22 changes: 2 additions & 20 deletions app/frontend/components/Project/ProjectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
project,
areas,
}) => {
// Initialize form data with existing project or default values
const [formData, setFormData] = useState<Project>(
project || {
name: "",
Expand All @@ -34,21 +33,16 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
}
);

// State to manage tags as an array of tag names
const [tags, setTags] = useState<string[]>(project?.tags?.map(tag => tag.name) || []);

// Fetch available tags from the backend
const { tags: availableTags, isLoading: isTagsLoading, isError: isTagsError } = useFetchTags();

// Refs and state for handling modal animations and confirmations
const modalRef = useRef<HTMLDivElement>(null);
const [isClosing, setIsClosing] = useState(false);
const [showConfirmDialog, setShowConfirmDialog] = useState(false);

// Toast notifications for user feedback
const { showSuccessToast, showErrorToast } = useToast();

// Update form data and tags when the `project` prop changes
useEffect(() => {
if (project) {
setFormData({
Expand All @@ -68,7 +62,6 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
}
}, [project]);

// Handle clicks outside the modal to close it
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (
Expand All @@ -87,7 +80,6 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
};
}, [isOpen]);

// Handle pressing the Escape key to close the modal
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") {
Expand All @@ -102,7 +94,6 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
};
}, [isOpen]);

// Handle changes in form inputs
const handleChange = (
e: React.ChangeEvent<
HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement
Expand All @@ -112,7 +103,6 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
const { name, type, value } = target;

if (type === "checkbox") {
// Type Narrowing: Ensure target is HTMLInputElement before accessing 'checked'
if (target instanceof HTMLInputElement) {
const checked = target.checked;
setFormData((prev) => ({
Expand All @@ -128,7 +118,6 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
}
};

// Handle changes in tags using the TagInput component
const handleTagsChange = useCallback((newTags: string[]) => {
setTags(newTags);
setFormData((prev) => ({
Expand All @@ -137,7 +126,6 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
}));
}, []);

// Handle form submission
const handleSubmit = () => {
onSave({ ...formData, tags: tags.map(name => ({ name })) });
showSuccessToast(
Expand All @@ -148,12 +136,10 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
handleClose();
};

// Handle delete button click to show confirmation dialog
const handleDeleteClick = () => {
setShowConfirmDialog(true);
};

// Confirm deletion of the project
const handleDeleteConfirm = () => {
if (project && project.id && onDelete) {
onDelete(project.id);
Expand All @@ -163,19 +149,16 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
}
};

// Handle closing the modal with animation
const handleClose = () => {
setIsClosing(true);
setTimeout(() => {
onClose();
setIsClosing(false);
}, 300); // Duration should match the CSS transition
}, 300);
};

// Render nothing if the modal is not open
if (!isOpen) return null;

// Show loading state while tags are being fetched
if (isTagsLoading) {
return (
<div className="fixed top-16 left-0 right-0 bottom-0 flex items-center justify-center bg-gray-900 bg-opacity-80 z-50">
Expand All @@ -186,7 +169,6 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
);
}

// Show error state if tags failed to load
if (isTagsError) {
return (
<div className="fixed top-16 left-0 right-0 bottom-0 flex items-center justify-center bg-gray-900 bg-opacity-80 z-50">
Expand All @@ -212,7 +194,7 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
isClosing ? "scale-95" : "scale-100"
} h-screen sm:h-auto flex flex-col`}
style={{
maxHeight: "calc(100vh - 4rem)", // Prevent modal from exceeding viewport height
maxHeight: "calc(100vh - 4rem)",
}}
>
{/* Form */}
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/components/Task/TasksToday.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ClipboardDocumentListIcon,
ClockIcon,
ArrowPathIcon,
CalendarDaysIcon, // Import the icon for due tasks
CalendarDaysIcon,
} from "@heroicons/react/24/outline";

import { Task } from "../../entities/Task";
Expand Down
3 changes: 0 additions & 3 deletions app/frontend/hooks/useFetchTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const initialMetrics: Metrics = {
suggested_tasks: [],
};

// Define the fetcher function
const fetcher = (url: string) =>
fetch(url, {
credentials: 'include',
Expand All @@ -56,8 +55,6 @@ const useFetchTasks = (options?: UseFetchTasksOptions): UseFetchTasksResult => {

const queryString = params.toString();
const url = `/api/tasks${queryString ? `?${queryString}` : ''}`;

// Use SWR to fetch data
const { data, error, mutate } = useSWR(url, fetcher);

return {
Expand Down

0 comments on commit 71d0834

Please sign in to comment.