diff --git a/packages/app/src/app/overmind/namespaces/files/actions.ts b/packages/app/src/app/overmind/namespaces/files/actions.ts index 5ce46105b96..e4f2d7316ce 100755 --- a/packages/app/src/app/overmind/namespaces/files/actions.ts +++ b/packages/app/src/app/overmind/namespaces/files/actions.ts @@ -4,13 +4,14 @@ import { getModulesAndDirectoriesInDirectory, } from '@codesandbox/common/lib/sandbox/modules'; import getDefinition from '@codesandbox/common/lib/templates'; -import { Directory, Module } from '@codesandbox/common/lib/types'; +import { Directory, Module, UploadFile } from '@codesandbox/common/lib/types'; import { getTextOperation } from '@codesandbox/common/lib/utils/diff'; +import denormalize from 'codesandbox-import-utils/lib/utils/files/denormalize'; +import { INormalizedModules } from 'codesandbox-import-util-types'; + import { AsyncAction } from 'app/overmind'; import { withOwnedSandbox } from 'app/overmind/factories'; import { createOptimisticModule } from 'app/overmind/utils/common'; -import { INormalizedModules } from 'codesandbox-import-util-types'; -import denormalize from 'codesandbox-import-utils/lib/utils/files/denormalize'; import { resolveDirectoryWrapped, @@ -417,10 +418,10 @@ export const gotUploadedFiles: AsyncAction = async ( } }; -export const addedFileToSandbox: AsyncAction<{ - url: string; - name: string; -}> = withOwnedSandbox( +export const addedFileToSandbox: AsyncAction> = withOwnedSandbox( async ({ actions, effects, state }, { name, url }) => { if (!state.editor.currentSandbox) { return; @@ -439,9 +440,10 @@ export const addedFileToSandbox: AsyncAction<{ 'write_code' ); -export const deletedUploadedFile: AsyncAction<{ - id: string; -}> = async ({ state, actions, effects }, { id }) => { +export const deletedUploadedFile: AsyncAction = async ( + { actions, effects, state }, + id +) => { if (!state.uploadedFiles) { return; } diff --git a/packages/app/src/app/pages/common/Modals/StorageManagementModal/AddFileToSandboxButton/elements.js b/packages/app/src/app/pages/common/Modals/StorageManagementModal/AddFileToSandboxButton/elements.js deleted file mode 100644 index 6d1600bb57c..00000000000 --- a/packages/app/src/app/pages/common/Modals/StorageManagementModal/AddFileToSandboxButton/elements.js +++ /dev/null @@ -1,26 +0,0 @@ -import React from 'react'; -import styled from 'styled-components'; -import AddIcon from 'react-icons/lib/md/add'; -import Tooltip from '@codesandbox/common/lib/components/Tooltip'; - -export const AddFileToSandboxButton = styled(props => ( - - - -))` - font-size: 1.2em; - background-color: inherit; - border: none; - padding: 5px 6px 9px 6px; - color: rgba(255, 255, 255, 0.5); - cursor: pointer; - &:hover { - color: rgba(255, 255, 255, 1); - } - &[disabled] { - opacity: 0.5; - cursor: default; - } -`; diff --git a/packages/app/src/app/pages/common/Modals/StorageManagementModal/AddFileToSandboxButton/index.js b/packages/app/src/app/pages/common/Modals/StorageManagementModal/AddFileToSandboxButton/index.js deleted file mode 100644 index 05035497dcd..00000000000 --- a/packages/app/src/app/pages/common/Modals/StorageManagementModal/AddFileToSandboxButton/index.js +++ /dev/null @@ -1,18 +0,0 @@ -import React from 'react'; -import { AddFileToSandboxButton } from './elements'; - -export default class AddFileToSandboxButtonContainer extends React.PureComponent { - addFileToSandbox = () => { - const { onAddFileToSandbox, url, name } = this.props; - onAddFileToSandbox({ url, name }); - }; - - render() { - return ( - - ); - } -} diff --git a/packages/app/src/app/pages/common/Modals/StorageManagementModal/DeleteFileButton/elements.js b/packages/app/src/app/pages/common/Modals/StorageManagementModal/DeleteFileButton/elements.js deleted file mode 100644 index bb59cf2a036..00000000000 --- a/packages/app/src/app/pages/common/Modals/StorageManagementModal/DeleteFileButton/elements.js +++ /dev/null @@ -1,26 +0,0 @@ -import React from 'react'; -import styled from 'styled-components'; -import DeleteIcon from 'react-icons/lib/md/delete'; -import Tooltip from '@codesandbox/common/lib/components/Tooltip'; - -export const DeleteFileButton = styled(props => ( - - - -))` - font-size: 1.2em; - background-color: inherit; - border: none; - padding: 5px 6px 9px 6px; - color: rgba(255, 255, 255, 0.5); - cursor: pointer; - &:hover { - color: rgba(255, 255, 255, 1); - } - &[disabled] { - opacity: 0.5; - cursor: default; - } -`; diff --git a/packages/app/src/app/pages/common/Modals/StorageManagementModal/DeleteFileButton/index.js b/packages/app/src/app/pages/common/Modals/StorageManagementModal/DeleteFileButton/index.js deleted file mode 100644 index 93a76398f22..00000000000 --- a/packages/app/src/app/pages/common/Modals/StorageManagementModal/DeleteFileButton/index.js +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react'; -import { DeleteFileButton } from './elements'; - -export default class DeleteFileButtonContainer extends React.PureComponent { - deleteFile = () => { - this.props.onDelete({ id: this.props.id }); - }; - - render() { - return ; - } -} diff --git a/packages/app/src/app/pages/common/Modals/StorageManagementModal/FilesList/AddFileToSandboxButton.tsx b/packages/app/src/app/pages/common/Modals/StorageManagementModal/FilesList/AddFileToSandboxButton.tsx new file mode 100644 index 00000000000..38737dfbd19 --- /dev/null +++ b/packages/app/src/app/pages/common/Modals/StorageManagementModal/FilesList/AddFileToSandboxButton.tsx @@ -0,0 +1,35 @@ +import { UploadFile } from '@codesandbox/common/lib/types'; +import React, { FunctionComponent } from 'react'; +import AddIcon from 'react-icons/lib/md/add'; + +import { useOvermind } from 'app/overmind'; + +import { Button } from './Button'; + +type Props = Pick; +export const AddFileToSandboxButton: FunctionComponent = ({ + name, + url, +}) => { + const { + actions: { + files: { addedFileToSandbox }, + }, + state: { + editor: { currentSandbox }, + }, + } = useOvermind(); + + if (!currentSandbox) { + return null; + } + + return ( + - - - - - - - File - Size - - - - - - - {sortBy(files, 'name').map((f, i) => ( - - - - - - - - - - - - ))} - -
- this.toggleCheckbox(e, f.id)} - selected={this.state[f.id]} - /> - - - {f.name} - - {filesize(f.objectSize)}
- - ); - } -} - -export default FilesList; diff --git a/packages/app/src/app/pages/common/Modals/StorageManagementModal/FilesList/index.tsx b/packages/app/src/app/pages/common/Modals/StorageManagementModal/FilesList/index.tsx new file mode 100644 index 00000000000..a0107da9057 --- /dev/null +++ b/packages/app/src/app/pages/common/Modals/StorageManagementModal/FilesList/index.tsx @@ -0,0 +1,137 @@ +import { Button } from '@codesandbox/common/lib/components/Button'; +import filesize from 'filesize'; +import { sortBy } from 'lodash-es'; +import React, { FunctionComponent, useState } from 'react'; + +import { useOvermind } from 'app/overmind'; + +import { AddFileToSandboxButton } from './AddFileToSandboxButton'; +import { DeleteFileButton } from './DeleteFileButton'; +import { + Body, + Buttons, + CheckBox, + Container, + FileRow, + HeaderTitle, + StatBody, + Table, +} from './elements'; + +export const FilesList: FunctionComponent = () => { + const { + actions: { + files: { deletedUploadedFile, addedFileToSandbox }, + }, + state: { + editor: { currentSandbox }, + uploadedFiles, + }, + } = useOvermind(); + const [selectedItems, setSelectedItems] = useState([]); + + const getSelection = () => + uploadedFiles.filter(({ id }) => selectedItems.includes(id)); + const toggleCheckbox = (id: string) => + setSelectedItems(items => + items.includes(id) ? items.filter(item => item !== id) : items.concat(id) + ); + + return ( + + + + + + + + + + + + + File + + Size + + + + + + + + + + + {sortBy(uploadedFiles, 'name').map( + ({ id, name, objectSize, url }, index) => ( + + + + + + + + + + + + + + + + ) + )} + +
+ toggleCheckbox(id)} + selected={selectedItems.includes(id)} + /> + + + {name} + + {filesize(objectSize)}
+
+ ); +}; diff --git a/packages/app/src/app/pages/common/Modals/StorageManagementModal/elements.ts b/packages/app/src/app/pages/common/Modals/StorageManagementModal/elements.ts index a7b4a6faf25..827a41b714d 100644 --- a/packages/app/src/app/pages/common/Modals/StorageManagementModal/elements.ts +++ b/packages/app/src/app/pages/common/Modals/StorageManagementModal/elements.ts @@ -1,9 +1,11 @@ -import styled, { keyframes } from 'styled-components'; +import styled, { css, keyframes } from 'styled-components'; export const Container = styled.div` - background-color: ${props => props.theme.background}; - width: 100%; - padding-bottom: 2rem; + ${({ theme }) => css` + background-color: ${theme.background}; + width: 100%; + padding-bottom: 2rem; + `}; `; export const JustifiedArea = styled.div` @@ -16,7 +18,6 @@ export const Title = styled.h2` font-weight: 500; padding: 2rem; color: rgba(255, 255, 255, 0.9); - margin-top: 0 !important; font-size: 1.125rem; margin: 0; text-transform: uppercase; @@ -27,7 +28,6 @@ export const SubTitle = styled.p` font-weight: 700; font-size: 0.875rem; padding: 2rem; - margin-top: 0 !important; margin: 0; line-height: 1.4; `; @@ -41,12 +41,13 @@ export const Description = styled.div` `; export const SubDescription = styled.div` - margin: 0; - padding-left: 2rem; - font-weight: 500; - color: ${props => - props.theme.light ? 'rgba(0, 0, 0, 0.7)' : 'rgba(255, 255, 255, 0.7)'}; - font-size: 1rem; + ${({ theme }) => css` + margin: 0; + padding-left: 2rem; + font-weight: 500; + color: ${theme.light ? 'rgba(0, 0, 0, 0.7)' : 'rgba(255, 255, 255, 0.7)'}; + font-size: 1rem; + `}; `; export const Rule = styled.hr` @@ -62,6 +63,7 @@ const loadingAnimation = keyframes` 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } diff --git a/packages/app/src/app/pages/common/Modals/StorageManagementModal/index.tsx b/packages/app/src/app/pages/common/Modals/StorageManagementModal/index.tsx index baaad54a51d..b7750230c03 100644 --- a/packages/app/src/app/pages/common/Modals/StorageManagementModal/index.tsx +++ b/packages/app/src/app/pages/common/Modals/StorageManagementModal/index.tsx @@ -5,29 +5,20 @@ import { useOvermind } from 'app/overmind'; import { Container, - Title, - JustifiedArea, - SubTitle, Description, - SubDescription, - Rule, + JustifiedArea, LoadingAnimationContainer, + Rule, + SubDescription, + SubTitle, + Title, } from './elements'; -import FilesList from './FilesList'; +import { FilesList } from './FilesList'; export const StorageManagementModal: FunctionComponent = () => { const { - state: { - editor: { currentSandbox }, - usedStorage, - maxStorage, - uploadedFiles, - }, - actions: { - files: { deletedUploadedFile, addedFileToSandbox }, - }, + state: { maxStorage, uploadedFiles, usedStorage }, } = useOvermind(); - const isLoading = uploadedFiles === null; const isEmpty = !isLoading && uploadedFiles.length === 0; @@ -37,9 +28,7 @@ export const StorageManagementModal: FunctionComponent = () => { Storage Management - Used {filesize(usedStorage)} - {' / '} - Total {filesize(maxStorage)} + {`Used ${filesize(usedStorage)} / Total ${filesize(maxStorage)}`} @@ -49,15 +38,7 @@ export const StorageManagementModal: FunctionComponent = () => { - {!isEmpty && !isLoading && ( - files.map(id => deletedUploadedFile({ id }))} - addFilesToSandbox={files => files.map(addedFileToSandbox)} - addFileToSandbox={currentSandbox ? addedFileToSandbox : undefined} - /> - )} + {!isEmpty && !isLoading && } {isEmpty && You have no uploaded files.}