From 8fb34fe1e380b4edec51e5e1b00b3499d890f790 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Mon, 13 Feb 2023 13:14:23 +0530 Subject: [PATCH] feat : sidebar progress improvement (#272) * feat: progress chart render validation * fix: sidebar stats tab * feat: sidebar active tab context --- .../core/sidebar/sidebar-progress-stats.tsx | 30 ++++++++++++++++++- apps/app/components/modules/sidebar.tsx | 23 +++++++++----- .../cycles/cycle-detail-sidebar/index.tsx | 26 +++++++++++----- apps/app/hooks/use-local-storage.tsx | 22 ++++++++++++++ 4 files changed, 85 insertions(+), 16 deletions(-) create mode 100644 apps/app/hooks/use-local-storage.tsx diff --git a/apps/app/components/core/sidebar/sidebar-progress-stats.tsx b/apps/app/components/core/sidebar/sidebar-progress-stats.tsx index 49c5be771..ea8e1e401 100644 --- a/apps/app/components/core/sidebar/sidebar-progress-stats.tsx +++ b/apps/app/components/core/sidebar/sidebar-progress-stats.tsx @@ -20,6 +20,7 @@ import User from "public/user.png"; import { IIssue, IIssueLabels } from "types"; // fetch-keys import { PROJECT_ISSUE_LABELS, PROJECT_MEMBERS } from "constants/fetch-keys"; +import useLocalStorage from "hooks/use-local-storage"; // types type Props = { groupedIssues: any; @@ -38,6 +39,7 @@ const stateGroupColours: { export const SidebarProgressStats: React.FC = ({ groupedIssues, issues }) => { const router = useRouter(); + const [tab, setTab] = useLocalStorage("tab", "Assignees"); const { workspaceSlug, projectId } = router.query; const { data: issueLabels } = useSWR( workspaceSlug && projectId ? PROJECT_ISSUE_LABELS(projectId as string) : null, @@ -52,8 +54,34 @@ export const SidebarProgressStats: React.FC = ({ groupedIssues, issues }) ? () => projectService.projectMembers(workspaceSlug as string, projectId as string) : null ); + + const currentValue = (tab: string) => { + switch (tab) { + case "Assignees": + return 0; + case "Labels": + return 1; + case "States": + return 2; + } + }; return ( - + { + switch (i) { + case 0: + return setTab("Assignees"); + case 1: + return setTab("Labels"); + case 2: + return setTab("States"); + + default: + return setTab("Assignees"); + } + }} + > = ({ }); }, [module, reset]); + const isStartValid = new Date(`${module?.start_date}`) <= new Date(); + const isEndValid = new Date(`${module?.target_date}`) >= new Date(`${module?.start_date}`); return ( <> = ({
- - - + {isStartValid && isEndValid ? ( + + ) : ( + "" + )} + {issues.length > 0 ? ( + + ) : ( + "" + )}
) : ( diff --git a/apps/app/components/project/cycles/cycle-detail-sidebar/index.tsx b/apps/app/components/project/cycles/cycle-detail-sidebar/index.tsx index e1aa46692..ef3788314 100644 --- a/apps/app/components/project/cycles/cycle-detail-sidebar/index.tsx +++ b/apps/app/components/project/cycles/cycle-detail-sidebar/index.tsx @@ -101,6 +101,8 @@ const CycleDetailSidebar: React.FC = ({ issues, cycle, isOpen, cycleIssue }); }, [cycle, reset]); + const isStartValid = new Date(`${cycle?.start_date}`) <= new Date(); + const isEndValid = new Date(`${cycle?.end_date}`) >= new Date(`${cycle?.start_date}`); return (
= ({ issues, cycle, isOpen, cycleIssue
-
- -
- + {isStartValid && isEndValid ? ( +
+ +
+ ) : ( + "" + )} + {issues.length > 0 ? ( + + ) : ( + "" + )}
) : ( diff --git a/apps/app/hooks/use-local-storage.tsx b/apps/app/hooks/use-local-storage.tsx new file mode 100644 index 000000000..8b863899c --- /dev/null +++ b/apps/app/hooks/use-local-storage.tsx @@ -0,0 +1,22 @@ +import React, { useEffect, useState } from "react"; + +const getSavedValue = (key: any, value: any) => { + const savedValue = localStorage.getItem(key); + if (savedValue) { + return savedValue; + } + return value; +}; + +const useLocalStorage = (key: any, value: any) => { + const [updatedvalue, seUpdatedvalue] = useState(() => getSavedValue(key, value)); + + useEffect(() => { + localStorage.setItem(key, updatedvalue); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [updatedvalue]); + + return [updatedvalue, seUpdatedvalue]; +}; + +export default useLocalStorage;