Skip to content

Commit 7ac7912

Browse files
committed
added a create collection modal button to add to collection modal
1 parent 19778f5 commit 7ac7912

4 files changed

Lines changed: 34 additions & 9 deletions

File tree

client/modules/App/components/Overlay.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ type OverlayProps = {
1515
title?: string;
1616
ariaLabel?: string;
1717
isFixedHeight?: boolean;
18+
isCompactHeight?: boolean;
1819
};
1920

2021
export const Overlay = ({
2122
actions,
2223
ariaLabel = 'modal',
2324
children,
2425
closeOverlay,
26+
isCompactHeight = false,
2527
isFixedHeight = false,
2628
title = 'Modal'
2729
}: OverlayProps) => {
@@ -43,8 +45,7 @@ export const Overlay = ({
4345
if (!node) return;
4446
// Only close if it is the last (and therefore the topmost overlay)
4547
const overlays = document.getElementsByClassName('overlay');
46-
if (node.parentElement?.parentElement !== overlays[overlays.length - 1])
47-
return;
48+
if (node.closest('.overlay') !== overlays[overlays.length - 1]) return;
4849

4950
if (!closeOverlay) {
5051
browserHistory.push(previousPath);
@@ -57,7 +58,9 @@ export const Overlay = ({
5758

5859
return (
5960
<div
60-
className={`overlay ${isFixedHeight ? 'overlay--is-fixed-height' : ''}`}
61+
className={`overlay ${isFixedHeight ? 'overlay--is-fixed-height' : ''} ${
62+
isCompactHeight ? 'overlay--is-compact-height' : ''
63+
}`}
6164
>
6265
<div className="overlay__content">
6366
<section
@@ -72,7 +75,10 @@ export const Overlay = ({
7275
{isDesktop && actions}
7376
<button
7477
className="overlay__close-button"
75-
onClick={close}
78+
onClick={(event) => {
79+
event.stopPropagation();
80+
close();
81+
}}
7682
aria-label={t('Overlay.AriaLabel', { title })}
7783
>
7884
<ExitIcon focusable="false" aria-hidden="true" />

client/modules/IDE/actions/collections.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function getCollections(username) {
3434
};
3535
}
3636

37-
export function createCollection(collection) {
37+
export function createCollection(collection, redirect = true) {
3838
return (dispatch) => {
3939
dispatch(startLoader());
4040
const url = '/collections';
@@ -52,8 +52,9 @@ export function createCollection(collection) {
5252

5353
const pathname = `/${newCollection.owner.username}/collections/${newCollection.id}`;
5454
const location = { pathname, state: { skipSavingPath: true } };
55-
56-
browserHistory.push(location);
55+
if (redirect) {
56+
browserHistory.push(location);
57+
}
5758
})
5859
.catch((error) => {
5960
dispatch({

client/modules/IDE/components/AddToCollectionList.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import {
1313
import getSortedCollections from '../selectors/collections';
1414
import QuickAddList from './QuickAddList';
1515
import { remSize } from '../../../theme';
16+
import { Overlay } from '../../App/components/Overlay';
17+
import CollectionCreate from '../../User/components/CollectionCreate';
18+
import { Button } from '../../../common/Button';
1619

1720
export const CollectionAddSketchWrapper = styled.div`
1821
width: ${remSize(600)};
@@ -40,10 +43,11 @@ const AddToCollectionList = ({ projectId }) => {
4043
const loading = useSelector((state) => state.loading);
4144
const [hasLoadedData, setHasLoadedData] = useState(false);
4245
const showLoader = loading && !hasLoadedData;
46+
const [createCollectionVisible, setCreateCollectionVisible] = useState(false);
4347

4448
useEffect(() => {
4549
dispatch(getCollections(username)).then(() => setHasLoadedData(true));
46-
}, [dispatch, username]);
50+
}, [dispatch, username, createCollectionVisible]);
4751

4852
const handleCollectionAdd = (collection) => {
4953
dispatch(addToCollection(collection.id, projectId));
@@ -80,6 +84,19 @@ const AddToCollectionList = ({ projectId }) => {
8084
<Helmet>
8185
<title>{t('AddToCollectionList.Title')}</title>
8286
</Helmet>
87+
<Button onClick={() => setCreateCollectionVisible(true)}>
88+
{t('DashboardView.CreateCollection')}
89+
</Button>
90+
91+
{createCollectionVisible && (
92+
<Overlay
93+
title={t('DashboardView.CreateCollectionOverlay')}
94+
closeOverlay={() => setCreateCollectionVisible(false)}
95+
isCompactHeight
96+
>
97+
<CollectionCreate />
98+
</Overlay>
99+
)}
83100
{getContent()}
84101
</QuickAddWrapper>
85102
</CollectionAddSketchWrapper>

client/modules/User/components/CollectionCreate.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const CollectionCreate = () => {
2424
const handleCreateCollection = (event) => {
2525
event.preventDefault();
2626

27-
dispatch(createCollection({ name, description }));
27+
// second argument is redirect flag, set to false to avoid redirect
28+
dispatch(createCollection({ name, description }, false));
2829
};
2930

3031
const invalid = name === '' || name == null;

0 commit comments

Comments
 (0)