Skip to content

Commit c7c1ca8

Browse files
committed
🔨 Switch StorageManagementModal to use useOvermind
1 parent f2f3c22 commit c7c1ca8

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
@@ -4,7 +4,7 @@ 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 { AsyncAction } from 'app/overmind';
99
import { withOwnedSandbox } from 'app/overmind/factories';
1010
import { createOptimisticModule } from 'app/overmind/utils/common';
@@ -378,10 +378,10 @@ export const gotUploadedFiles: AsyncAction<string> = async (
378378
}
379379
};
380380

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

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

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-
});
401+
try {
402+
await effects.api.deleteUploadedFile(id);
403+
} catch (error) {
404+
state.uploadedFiles.splice(index, 0, ...removedFiles);
405+
actions.internal.handleError({
406+
message: 'Unable to delete uploaded file',
407+
error,
408+
});
409+
}
410410
}
411-
});
411+
);
412412

413413
export const filesUploaded: AsyncAction<{
414414
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)