Skip to content

Commit a6df780

Browse files
committed
🔨 Switch StorageManagementModal to use useOvermind
1 parent d91170b commit a6df780

File tree

15 files changed

+365
-361
lines changed

15 files changed

+365
-361
lines changed

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@codesandbox/common/lib/sandbox/modules';
66
import getDefinition from '@codesandbox/common/lib/templates';
77
import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
8-
import { Directory, Module } from '@codesandbox/common/lib/types';
8+
import { Directory, Module, UploadFile } from '@codesandbox/common/lib/types';
99
import { AsyncAction } from 'app/overmind';
1010
import { withOwnedSandbox } from 'app/overmind/factories';
1111
import { createOptimisticModule } from 'app/overmind/utils/common';
@@ -379,10 +379,10 @@ export const gotUploadedFiles: AsyncAction<string> = async (
379379
}
380380
};
381381

382-
export const addedFileToSandbox: AsyncAction<{
383-
url: string;
384-
name: string;
385-
}> = withOwnedSandbox(async ({ actions, effects, state }, { name, url }) => {
382+
export const addedFileToSandbox: AsyncAction<Pick<
383+
UploadFile,
384+
'name' | 'url'
385+
>> = withOwnedSandbox(async ({ actions, effects, state }, { name, url }) => {
386386
actions.internal.closeModals(false);
387387
await actions.files.moduleCreated({
388388
title: name,
@@ -394,22 +394,22 @@ export const addedFileToSandbox: AsyncAction<{
394394
effects.executor.updateFiles(state.editor.currentSandbox);
395395
});
396396

397-
export const deletedUploadedFile: AsyncAction<{
398-
id: string;
399-
}> = withOwnedSandbox(async ({ state, actions, effects }, { id }) => {
400-
const index = state.uploadedFiles.findIndex(file => file.id === id);
401-
const removedFiles = state.uploadedFiles.splice(index, 1);
397+
export const deletedUploadedFile: AsyncAction<string> = withOwnedSandbox(
398+
async ({ actions, effects, state }, id) => {
399+
const index = state.uploadedFiles.findIndex(file => file.id === id);
400+
const removedFiles = state.uploadedFiles.splice(index, 1);
402401

403-
try {
404-
await effects.api.deleteUploadedFile(id);
405-
} catch (error) {
406-
state.uploadedFiles.splice(index, 0, ...removedFiles);
407-
actions.internal.handleError({
408-
message: 'Unable to delete uploaded file',
409-
error,
410-
});
402+
try {
403+
await effects.api.deleteUploadedFile(id);
404+
} catch (error) {
405+
state.uploadedFiles.splice(index, 0, ...removedFiles);
406+
actions.internal.handleError({
407+
message: 'Unable to delete uploaded file',
408+
error,
409+
});
410+
}
411411
}
412-
});
412+
);
413413

414414
export const filesUploaded: AsyncAction<{
415415
files: { [k: string]: { dataURI: string; type: string } };

‎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)