Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions packages/app/src/app/overmind/namespaces/files/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -417,10 +418,10 @@ export const gotUploadedFiles: AsyncAction<string> = async (
}
};

export const addedFileToSandbox: AsyncAction<{
url: string;
name: string;
}> = withOwnedSandbox(
export const addedFileToSandbox: AsyncAction<Pick<
UploadFile,
'name' | 'url'
>> = withOwnedSandbox(
async ({ actions, effects, state }, { name, url }) => {
if (!state.editor.currentSandbox) {
return;
Expand All @@ -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<string> = async (
{ actions, effects, state },
id
) => {
if (!state.uploadedFiles) {
return;
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<UploadFile, 'name' | 'url'>;
export const AddFileToSandboxButton: FunctionComponent<Props> = ({
name,
url,
}) => {
const {
actions: {
files: { addedFileToSandbox },
},
state: {
editor: { currentSandbox },
},
} = useOvermind();

if (!currentSandbox) {
return null;
}

return (
<Button
disabled={!currentSandbox}
Icon={AddIcon}
onClick={() => addedFileToSandbox({ name, url })}
tooltip="Add file to sandbox"
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import TooltipBase from '@codesandbox/common/lib/components/Tooltip';
import styled from 'styled-components';

export const ButtonComponent = styled.button`
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;
}
`;

export const Tooltip = styled(TooltipBase)`
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;
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { ComponentType, FunctionComponent, HTMLAttributes } from 'react';
import { ButtonComponent, Tooltip } from './elements';

type Props = {
disabled?: boolean;
Icon: ComponentType;
tooltip: string;
} & Pick<HTMLAttributes<HTMLButtonElement>, 'onClick'>;
export const Button: FunctionComponent<Props> = ({
disabled = false,
Icon,
onClick,
tooltip,
}) => (
<Tooltip content={tooltip} isEnabled={!disabled}>
<ButtonComponent onClick={onClick} type="button">
<Icon />
</ButtonComponent>
</Tooltip>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { UploadFile } from '@codesandbox/common/lib/types';
import React, { FunctionComponent } from 'react';
import DeleteIcon from 'react-icons/lib/md/delete';

import { useOvermind } from 'app/overmind';

import { Button } from './Button';

type Props = Pick<UploadFile, 'id'>;
export const DeleteFileButton: FunctionComponent<Props> = ({ id }) => {
const {
actions: {
files: { deletedUploadedFile },
},
} = useOvermind();

return (
<Button
Icon={DeleteIcon}
onClick={() => deletedUploadedFile(id)}
tooltip="Delete File"
/>
);
};

This file was deleted.

Loading