Skip to content

Commit b93bde6

Browse files
committed
🔨 Switch StorageManagementModal to use useOvermind
1 parent f2c7f93 commit b93bde6

File tree

15 files changed

+358
-352
lines changed

15 files changed

+358
-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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
return (
24+
<Button
25+
disabled={!currentSandbox}
26+
Icon={AddIcon}
27+
onClick={() => addedFileToSandbox({ name, url })}
28+
tooltip="Add file to sandbox"
29+
/>
30+
);
31+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import TooltipBase from '@codesandbox/common/lib/components/Tooltip';
2+
import styled from 'styled-components';
3+
4+
export const Tooltip = styled(TooltipBase)`
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+
`;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, { ComponentType, FunctionComponent, HTMLAttributes } from 'react';
2+
3+
import { Tooltip } from './elements';
4+
5+
type Props = {
6+
disabled?: boolean;
7+
Icon: ComponentType;
8+
tooltip: string;
9+
} & Pick<HTMLAttributes<HTMLButtonElement>, 'onClick'>;
10+
export const Button: FunctionComponent<Props> = ({
11+
disabled = false,
12+
Icon,
13+
onClick,
14+
tooltip,
15+
}) => (
16+
<Tooltip content={tooltip} isEnabled={!disabled}>
17+
<button type="button" onClick={onClick}>
18+
<Icon />
19+
</button>
20+
</Tooltip>
21+
);
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)