Skip to content

Commit 4f379fd

Browse files
πŸ”¨ Switch StorageManagementModal to use useOvermind (#3438)
* πŸ”¨ Switch StorageManagementModal to use useOvermind * fix buttons * only show delete in sandbox * Cleanup Co-authored-by: Sara Vieira <[email protected]>
1 parent 601d1f4 commit 4f379fd

File tree

15 files changed

+379
-352
lines changed

15 files changed

+379
-352
lines changed

β€Žpackages/app/src/app/overmind/namespaces/files/actions.tsβ€Ž

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import {
44
getModulesAndDirectoriesInDirectory,
55
} from '@codesandbox/common/lib/sandbox/modules';
66
import getDefinition from '@codesandbox/common/lib/templates';
7-
import { Directory, Module } from '@codesandbox/common/lib/types';
7+
import { Directory, Module, UploadFile } from '@codesandbox/common/lib/types';
88
import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
9+
import denormalize from 'codesandbox-import-utils/lib/utils/files/denormalize';
10+
import { INormalizedModules } from 'codesandbox-import-util-types';
11+
912
import { AsyncAction } from 'app/overmind';
1013
import { withOwnedSandbox } from 'app/overmind/factories';
1114
import { createOptimisticModule } from 'app/overmind/utils/common';
12-
import { INormalizedModules } from 'codesandbox-import-util-types';
13-
import denormalize from 'codesandbox-import-utils/lib/utils/files/denormalize';
1415

1516
import {
1617
resolveDirectoryWrapped,
@@ -417,10 +418,10 @@ export const gotUploadedFiles: AsyncAction<string> = async (
417418
}
418419
};
419420

420-
export const addedFileToSandbox: AsyncAction<{
421-
url: string;
422-
name: string;
423-
}> = withOwnedSandbox(
421+
export const addedFileToSandbox: AsyncAction<Pick<
422+
UploadFile,
423+
'name' | 'url'
424+
>> = withOwnedSandbox(
424425
async ({ actions, effects, state }, { name, url }) => {
425426
if (!state.editor.currentSandbox) {
426427
return;
@@ -439,9 +440,10 @@ export const addedFileToSandbox: AsyncAction<{
439440
'write_code'
440441
);
441442

442-
export const deletedUploadedFile: AsyncAction<{
443-
id: string;
444-
}> = async ({ state, actions, effects }, { id }) => {
443+
export const deletedUploadedFile: AsyncAction<string> = async (
444+
{ actions, effects, state },
445+
id
446+
) => {
445447
if (!state.uploadedFiles) {
446448
return;
447449
}

β€Žpackages/app/src/app/pages/common/Modals/StorageManagementModal/AddFileToSandboxButton/elements.jsβ€Ž

Lines changed: 0 additions & 26 deletions
This file was deleted.

β€Žpackages/app/src/app/pages/common/Modals/StorageManagementModal/AddFileToSandboxButton/index.jsβ€Ž

Lines changed: 0 additions & 18 deletions
This file was deleted.

β€Žpackages/app/src/app/pages/common/Modals/StorageManagementModal/DeleteFileButton/elements.jsβ€Ž

Lines changed: 0 additions & 26 deletions
This file was deleted.

β€Žpackages/app/src/app/pages/common/Modals/StorageManagementModal/DeleteFileButton/index.jsβ€Ž

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { UploadFile } from '@codesandbox/common/lib/types';
2+
import React, { FunctionComponent } from 'react';
3+
import AddIcon from 'react-icons/lib/md/add';
4+
5+
import { useOvermind } from 'app/overmind';
6+
7+
import { Button } from './Button';
8+
9+
type Props = Pick<UploadFile, 'name' | 'url'>;
10+
export const AddFileToSandboxButton: FunctionComponent<Props> = ({
11+
name,
12+
url,
13+
}) => {
14+
const {
15+
actions: {
16+
files: { addedFileToSandbox },
17+
},
18+
state: {
19+
editor: { currentSandbox },
20+
},
21+
} = useOvermind();
22+
23+
if (!currentSandbox) {
24+
return null;
25+
}
26+
27+
return (
28+
<Button
29+
disabled={!currentSandbox}
30+
Icon={AddIcon}
31+
onClick={() => addedFileToSandbox({ name, url })}
32+
tooltip="Add file to sandbox"
33+
/>
34+
);
35+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import TooltipBase from '@codesandbox/common/lib/components/Tooltip';
2+
import styled from 'styled-components';
3+
4+
export const ButtonComponent = styled.button`
5+
font-size: 1.2em;
6+
background-color: inherit;
7+
border: none;
8+
padding: 5px 6px 9px 6px;
9+
color: rgba(255, 255, 255, 0.5);
10+
cursor: pointer;
11+
12+
&:hover {
13+
color: rgba(255, 255, 255, 1);
14+
}
15+
16+
&[disabled] {
17+
opacity: 0.5;
18+
cursor: default;
19+
}
20+
`;
21+
22+
export const Tooltip = styled(TooltipBase)`
23+
font-size: 1.2em;
24+
background-color: inherit;
25+
border: none;
26+
padding: 5px 6px 9px 6px;
27+
color: rgba(255, 255, 255, 0.5);
28+
cursor: pointer;
29+
30+
&:hover {
31+
color: rgba(255, 255, 255, 1);
32+
}
33+
34+
&[disabled] {
35+
opacity: 0.5;
36+
cursor: default;
37+
}
38+
`;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { ComponentType, FunctionComponent, HTMLAttributes } from 'react';
2+
import { ButtonComponent, Tooltip } from './elements';
3+
4+
type Props = {
5+
disabled?: boolean;
6+
Icon: ComponentType;
7+
tooltip: string;
8+
} & Pick<HTMLAttributes<HTMLButtonElement>, 'onClick'>;
9+
export const Button: FunctionComponent<Props> = ({
10+
disabled = false,
11+
Icon,
12+
onClick,
13+
tooltip,
14+
}) => (
15+
<Tooltip content={tooltip} isEnabled={!disabled}>
16+
<ButtonComponent onClick={onClick} type="button">
17+
<Icon />
18+
</ButtonComponent>
19+
</Tooltip>
20+
);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { UploadFile } from '@codesandbox/common/lib/types';
2+
import React, { FunctionComponent } from 'react';
3+
import DeleteIcon from 'react-icons/lib/md/delete';
4+
5+
import { useOvermind } from 'app/overmind';
6+
7+
import { Button } from './Button';
8+
9+
type Props = Pick<UploadFile, 'id'>;
10+
export const DeleteFileButton: FunctionComponent<Props> = ({ id }) => {
11+
const {
12+
actions: {
13+
files: { deletedUploadedFile },
14+
},
15+
} = useOvermind();
16+
17+
return (
18+
<Button
19+
Icon={DeleteIcon}
20+
onClick={() => deletedUploadedFile(id)}
21+
tooltip="Delete File"
22+
/>
23+
);
24+
};

β€Žpackages/app/src/app/pages/common/Modals/StorageManagementModal/FilesList/elements.jsβ€Ž

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
Β (0)