From 627f2021d6fb5862ac21b4a58a0fa7f6c1c4fe28 Mon Sep 17 00:00:00 2001 From: Nickolai Date: Fri, 9 Aug 2024 17:05:38 +0400 Subject: [PATCH] feat/main cards --- src/components/App/App.tsx | 5 +---- src/pages/Main/Main.module.scss | 31 +++-------------------------- src/pages/Main/Main.tsx | 35 ++++++++++++++++++--------------- src/services/types.ts | 1 - 4 files changed, 23 insertions(+), 49 deletions(-) diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index 2b912ff..4ea0d54 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx @@ -21,16 +21,13 @@ export interface DroppedCard { export default function App() { let { loggedIn } = useAppSelector(selectUsers); const dispatch = useAppDispatch(); - const navigate = useNavigate(); function handleRegister({ email, password }: RegisterDataProps) { dispatch(registerUser({ email, password })) .unwrap() .then((data) => { - console.log('data: ', data); if (data.access) { - console.log('data.access: ', data.access); localStorage.setItem('token', data.access); dispatch(setLoggedIn(true)); navigate('/'); @@ -81,7 +78,7 @@ export default function App() { const dropTarget = e.currentTarget; const dropTargetRect = dropTarget.getBoundingClientRect(); - const cellWidth = 330; + const cellWidth = 300; const cellHeight = 157; const columnIndex = Math.floor( diff --git a/src/pages/Main/Main.module.scss b/src/pages/Main/Main.module.scss index 86b1712..4075e69 100644 --- a/src/pages/Main/Main.module.scss +++ b/src/pages/Main/Main.module.scss @@ -2,39 +2,14 @@ @include main-container; position: relative; height: 100vh; - gap: 8px; - height: 100vh; margin: 56px 64px 0 0; - - display: grid; - grid-template-columns: repeat(3, 1fr) - // display: grid; - // grid-template-columns: repeat(3, minmax(300px, 1fr)); - // grid-auto-rows: 127px; - // grid-template-rows: repeat(auto-fill, 127px); - // justify-content: center } - -// .grid { -// display: grid; -// grid-template-columns: repeat(3, 1fr); /* Три колонки */ -// grid-auto-rows: minmax(100px, auto); /* Автоматическая высота строк */ -// gap: 8px; -// margin: 56px 64px 0 0; -// } - .cardContainer { - @include flex-column-container; + display: grid; + grid-template-columns: repeat(3, 1fr); gap: 24px; - position: relative; - } -.subordinates { - display: flex; - // justify-content: center; - gap: 24px; - position: relative; -} + diff --git a/src/pages/Main/Main.tsx b/src/pages/Main/Main.tsx index 6d1da60..3f8c026 100644 --- a/src/pages/Main/Main.tsx +++ b/src/pages/Main/Main.tsx @@ -2,6 +2,7 @@ import Card from 'src/ui/Card/Card'; import styles from 'src/pages/Main/Main.module.scss'; import { useOutletContext } from 'react-router-dom'; import { initialCardsProps } from 'src/services/types'; +import Arrow from 'src/ui/Arrow/Arrow'; export default function Main() { const { allowDrop, handleDrop, handleDragStart, cards } = useOutletContext<{ @@ -10,16 +11,23 @@ export default function Main() { handleDragStart: (e: React.DragEvent) => void; cards: initialCardsProps[]; }>(); - // console.log('cards: ', cards); + console.log('cards: ', cards); + + const allCards: initialCardsProps[] = []; + + const collectCards = (card: any) => { + allCards.push(card); + if (card.subordinates) { + card.subordinates.forEach(collectCards); + } + }; + + cards.forEach(collectCards); const renderCards = (card: initialCardsProps) => { - // const [col, row ] = card.cellId.split('-').map(Number); + const [col, row] = card.cellId.split('-').map(Number); return ( -
+
- - {card.subordinates && card.subordinates.length > 0 && ( -
- {card.subordinates.map((subordinate) => renderCards(subordinate))} -
- )}
); }; return (
- {/*
*/} - {cards.map((card) => renderCards(card))} - {/*
*/} +
+ {allCards.map((card) => renderCards(card))} +
+ {/* */}
); } diff --git a/src/services/types.ts b/src/services/types.ts index aecca4e..7d77048 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -6,7 +6,6 @@ export interface initialCardsProps { photo: string; cellId: string; subordinates: initialCardsProps[]; - // coordinates?: { top: number; left: number }; } export interface RegisterDataProps {