Skip to content

Commit

Permalink
feat/arrows finish
Browse files Browse the repository at this point in the history
  • Loading branch information
k0t1k777 committed Aug 10, 2024
1 parent b598a90 commit 3554a8c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export default function App() {
<Header
onDragStart={handleDragStart}
droppedCards={droppedCards}
loggedIn={loggedIn}
/>
{loggedIn ? (
<div className='container'>
Expand Down
23 changes: 10 additions & 13 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import { Link } from 'react-router-dom';
import Filter from 'src/components/Filter/Filter';
import cn from 'classnames/bind';
import { useAppDispatch, useAppSelector } from 'src/store/hooks';
import { selectMembers, setIsFilterOpen } from 'src/store/features/slice/membersSlice';
import {
selectMembers,
setIsFilterOpen,
} from 'src/store/features/slice/membersSlice';
import { DroppedCard } from 'src/services/types';
import { selectUsers } from 'src/store/features/slice/userSlice';
const cx = cn.bind(styles);

interface HeaderProps {
onDragStart: (e: React.DragEvent<HTMLDivElement>) => void;
droppedCards: DroppedCard[];
loggedIn: boolean;
}

export default function Header({
onDragStart,
droppedCards,
loggedIn,
}: HeaderProps) {
export default function Header({ onDragStart, droppedCards }: HeaderProps) {
let { isFilterOpen } = useAppSelector(selectMembers);
const dispatch = useAppDispatch();
let { loggedIn } = useAppSelector(selectUsers);
const dispatch = useAppDispatch();

return (
<>
Expand All @@ -37,7 +37,7 @@ export default function Header({
<Input
placeholder='Поиск'
className={cx(styles.input, {
[styles.input_disabled]: setIsFilterOpen,
[styles.input_disabled]: isFilterOpen,
})}
/>
<FilterOutlined
Expand All @@ -50,10 +50,7 @@ export default function Header({
)}
</header>
{isFilterOpen && (
<Filter
onDragStart={onDragStart}
droppedCards={droppedCards}
/>
<Filter onDragStart={onDragStart} droppedCards={droppedCards} />
)}
</>
);
Expand Down
1 change: 1 addition & 0 deletions src/pages/Main/Main.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
width: 100%;
border-radius: $border-radius-s;
height: 127px;
transition: background-color 0.3s ease;
}
4 changes: 1 addition & 3 deletions src/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Card from 'src/ui/Card/Card';
import styles from 'src/pages/Main/Main.module.scss';
import Arrow from 'src/ui/Arrow/Arrow';
import { useOutletContext } from 'react-router-dom';
import { initialCardsProps } from 'src/services/types';
import Arrow from 'src/ui/Arrow/Arrow';
import { useEffect, useLayoutEffect, useState } from 'react';
import { numCols, numRows } from 'src/services/const';
import { useAppSelector } from 'src/store/hooks';
Expand Down Expand Up @@ -32,7 +32,6 @@ export default function Main() {
<div
key={card.id}
data-cell-id={card.id}
className={styles.cell}
style={{ gridColumn: col + 1, gridRow: row + 1 }}
>
<Card
Expand Down Expand Up @@ -98,7 +97,6 @@ export default function Main() {
const renderArrows = () => {
const newArrows = allCards.map((card) => {
const parentCard = allCards.find((item) => item.id === card.parentId);

if (parentCard) {
const parentElement = document.querySelector(
`[data-cell-id="${parentCard.id}"]`
Expand Down
16 changes: 8 additions & 8 deletions src/ui/Arrow/Arrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ interface ArrowProps {
endY: number;
}

const Arrow = ({ startX, startY, endX, endY }: ArrowProps) => {

const arrowHeadSize = 11;
export default function Arrow ({ startX, startY, endX, endY }: ArrowProps) {
const arrowHeadSize = 10;
const angle = Math.atan2(endY - startY, endX - startX);
const arrowX1 = endX - arrowHeadSize * Math.cos(angle - Math.PI / 6);
const arrowY1 = endY - arrowHeadSize * Math.sin(angle - Math.PI / 6);
const arrowX2 = endX - arrowHeadSize * Math.cos(angle + Math.PI / 6);
const arrowY2 = endY - arrowHeadSize * Math.sin(angle + Math.PI / 6);

const svgWidth = Math.max(startX, endX) + arrowHeadSize;
const svgHeight = Math.max(startY, endY) + arrowHeadSize;

return (
<svg
width={svgWidth}
height={svgHeight}
width={svgWidth}
height={svgHeight}
style={{ position: 'absolute', pointerEvents: 'none' }}
>
<line
x1={startX}
y1={startY}
x2={endX}
y2={endY}
className="arrow-line"
stroke='#8c8c8c'
strokeWidth='2'
/>
Expand All @@ -36,6 +36,7 @@ const Arrow = ({ startX, startY, endX, endY }: ArrowProps) => {
y1={endY}
x2={arrowX1}
y2={arrowY1}
className="arrow-line"
stroke='#8c8c8c'
strokeWidth='2'
/>
Expand All @@ -44,11 +45,10 @@ const Arrow = ({ startX, startY, endX, endY }: ArrowProps) => {
y1={endY}
x2={arrowX2}
y2={arrowY2}
className="arrow-line"
stroke='#8c8c8c'
strokeWidth='2'
/>
</svg>
);
};
export default Arrow;

0 comments on commit 3554a8c

Please sign in to comment.