Skip to content

Commit

Permalink
library fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rayzhou-bit committed Apr 26, 2024
1 parent 6711895 commit 9935854
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/components-shared/Dropdowns/ActionDropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ $y: 38px;
}

.item-btn {
height: 30px;
width: 100%;
margin: 0;
padding: 0;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Card/LibraryCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import { useLibraryCardHooks } from './hooks';

import Title from './Title';
import LibraryTitle from './LibraryTitle';
import LibraryContent from './LibraryContent';

import './LibraryCard.scss';
Expand Down Expand Up @@ -35,7 +35,7 @@ const LibraryCard = ({ cardId }) => {
style={cardAnimation}
>
{/* <div className="library-border"> */}
<Title
<LibraryTitle
cardId={cardId}
setEditingCard={setIsEditing}
/>
Expand Down
105 changes: 105 additions & 0 deletions src/components/Card/LibraryTitle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import React from 'react';

import { useTitleHooks, useColorDropdownHooks, useOptionsDropdownLibraryHooks } from './hooks';

import ColorDropdown from '../../components-shared/Dropdowns/ColorDropdown';
import ActionDropdown from '../../components-shared/Dropdowns/ActionDropdown';

import './Card.scss';
import '../../styles/colors.scss';
import OpenColorBlackIcon from '../../assets/icons/rounded-square.svg';
import OpenColorWhiteIcon from '../../assets/icons/rounded-square-white.svg';
import DropdownArrowBlackIcon from '../../assets/icons/dropdown-arrow.svg';
import DropdownArrowWhiteIcon from '../../assets/icons/dropdown-arrow-white.svg';

const LibraryTitle = ({
cardId,
setEditingCard,
}) => {

const {
inputClassName,
readOnly,
titleRef,
titleValue,
changeTitleValue,
beginTitleEdit,
endTitleEdit,
handleTitleKeyPress,
} = useTitleHooks({
cardId,
setEditingCard,
});

const {
color,
colorDropdownBtnRef,
isColorDropdownOpen,
isLightColor,
closeColorDropdown,
openColorDropdown,
updateColor,
} = useColorDropdownHooks({ cardId });

const {
isOptionDropdownOpen,
options,
optionDropdownBtnRef,
closeOptionsDropdown,
openOptionsDropdown,
} = useOptionsDropdownLibraryHooks({
beginTitleEdit,
cardId,
});

return (
<div className={'title ' + color}>
<div className={'input-div' + (isLightColor ? ' dark' : ' light')}>
<input
className={inputClassName}
maxLength='50'
onBlur={endTitleEdit}
onChange={(e) => changeTitleValue(e.target.value)}
onDoubleClick={beginTitleEdit}
onDragOver={(e) => e.preventDefault()}
onKeyDown={handleTitleKeyPress}
readOnly={readOnly}
ref={titleRef}
title={titleValue}
type='text'
value={titleValue}
/>
</div>
<button
className='color-btn'
onClick={openColorDropdown}
ref={colorDropdownBtnRef}
>
<img src={isLightColor ? OpenColorBlackIcon : OpenColorWhiteIcon} />
</button>
<ColorDropdown
cardId={cardId}
btnRef={colorDropdownBtnRef}
cardColor={color}
isOpen={isColorDropdownOpen}
onClose={closeColorDropdown}
onUpdateColor={updateColor}
/>
<button
className='dropdown-btn'
ref={optionDropdownBtnRef}
onClick={openOptionsDropdown}
>
<img src={isLightColor ? DropdownArrowBlackIcon : DropdownArrowWhiteIcon} />
</button>
<ActionDropdown
btnRef={optionDropdownBtnRef}
isOpen={isOptionDropdownOpen}
onClose={closeOptionsDropdown}
items={options}
/>
</div>
);
};

export default LibraryTitle;
70 changes: 63 additions & 7 deletions src/components/Card/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ACTION_TYPE } from '../../components-shared/Dropdowns/ActionDropdown';

import LibraryIcon from '../../assets/icons/library-icon.png';
import RedTrashIcon from '../../assets/icons/red-trash.png';
import { DEFAULT_CARD_POSITION } from '../../data/redux/project/constants';

export const ANIMATION = {
cardBlink: 'card-blink .25s step-end 4 alternate',
Expand Down Expand Up @@ -120,6 +121,7 @@ export const useLibraryCardHooks = ({
const [isSelected, setIsSelected] = useState(false);
const [isEditing, setIsEditing] = useState(false);
const [cardAnimation, setCardAnimation] = useState({});
const [useAnimation, setUseAnimation] = useState(false);

const libraryCardRef = useRef();

Expand All @@ -139,13 +141,19 @@ export const useLibraryCardHooks = ({
isEditing,
cardAnimation: { animation: cardAnimation[cardId] },
setIsEditing,
onDragStart: (event) => event.dataTransfer.setData('text', cardId),
onDragEnd: () => {
onDragStart: (event) => {
event.dataTransfer.setData('text', cardId);
if (cardTabs[activeTab]) {
setUseAnimation(true);
}
},
onDragEnd: () => {
if (useAnimation) {
setCardAnimation({
...cardAnimation,
[cardId]: ANIMATION.libraryCardBlink,
});
setUseAnimation(false);
}
},
onAnimationEnd: () => setCardAnimation({
Expand Down Expand Up @@ -253,10 +261,6 @@ export const useOptionsDropdownHooks = ({
const optionDropdownBtnRef = useRef();

const options = [
// {
// title: 'Insert image',
// callback: () => {},
// },
{
title: 'Duplicate card',
callback: () => dispatch(actions.project.copyCard({ id: cardId })),
Expand All @@ -276,7 +280,7 @@ export const useOptionsDropdownHooks = ({
// callback: () => {},
// },
{
title: 'Move to unsorted',
title: 'Remove from tab',
callback: () => dispatch(actions.project.unlinkCardFromView({ id: cardId })),
icon: LibraryIcon,
},
Expand All @@ -301,6 +305,58 @@ export const useOptionsDropdownHooks = ({
};
};

export const useOptionsDropdownLibraryHooks = ({
beginTitleEdit,
cardId,
}) => {
const dispatch = useDispatch();

const activeTab = useSelector(state => state.project.present.activeViewId);
const cardTabs = useSelector(state => state.project.present.cards[cardId].views);
const [ isOptionDropdownOpen, setIsOptionDropdownOpen ] = useState(false);
const optionDropdownBtnRef = useRef();

const options = [
{
title: 'Add to tab',
type: cardTabs[activeTab] ? ACTION_TYPE.disabled : null,
callback: () => dispatch(actions.project.linkCardToView({ id: cardId, position: DEFAULT_CARD_POSITION })),
},
{
title: 'Remove from tab',
type: cardTabs[activeTab] ? null : ACTION_TYPE.disabled,
callback: () => dispatch(actions.project.unlinkCardFromView({ id: cardId })),
},
// {
// title: 'Duplicate card',
// callback: () => dispatch(actions.project.copyCard({ id: cardId })),
// },
{},
{
title: 'Rename',
callback: () => beginTitleEdit(),
},
{},
{
title: 'Delete',
type: ACTION_TYPE.danger,
icon: RedTrashIcon,
callback: () => dispatch(actions.session.setPopup({
type: POPUP_KEYS.confirmCardDelete,
id: cardId,
})),
},
];

return {
optionDropdownBtnRef,
isOptionDropdownOpen,
options,
openOptionsDropdown: () => setIsOptionDropdownOpen(!isOptionDropdownOpen),
closeOptionsDropdown: () => setIsOptionDropdownOpen(false),
};
};

export const useContentHooks = ({
cardId,
setEditingCard,
Expand Down

0 comments on commit 9935854

Please sign in to comment.