chore: add arrow navigation position logic

This commit is contained in:
Aaryan Khandelwal 2024-02-01 13:56:59 +05:30
parent 0cea96060e
commit b45ed5c34c
4 changed files with 46 additions and 26 deletions

View File

@ -47,7 +47,14 @@ export const ChartContextProvider: React.FC<{ children: React.ReactNode }> = ({
return ( return (
<ChartContext.Provider <ChartContext.Provider
value={{ ...state, scrollLeft, updateScrollLeft, scrollTop, updateScrollTop, dispatch: handleDispatch }} value={{
...state,
scrollLeft,
updateScrollLeft,
scrollTop,
updateScrollTop,
dispatch: handleDispatch,
}}
> >
{children} {children}
</ChartContext.Provider> </ChartContext.Provider>

View File

@ -1,9 +1,9 @@
import React, { useEffect, useRef, useState } from "react"; import React, { useEffect, useRef, useState } from "react";
import { ArrowLeft, ArrowRight } from "lucide-react"; import { ArrowLeft, ArrowRight } from "lucide-react";
// hooks // hooks
import { useChart } from "../hooks"; import { IGanttBlock, useChart } from "components/gantt-chart";
// types // helpers
import { IGanttBlock } from "../types"; import { cn } from "helpers/common.helper";
type Props = { type Props = {
block: IGanttBlock; block: IGanttBlock;
@ -201,10 +201,8 @@ export const ChartDraggable: React.FC<Props> = (props) => {
}; };
// scroll to a hidden block // scroll to a hidden block
const handleScrollToBlock = () => { const handleScrollToBlock = () => {
const scrollContainer = document.querySelector("#scroll-container") as HTMLElement; const scrollContainer = document.querySelector("#scroll-container") as HTMLDivElement;
if (!scrollContainer || !block.position) return; if (!scrollContainer || !block.position) return;
// update container's scroll position to the block's position // update container's scroll position to the block's position
scrollContainer.scrollLeft = block.position.marginLeft - 4; scrollContainer.scrollLeft = block.position.marginLeft - 4;
}; };
@ -225,13 +223,18 @@ export const ChartDraggable: React.FC<Props> = (props) => {
const textDisplacement = scrollLeft - (block.position?.marginLeft ?? 0); const textDisplacement = scrollLeft - (block.position?.marginLeft ?? 0);
console.log("scrollLeft", scrollLeft);
return ( return (
<> <>
{/* move to left side hidden block button */} {/* move to left side hidden block button */}
{isBlockHiddenOnLeft && ( {isBlockHiddenOnLeft && (
<div <div
className="fixed z-[1] ml-1 mt-1.5 grid h-8 w-8 cursor-pointer place-items-center rounded border border-custom-border-300 bg-custom-background-80 text-custom-text-200 hover:text-custom-text-100" className="absolute top-1/2 z-[1] grid h-8 w-8 cursor-pointer place-items-center rounded border border-custom-border-300 bg-custom-background-80 text-custom-text-200 hover:text-custom-text-100"
onClick={handleScrollToBlock} onClick={handleScrollToBlock}
style={{
transform: `translate(${scrollLeft + 4}px, -50%)`,
}}
> >
<ArrowLeft className="h-3.5 w-3.5" /> <ArrowLeft className="h-3.5 w-3.5" />
</div> </div>
@ -239,8 +242,11 @@ export const ChartDraggable: React.FC<Props> = (props) => {
{/* move to right side hidden block button */} {/* move to right side hidden block button */}
{isBlockHiddenOnRight && ( {isBlockHiddenOnRight && (
<div <div
className="fixed right-1 z-[1] mt-1.5 grid h-8 w-8 cursor-pointer place-items-center rounded border border-custom-border-300 bg-custom-background-80 text-custom-text-200 hover:text-custom-text-100" className="absolute top-1/2 z-[1] grid h-8 w-8 cursor-pointer place-items-center rounded border border-custom-border-300 bg-custom-background-80 text-custom-text-200 hover:text-custom-text-100"
onClick={handleScrollToBlock} onClick={handleScrollToBlock}
style={{
transform: `translate(${(block.position?.marginLeft ?? 0) - posFromLeft + window.innerWidth - 36}px, -50%)`,
}}
> >
<ArrowRight className="h-3.5 w-3.5" /> <ArrowRight className="h-3.5 w-3.5" />
</div> </div>
@ -261,17 +267,22 @@ export const ChartDraggable: React.FC<Props> = (props) => {
onMouseDown={handleBlockLeftResize} onMouseDown={handleBlockLeftResize}
onMouseEnter={() => setIsLeftResizing(true)} onMouseEnter={() => setIsLeftResizing(true)}
onMouseLeave={() => setIsLeftResizing(false)} onMouseLeave={() => setIsLeftResizing(false)}
className="absolute -left-2.5 top-1/2 z-[3] h-full w-6 -translate-y-1/2 cursor-col-resize rounded-md" className="absolute -left-2.5 top-1/2 -translate-y-1/2 z-[3] h-full w-6 cursor-col-resize rounded-md"
/> />
<div <div
className={`absolute top-1/2 h-7 w-1 -translate-y-1/2 rounded-sm bg-custom-background-100 transition-all duration-300 ${ className={cn(
isLeftResizing ? "-left-2.5" : "left-1" "absolute left-1 top-1/2 -translate-y-1/2 h-7 w-1 rounded-sm bg-custom-background-100 transition-all duration-300",
}`} {
"-left-2.5": isLeftResizing,
}
)}
/> />
</> </>
)} )}
<div <div
className={`relative z-[2] flex h-8 w-full items-center rounded ${isMoving ? "pointer-events-none" : ""}`} className={cn("relative z-[2] flex h-8 w-full items-center rounded", {
"pointer-events-none": isMoving,
})}
onMouseDown={handleBlockMove} onMouseDown={handleBlockMove}
> >
{blockToRender(block.data, textDisplacement)} {blockToRender(block.data, textDisplacement)}
@ -283,12 +294,15 @@ export const ChartDraggable: React.FC<Props> = (props) => {
onMouseDown={handleBlockRightResize} onMouseDown={handleBlockRightResize}
onMouseEnter={() => setIsRightResizing(true)} onMouseEnter={() => setIsRightResizing(true)}
onMouseLeave={() => setIsRightResizing(false)} onMouseLeave={() => setIsRightResizing(false)}
className="absolute -right-2.5 top-1/2 z-[2] h-full w-6 -translate-y-1/2 cursor-col-resize rounded-md" className="absolute -right-2.5 top-1/2 -translate-y-1/2 z-[2] h-full w-6 cursor-col-resize rounded-md"
/> />
<div <div
className={`absolute top-1/2 h-7 w-1 -translate-y-1/2 rounded-sm bg-custom-background-100 transition-all duration-300 ${ className={cn(
isRightResizing ? "-right-2.5" : "right-1" "absolute right-1 top-1/2 -translate-y-1/2 h-7 w-1 rounded-sm bg-custom-background-100 transition-all duration-300",
}`} {
"-right-2.5": isRightResizing,
}
)}
/> />
</> </>
)} )}

View File

@ -157,13 +157,13 @@ export const IssueGanttSidebar: React.FC<Props> = (props) => {
<div className="flex-grow truncate"> <div className="flex-grow truncate">
<IssueGanttSidebarBlock data={block.data} /> <IssueGanttSidebarBlock data={block.data} />
</div> </div>
<div className="flex-shrink-0 text-sm text-custom-text-200"> {duration && (
{duration && ( <div className="flex-shrink-0 text-sm text-custom-text-200">
<span> <span>
{duration} day{duration > 1 ? "s" : ""} {duration} day{duration > 1 ? "s" : ""}
</span> </span>
)} </div>
</div> )}
</div> </div>
</div> </div>
</div> </div>

View File

@ -61,7 +61,7 @@ export const IssueGanttBlock = ({ data, textDisplacement }: { data: TIssue; text
// rendering issues on gantt sidebar // rendering issues on gantt sidebar
export const IssueGanttSidebarBlock = ({ data }: { data: TIssue }) => { export const IssueGanttSidebarBlock = ({ data }: { data: TIssue }) => {
// hooks // hooks
const { getProjectStates } = useProjectState(); const { getStateById } = useProjectState();
const { getProjectById } = useProject(); const { getProjectById } = useProject();
const { const {
router: { workspaceSlug }, router: { workspaceSlug },
@ -75,8 +75,7 @@ export const IssueGanttSidebarBlock = ({ data }: { data: TIssue }) => {
data.id && data.id &&
setPeekIssue({ workspaceSlug, projectId: data.project_id, issueId: data.id }); setPeekIssue({ workspaceSlug, projectId: data.project_id, issueId: data.id });
const currentStateDetails = const currentStateDetails = getStateById(data?.state_id);
getProjectStates(data?.project_id)?.find((state) => state?.id == data?.state_id) || undefined;
return ( return (
<ControlLink <ControlLink
@ -86,7 +85,7 @@ export const IssueGanttSidebarBlock = ({ data }: { data: TIssue }) => {
className="w-full line-clamp-1 cursor-pointer text-sm text-custom-text-100" className="w-full line-clamp-1 cursor-pointer text-sm text-custom-text-100"
> >
<div className="relative flex h-full w-full cursor-pointer items-center gap-2" onClick={handleIssuePeekOverview}> <div className="relative flex h-full w-full cursor-pointer items-center gap-2" onClick={handleIssuePeekOverview}>
{currentStateDetails != undefined && ( {currentStateDetails && (
<StateGroupIcon stateGroup={currentStateDetails?.group} color={currentStateDetails?.color} /> <StateGroupIcon stateGroup={currentStateDetails?.group} color={currentStateDetails?.color} />
)} )}
<div className="flex-shrink-0 text-xs text-custom-text-300"> <div className="flex-shrink-0 text-xs text-custom-text-300">