diff --git a/app/actions/api.ts b/app/actions/api.ts index ba981c1a..90d2cacc 100644 --- a/app/actions/api.ts +++ b/app/actions/api.ts @@ -327,3 +327,36 @@ export function addDatasetAndFetch (peername: string, name: string): ApiActionTh return response } } + +export function initDataset (filepath: string, name: string, format: string): ApiActionThunk { + return async (dispatch) => { + const action = { + type: 'init', + [CALL_API]: { + endpoint: 'init', + method: 'POST', + params: { + filepath, + name, + format + } + } + } + return dispatch(action) + } +} + +export function initDatasetAndFetch (filepath: string, name: string, format: string): ApiActionThunk { + return async (dispatch, getState) => { + const whenOk = chainSuccess(dispatch, getState) + let response: Action + + try { + response = await initDataset(filepath, name, format)(dispatch, getState) + response = await whenOk(fetchMyDatasets())(response) + } catch (action) { + throw action + } + return response + } +} diff --git a/app/components/App.tsx b/app/components/App.tsx index b007697c..6269d77f 100644 --- a/app/components/App.tsx +++ b/app/components/App.tsx @@ -13,6 +13,7 @@ interface AppProps { fetchSession: () => Promise fetchMyDatasetsAndLinks: () => Promise addDataset: (peername: string, name: string) => Promise + initDataset: (path: string, name: string, format: string) => Promise acceptTOS: () => Action setPeername: () => Action hasDatasets: boolean @@ -54,7 +55,7 @@ export default class App extends React.Component { switch (Modal.type) { case ModalType.CreateDataset: return ( - this.setState({ currentModal: NoModal })} onDismissed={() => this.setState({ currentModal: NoModal })}/> + this.setState({ currentModal: NoModal })}/> ) case ModalType.AddDataset: return ( diff --git a/app/components/AppLoading.tsx b/app/components/AppLoading.tsx index b42b80ae..15d25439 100644 --- a/app/components/AppLoading.tsx +++ b/app/components/AppLoading.tsx @@ -1,5 +1,4 @@ import * as React from 'react' -// import Spinner from './chrome/Spinner' import WelcomeTemplate from './WelcomeTemplate' const version: string = require('../../version').default @@ -10,30 +9,5 @@ export const AppLoading: React.FunctionComponent = () => id='app-loading' loading={true} > - //
- //
- // - //

Starting Qri Desktop

- //
version {version}
- //
- //
- //
export default AppLoading diff --git a/app/components/modals/AddDataset.tsx b/app/components/modals/AddDataset.tsx index 0a1d1cd9..790e6db3 100644 --- a/app/components/modals/AddDataset.tsx +++ b/app/components/modals/AddDataset.tsx @@ -111,12 +111,8 @@ const AddDataset: React.FunctionComponent = ({ onDismissed, onS } } - const handleSetDismissable = (dismissable: boolean) => { - setDismissable(dismissable) - } - const handleSubmit = () => { - handleSetDismissable(false) + setDismissable(false) setLoading(true) // should fire off action and catch error response // if success, fetchDatatsets diff --git a/app/components/modals/CreateDataset.tsx b/app/components/modals/CreateDataset.tsx index 3ab1a7b8..f24b339a 100644 --- a/app/components/modals/CreateDataset.tsx +++ b/app/components/modals/CreateDataset.tsx @@ -1,7 +1,8 @@ import * as React from 'react' import { remote } from 'electron' import { CSSTransition } from 'react-transition-group' -import Modal, { ModalProps } from './Modal' +import Modal from './Modal' +import { ApiAction } from '../../store/api' import TextInput from '../form/TextInput' import SelectInput from '../form/SelectInput' import Error from './Error' @@ -23,7 +24,12 @@ enum TabTypes { ExistingBody = 'Use existing file', } -const CreateDataset: React.FunctionComponent = ({ onDismissed, onSubmit }) => { +interface CreateDatasetProps { + onDismissed: () => void + onSubmit: (path: string, name: string, format: string) => Promise +} + +const CreateDataset: React.FunctionComponent = ({ onDismissed, onSubmit }) => { const [datasetName, setDatasetName] = React.useState('') const [path, setPath] = React.useState('') const [bodyFormat, setBodyFormat] = React.useState(formatOptions[0].value) @@ -104,12 +110,6 @@ const CreateDataset: React.FunctionComponent = ({ onDismissed, onSub .then(() => setDismissable(true)) } - const handleSetActiveTab = (activeTab: TabTypes) => { - setActiveTab(activeTab) - toggleButton(activeTab) - setError('') - } - const renderCreateDataset = () => { return (
@@ -148,11 +148,11 @@ const CreateDataset: React.FunctionComponent = ({ onDismissed, onSub } if (name === 'format') setBodyFormat(value) if (name === 'bodyPath') setBodyPath(value) - toggleButton(activeTab) } const renderTabs = () => { - return + // return setActiveTab(activeTab)}/> + return setActiveTab(activeTab)}/> } const renderCreateNewBody = () => @@ -202,23 +202,13 @@ const CreateDataset: React.FunctionComponent = ({ onDismissed, onSub setLoading(true) // should fire off action and catch error response // if success, fetchDatatsets - const handleResponse = () => { - if (datasetName === 'error' || path === 'error' || bodyPath === 'error') { - setError('could not find dataset!') - setDismissable(true) + if (!onSubmit) return + onSubmit(path, datasetName, bodyFormat) + .then(() => onDismissed()) + .catch((action) => { setLoading(false) - return - } - if (onSubmit) { - new Promise((resolve) => { - onSubmit() - resolve() - }).then(() => - setTimeout(onDismissed, 200) - ) - } - } - setTimeout(handleResponse, 1000) + setError(action.payload.err.message) + }) } return ( @@ -243,7 +233,7 @@ const CreateDataset: React.FunctionComponent = ({ onDismissed, onSub