|
|
@ -4,7 +4,7 @@ import { Dropdown } from 'react-bootstrap' |
|
|
|
import { CustomIconsToggle, CustomMenu, CustomToggle, CustomTooltip, extractNameFromKey, extractParentFromKey } from '@remix-ui/helper' |
|
|
|
import { CustomIconsToggle, CustomMenu, CustomToggle, CustomTooltip, extractNameFromKey, extractParentFromKey } from '@remix-ui/helper' |
|
|
|
import { CopyToClipboard } from '@remix-ui/clipboard' |
|
|
|
import { CopyToClipboard } from '@remix-ui/clipboard' |
|
|
|
import {FileExplorer} from './components/file-explorer' // eslint-disable-line
|
|
|
|
import {FileExplorer} from './components/file-explorer' // eslint-disable-line
|
|
|
|
import {ModalDialog} from '@remix-ui/modal-dialog' // eslint-disable-line
|
|
|
|
import {ModalDialog, ValidationResult} from '@remix-ui/modal-dialog' // eslint-disable-line
|
|
|
|
import { FileSystemContext } from './contexts' |
|
|
|
import { FileSystemContext } from './contexts' |
|
|
|
import './css/remix-ui-workspace.css' |
|
|
|
import './css/remix-ui-workspace.css' |
|
|
|
import { ROOT_PATH, TEMPLATE_NAMES } from './utils/constants' |
|
|
|
import { ROOT_PATH, TEMPLATE_NAMES } from './utils/constants' |
|
|
@ -109,6 +109,7 @@ export function Workspace() { |
|
|
|
const [modalState, setModalState] = useState<{ |
|
|
|
const [modalState, setModalState] = useState<{ |
|
|
|
searchInput: string |
|
|
|
searchInput: string |
|
|
|
showModalDialog: boolean |
|
|
|
showModalDialog: boolean |
|
|
|
|
|
|
|
// modalValidation?: ValidationResult
|
|
|
|
modalInfo: { |
|
|
|
modalInfo: { |
|
|
|
title: string |
|
|
|
title: string |
|
|
|
loadItem: string |
|
|
|
loadItem: string |
|
|
@ -117,15 +118,17 @@ export function Workspace() { |
|
|
|
} |
|
|
|
} |
|
|
|
importSource: string |
|
|
|
importSource: string |
|
|
|
toasterMsg: string |
|
|
|
toasterMsg: string |
|
|
|
recentWorkspaces: Array<string> |
|
|
|
|
|
|
|
}>({ |
|
|
|
}>({ |
|
|
|
searchInput: '', |
|
|
|
searchInput: '', |
|
|
|
showModalDialog: false, |
|
|
|
showModalDialog: false, |
|
|
|
|
|
|
|
// modalValidation: {} as ValidationResult,
|
|
|
|
modalInfo: { title: '', loadItem: '', examples: [], prefix: '' }, |
|
|
|
modalInfo: { title: '', loadItem: '', examples: [], prefix: '' }, |
|
|
|
importSource: '', |
|
|
|
importSource: '', |
|
|
|
toasterMsg: '', |
|
|
|
toasterMsg: '' |
|
|
|
recentWorkspaces: [], |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [validationResult, setValidationResult] = useState<ValidationResult>({ valid: true, message: '' }) |
|
|
|
|
|
|
|
|
|
|
|
const loadingInitialState = { |
|
|
|
const loadingInitialState = { |
|
|
|
tooltip: '', |
|
|
|
tooltip: '', |
|
|
|
showModalDialog: false, |
|
|
|
showModalDialog: false, |
|
|
@ -186,6 +189,14 @@ export function Workspace() { |
|
|
|
setState((prevState) => { |
|
|
|
setState((prevState) => { |
|
|
|
return { ...prevState, importSource: startsWith + modalState.importSource } |
|
|
|
return { ...prevState, importSource: startsWith + modalState.importSource } |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
global.plugin.call('notification', 'alert', { id: 'homeTabAlert', message: 'The provided value is invalid!' }) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!startsWith.startsWith('https://') || !startsWith.startsWith('http://')) { |
|
|
|
|
|
|
|
global.plugin.call('notification', 'alert', { id: 'homeTabAlert', message: 'The provided value is invalid!' }) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
contentImport.import( |
|
|
|
contentImport.import( |
|
|
|
modalState.modalInfo.prefix + modalState.importSource, |
|
|
|
modalState.modalInfo.prefix + modalState.importSource, |
|
|
@ -219,6 +230,20 @@ export function Workspace() { |
|
|
|
showFullMessage(title, loadItem, examples, prefix) |
|
|
|
showFullMessage(title, loadItem, examples, prefix) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Validate the url fed into the modal for ipfs and https imports |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
const validateUrlForImport = (input: any) => { |
|
|
|
|
|
|
|
if ((input.trim().startsWith('ipfs://') && input.length > 7) || input.trim().startsWith('https://') || input.trim() !== '') { |
|
|
|
|
|
|
|
setValidationResult({ valid: true, message: '' }) |
|
|
|
|
|
|
|
return validationResult |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
global.plugin.call('notification', 'alert', { id: 'homeTabAlert', message: 'The provided value is invalid!' }) |
|
|
|
|
|
|
|
setValidationResult({ valid: false, message: 'The provided value is invalid!' }) |
|
|
|
|
|
|
|
return validationResult |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
let workspaceName = localStorage.getItem('currentWorkspace') |
|
|
|
let workspaceName = localStorage.getItem('currentWorkspace') |
|
|
|
if (!workspaceName && global.fs.browser.workspaces.length) { |
|
|
|
if (!workspaceName && global.fs.browser.workspaces.length) { |
|
|
@ -1454,7 +1479,8 @@ export function Workspace() { |
|
|
|
)} |
|
|
|
)} |
|
|
|
<ModalDialog id="homeTab" title={'Import from ' + modalState.modalInfo.title} |
|
|
|
<ModalDialog id="homeTab" title={'Import from ' + modalState.modalInfo.title} |
|
|
|
okLabel="Import" hide={!modalState.showModalDialog} handleHide={() => hideFullMessage()} |
|
|
|
okLabel="Import" hide={!modalState.showModalDialog} handleHide={() => hideFullMessage()} |
|
|
|
okFn={() => processLoading(modalState.modalInfo.title)}> |
|
|
|
okFn={() => processLoading(modalState.modalInfo.title)} validationFn={validateUrlForImport} |
|
|
|
|
|
|
|
> |
|
|
|
<div className="p-2 user-select-auto"> |
|
|
|
<div className="p-2 user-select-auto"> |
|
|
|
{modalState.modalInfo.loadItem !== '' && <span>Enter the {modalState.modalInfo.loadItem} you would like to load.</span>} |
|
|
|
{modalState.modalInfo.loadItem !== '' && <span>Enter the {modalState.modalInfo.loadItem} you would like to load.</span>} |
|
|
|
{modalState.modalInfo.examples.length !== 0 && ( |
|
|
|
{modalState.modalInfo.examples.length !== 0 && ( |
|
|
|