Skip to content

Commit d7823e6

Browse files
yeion7christianalfoniSaraVieira
committed
Open folder on drag over it / Ignore thumbnail cache files (codesandbox#2951)
* refactor * fix types * add more types * support drop folders * ignore system file * prevent drag inside children folder * validation * Apply discard changes * fix types * fix ts * more type fixing Co-authored-by: Christian Alfoni <[email protected]> Co-authored-by: Sara Vieira <[email protected]>
1 parent afb207c commit d7823e6

File tree

11 files changed

+517
-461
lines changed

11 files changed

+517
-461
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,5 @@ Thanks goes to these wonderful people
251251

252252
<!-- markdownlint-enable -->
253253
<!-- prettier-ignore-end -->
254+
254255
<!-- ALL-CONTRIBUTORS-LIST:END -->

packages/app/src/app/overmind/namespaces/files/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ export const deletedUploadedFile: AsyncAction<{
402402
});
403403

404404
export const filesUploaded: AsyncAction<{
405-
files: any[];
405+
files: { [k: string]: { dataURI: string; type: string } };
406406
directoryShortid: string;
407407
}> = withOwnedSandbox(
408408
async ({ state, effects, actions }, { files, directoryShortid }) => {
@@ -420,7 +420,7 @@ export const filesUploaded: AsyncAction<{
420420
}
421421
);
422422

423-
actions.files.massCreateModules({
423+
await actions.files.massCreateModules({
424424
modules,
425425
directories,
426426
directoryShortid,

packages/app/src/app/overmind/namespaces/files/internalActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const recoverFiles: Action = ({ effects, actions, state }) => {
6060

6161
export const uploadFiles: AsyncAction<
6262
{
63-
files: any[];
63+
files: { [k: string]: { dataURI: string; type: string } };
6464
directoryShortid: string;
6565
},
6666
{

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/DirectoryChildren/ModuleEntry.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Module, Directory } from '@codesandbox/common/lib/types';
1+
import { Directory, Module } from '@codesandbox/common/lib/types';
22
import { useOvermind } from 'app/overmind';
33
// eslint-disable-next-line import/extensions
44
import getType from 'app/utils/get-type.ts';
@@ -8,18 +8,18 @@ import Entry from '../Entry';
88

99
interface IModuleEntryProps {
1010
module: Module;
11-
setCurrentModule: (id: string) => void;
12-
markTabsNotDirty: () => void;
13-
depth: number;
14-
renameModule: (title: string, moduleShortid: string) => void;
15-
deleteEntry: (shortid: string, title: string) => void;
16-
discardModuleChanges: (shortid: string) => void;
17-
getModulePath: (
11+
setCurrentModule?: (id: string) => void;
12+
markTabsNotDirty?: () => void;
13+
depth?: number;
14+
renameModule?: (title: string, moduleShortid: string) => void;
15+
deleteEntry?: (shortid: string, title: string) => void;
16+
discardModuleChanges?: (shortid: string, title: string) => void;
17+
getModulePath?: (
1818
modules: Module[],
1919
directories: Directory[],
2020
id: string
2121
) => string;
22-
renameValidator: (id: string, title: string) => string | false | null;
22+
renameValidator?: (id: string, title: string) => string | false | null;
2323
}
2424

2525
const ModuleEntry: React.FC<IModuleEntryProps> = ({

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/DirectoryChildren/index.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
import { HIDDEN_DIRECTORIES } from '@codesandbox/common/lib/templates/constants/files';
2-
import { Module, Directory } from '@codesandbox/common/lib/types';
2+
import { Directory, Module } from '@codesandbox/common/lib/types';
33
import { useOvermind } from 'app/overmind';
44
import { sortBy } from 'lodash-es';
55
import * as React from 'react';
6-
import DirectoryEntry from '..';
6+
77
import ModuleEntry from './ModuleEntry';
8+
import DirectoryEntry from '..';
89

910
interface IDirectoryChildrenProps {
10-
depth: number;
11-
renameModule: (title: string, moduleShortid: string) => void;
12-
setCurrentModule: (id: string) => void;
13-
parentShortid: string;
14-
deleteEntry: (shortid: string, title: string) => void;
15-
isInProjectView: boolean;
16-
markTabsNotDirty: () => void;
17-
discardModuleChanges: (shortid: string) => void;
18-
getModulePath: (
11+
depth?: number;
12+
renameModule?: (title: string, moduleShortid: string) => void;
13+
setCurrentModule?: (id: string) => void;
14+
parentShortid?: string;
15+
deleteEntry?: (shortid: string, title: string) => void;
16+
isInProjectView?: boolean;
17+
markTabsNotDirty?: () => void;
18+
discardModuleChanges: (moduleShortid: string, moduleName: string) => void;
19+
getModulePath?: (
1920
modules: Module[],
2021
directories: Directory[],
2122
id: string
2223
) => string;
23-
renameValidator: (id: string, title: string) => string | false | null;
24+
renameValidator?: (id: string, title: string) => string | false | null;
2425
}
2526

2627
const DirectoryChildren: React.FC<IDirectoryChildrenProps> = ({
@@ -36,10 +37,10 @@ const DirectoryChildren: React.FC<IDirectoryChildrenProps> = ({
3637
renameValidator,
3738
}) => {
3839
const {
39-
state: { isLoggedIn, editor: editorState },
40-
actions: { files, editor },
40+
state: {
41+
editor: { currentSandbox, mainModule, currentModuleShortid },
42+
},
4143
} = useOvermind();
42-
const { currentSandbox, mainModule, currentModuleShortid } = editorState;
4344

4445
const {
4546
id: sandboxId,
@@ -63,8 +64,6 @@ const DirectoryChildren: React.FC<IDirectoryChildrenProps> = ({
6364
key={dir.id}
6465
siblings={[...directories, ...modules]}
6566
depth={depth + 1}
66-
signals={{ files, editor }}
67-
store={{ editor: editorState, isLoggedIn }}
6867
id={dir.id}
6968
shortid={dir.shortid}
7069
title={dir.title}

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/index.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import theme from '@codesandbox/common/lib/theme';
2+
import { Directory, Module } from '@codesandbox/common/lib/types';
23
import { ContextMenu, Item } from 'app/components/ContextMenu';
3-
import { Module, Directory } from '@codesandbox/common/lib/types';
44
import React, { useState } from 'react';
55
import { DragSource } from 'react-dnd';
66
import EditIcon from 'react-icons/lib/go/pencil';
@@ -18,33 +18,37 @@ import EntryTitle from './EntryTitle';
1818
import { EntryTitleInput } from './EntryTitleInput';
1919

2020
interface IEntryProps {
21-
renameValidator: (id: string, title: string) => string | false | null;
22-
shortid: string;
21+
renameValidator?: (id: string, title: string) => string | false | null;
22+
shortid?: string;
2323
id: string;
24-
title: string;
24+
title?: string;
2525
rename?: (shortid: string, title: string) => void;
26-
deleteEntry: (shortid: string, title: string) => void;
27-
depth: number;
28-
type: string;
29-
active: boolean;
30-
discardModuleChanges: (shortid: string, title: string) => void;
31-
setCurrentModule: (id: string) => void;
32-
connectDragSource: (node: JSX.Element) => JSX.Element;
33-
onCreateDirectoryClick: () => boolean | void;
34-
onCreateModuleClick: () => boolean | void;
35-
onUploadFileClick: () => boolean | void;
36-
onClick: () => void;
37-
markTabsNotDirty: () => void;
26+
deleteEntry?: (shortid: string, title: string) => void;
27+
depth?: number;
28+
root?: boolean;
29+
isOpen?: boolean;
30+
hasChildren?: boolean;
31+
closeTree?: () => void;
32+
type?: string;
33+
active?: boolean;
34+
discardModuleChanges?: (shortid: string, title: string) => void;
35+
setCurrentModule?: (id: string) => void;
36+
connectDragSource?: (node: JSX.Element) => JSX.Element;
37+
onCreateDirectoryClick?: () => boolean | void;
38+
onCreateModuleClick?: () => boolean | void;
39+
onUploadFileClick?: () => boolean | void;
40+
onClick?: () => void;
41+
markTabsNotDirty?: () => void;
3842
onRenameCancel?: () => void;
39-
getModulePath: (
43+
getModulePath?: (
4044
modules: Module[],
4145
directories: Directory[],
4246
id: string
4347
) => string;
44-
isNotSynced: boolean;
45-
isMainModule: boolean;
46-
moduleHasError: boolean;
47-
rightColors: string[];
48+
isNotSynced?: boolean;
49+
isMainModule?: boolean;
50+
moduleHasError?: boolean;
51+
rightColors?: string[];
4852
state?: string;
4953
}
5054

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/elements.js renamed to packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/elements.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const EntryContainer = styled.div`
44
position: relative;
55
`;
66

7-
export const Overlay = styled.div`
7+
export const Overlay = styled.div<{ isOver: boolean }>`
88
position: absolute;
99
top: 0;
1010
bottom: 0;
@@ -14,7 +14,7 @@ export const Overlay = styled.div`
1414
display: ${props => (props.isOver ? 'block' : 'none')};
1515
`;
1616

17-
export const Opener = styled.div`
17+
export const Opener = styled.div<{ open: boolean }>`
1818
height: ${props => (props.open ? '100%' : '0px')};
1919
overflow: hidden;
2020
`;

0 commit comments

Comments
 (0)