|
|
@ -1,5 +1,6 @@ |
|
|
|
import React, { useState, useEffect, useRef, useContext } from 'react' // eslint-disable-line
|
|
|
|
import React, { useState, useEffect, useRef, useContext } from 'react' // eslint-disable-line
|
|
|
|
import { Dropdown } from 'react-bootstrap' |
|
|
|
import { Dropdown } from 'react-bootstrap' |
|
|
|
|
|
|
|
import { CustomMenu, CustomToggle } from './components/custom-dropdown' |
|
|
|
import { FileExplorer } from './components/file-explorer' // eslint-disable-line
|
|
|
|
import { FileExplorer } from './components/file-explorer' // eslint-disable-line
|
|
|
|
import { FileSystemContext } from './contexts' |
|
|
|
import { FileSystemContext } from './contexts' |
|
|
|
import './css/remix-ui-workspace.css' |
|
|
|
import './css/remix-ui-workspace.css' |
|
|
@ -10,8 +11,7 @@ export function Workspace () { |
|
|
|
const LOCALHOST = ' - connect to localhost - ' |
|
|
|
const LOCALHOST = ' - connect to localhost - ' |
|
|
|
const NO_WORKSPACE = ' - none - ' |
|
|
|
const NO_WORKSPACE = ' - none - ' |
|
|
|
const [currentWorkspace, setCurrentWorkspace] = useState<string>(NO_WORKSPACE) |
|
|
|
const [currentWorkspace, setCurrentWorkspace] = useState<string>(NO_WORKSPACE) |
|
|
|
// const [toggleSelectWorkspace, setToggleSelectWorkspace] = useState<string | JSX.Element>("")
|
|
|
|
const [selectedWorkspace, setSelectedWorkspace] = useState<{ name: string, isGitRepo: boolean}>(null) |
|
|
|
const [dropdownWorkspacesList, setDropdownWorkspacesList] = useState<{string: string | JSX.Element}[]>([]) |
|
|
|
|
|
|
|
const global = useContext(FileSystemContext) |
|
|
|
const global = useContext(FileSystemContext) |
|
|
|
const workspaceRenameInput = useRef() |
|
|
|
const workspaceRenameInput = useRef() |
|
|
|
const workspaceCreateInput = useRef() |
|
|
|
const workspaceCreateInput = useRef() |
|
|
@ -34,19 +34,21 @@ export function Workspace () { |
|
|
|
}, [global.fs.browser.currentWorkspace, global.fs.localhost.sharedFolder, global.fs.mode]) |
|
|
|
}, [global.fs.browser.currentWorkspace, global.fs.localhost.sharedFolder, global.fs.mode]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (global.fs.browser.currentWorkspace && !global.fs.browser.workspaces.includes(global.fs.browser.currentWorkspace)) { |
|
|
|
if (global.fs.browser.currentWorkspace && !global.fs.browser.workspaces.find(({ name }) => name === global.fs.browser.currentWorkspace)) { |
|
|
|
if (global.fs.browser.workspaces.length > 0) { |
|
|
|
if (global.fs.browser.workspaces.length > 0) { |
|
|
|
switchWorkspace(global.fs.browser.workspaces[global.fs.browser.workspaces.length - 1]) |
|
|
|
switchWorkspace(global.fs.browser.workspaces[global.fs.browser.workspaces.length - 1].name) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
switchWorkspace(NO_WORKSPACE) |
|
|
|
switchWorkspace(NO_WORKSPACE) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const dropdownList = global.fs.browser.workspaces.map((workspace) => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
setDropdownWorkspacesList(dropdownList) |
|
|
|
|
|
|
|
}, [global.fs.browser.workspaces]) |
|
|
|
}, [global.fs.browser.workspaces]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
const workspace = global.fs.browser.workspaces.find(workspace => workspace.name === currentWorkspace) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setSelectedWorkspace(workspace) |
|
|
|
|
|
|
|
}, [currentWorkspace]) |
|
|
|
|
|
|
|
|
|
|
|
const renameCurrentWorkspace = () => { |
|
|
|
const renameCurrentWorkspace = () => { |
|
|
|
global.modal('Rename Current Workspace', renameModalMessage(), 'OK', onFinishRenameWorkspace, '') |
|
|
|
global.modal('Rename Current Workspace', renameModalMessage(), 'OK', onFinishRenameWorkspace, '') |
|
|
|
} |
|
|
|
} |
|
|
@ -255,34 +257,34 @@ export function Workspace () { |
|
|
|
title='Clone Git Repository'> |
|
|
|
title='Clone Git Repository'> |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
{/* <Dropdown |
|
|
|
<Dropdown id="workspacesSelect" data-id="workspacesSelect"> |
|
|
|
onSelect={value => { |
|
|
|
<Dropdown.Toggle as={CustomToggle} id="dropdown-custom-components" className="btn btn-light btn-block w-100 d-inline-block border border-dark form-control" icon={selectedWorkspace && selectedWorkspace.isGitRepo ? 'far fa-code-branch' : null}> |
|
|
|
const { code, title } = [{ code: 'NG', title: 'Nigeria' }].find(({ code }) => value === code) |
|
|
|
{ selectedWorkspace ? selectedWorkspace.name : currentWorkspace === LOCALHOST ? 'localhost' : NO_WORKSPACE } |
|
|
|
|
|
|
|
|
|
|
|
setSelectedCountry(value) |
|
|
|
|
|
|
|
setToggleContents(<><i className="fas fa-code-branch"></i> {title}</>) |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<Dropdown.Toggle variant="secondary" id="dropdown-flags" className="text-left" style={{ width: 300 }}> |
|
|
|
|
|
|
|
{toggleContents} |
|
|
|
|
|
|
|
</Dropdown.Toggle> |
|
|
|
</Dropdown.Toggle> |
|
|
|
|
|
|
|
|
|
|
|
<Dropdown.Menu> |
|
|
|
<Dropdown.Menu as={CustomMenu} className='w-100 custom-dropdown-items' > |
|
|
|
{[{ code: 'NG', title: 'Nigeria' }].map(({ code, title }) => ( |
|
|
|
|
|
|
|
<Dropdown.Item key={code} eventKey={code}><i className="fas fa-code-branch"></i> {title}</Dropdown.Item> |
|
|
|
|
|
|
|
))} |
|
|
|
|
|
|
|
</Dropdown.Menu> |
|
|
|
|
|
|
|
</Dropdown> */} |
|
|
|
|
|
|
|
<select id="workspacesSelect" value={currentWorkspace} data-id="workspacesSelect" onChange={(e) => switchWorkspace(e.target.value)} className="form-select"> |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
global.fs.browser.workspaces |
|
|
|
global.fs.browser.workspaces.map(({ name, isGitRepo }, index) => ( |
|
|
|
.map((folder, index) => { |
|
|
|
<Dropdown.Item |
|
|
|
return <option key={index} value={folder}>{folder}</option> |
|
|
|
key={index} |
|
|
|
}) |
|
|
|
onClick={() => { |
|
|
|
|
|
|
|
switchWorkspace(name) |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{ isGitRepo ?
|
|
|
|
|
|
|
|
<div className='d-flex justify-content-between'> |
|
|
|
|
|
|
|
<span>{ currentWorkspace === name ? <span>✓ { name } </span> : <span className="pl-3">{ name }</span> }</span> |
|
|
|
|
|
|
|
<i className='fas fa-code-branch pt-1'></i> |
|
|
|
|
|
|
|
</div> :
|
|
|
|
|
|
|
|
<span>{ currentWorkspace === name ? <span>✓ { name } </span> : <span className="pl-3">{ name }</span> }</span> |
|
|
|
} |
|
|
|
} |
|
|
|
<option value={LOCALHOST}>{currentWorkspace === LOCALHOST ? 'localhost' : LOCALHOST}</option> |
|
|
|
</Dropdown.Item> |
|
|
|
{ global.fs.browser.workspaces.length <= 0 && <option value={NO_WORKSPACE}>{NO_WORKSPACE}</option> } |
|
|
|
)) |
|
|
|
</select> |
|
|
|
} |
|
|
|
|
|
|
|
<Dropdown.Item onClick={() => { switchWorkspace(LOCALHOST) }}>{currentWorkspace === LOCALHOST ? <span>✓ localhost </span> : <span className="pl-3"> { LOCALHOST } </span>}</Dropdown.Item> |
|
|
|
|
|
|
|
{ ((global.fs.browser.workspaces.length <= 0) || currentWorkspace === NO_WORKSPACE) && <Dropdown.Item onClick={() => { switchWorkspace(NO_WORKSPACE) }}>{ <span className="pl-3">NO_WORKSPACE</span> }</Dropdown.Item> } |
|
|
|
|
|
|
|
</Dropdown.Menu> |
|
|
|
|
|
|
|
</Dropdown> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</header> |
|
|
|
</header> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|