From ee47f88830ea7d27edd314d5046ad3798ff2e9da Mon Sep 17 00:00:00 2001 From: David Disu Date: Mon, 12 Sep 2022 19:06:13 +0100 Subject: [PATCH] Add track workspace as new git repo --- .../workspace/src/lib/actions/workspace.ts | 1 + .../workspace/src/lib/contexts/index.ts | 2 +- .../src/lib/providers/FileSystemProvider.tsx | 4 ++-- .../workspace/src/lib/remix-ui-workspace.tsx | 22 ++++++++++++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 3ef203644e..083d9ce67c 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -53,6 +53,7 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa await plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) await plugin.setWorkspaces(await getWorkspaces()) await plugin.workspaceCreated(workspaceName) + if (isGitRepo) await plugin.call('dGitProvider', 'init') if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName) cb && cb(null, workspaceName) }).catch((error) => { diff --git a/libs/remix-ui/workspace/src/lib/contexts/index.ts b/libs/remix-ui/workspace/src/lib/contexts/index.ts index 1724ca7c29..27f46391c4 100644 --- a/libs/remix-ui/workspace/src/lib/contexts/index.ts +++ b/libs/remix-ui/workspace/src/lib/contexts/index.ts @@ -9,7 +9,7 @@ export const FileSystemContext = createContext<{ dispatchFetchDirectory:(path: string) => Promise, dispatchAddInputField:(path: string, type: 'file' | 'folder') => Promise, dispatchRemoveInputField:(path: string) => Promise, - dispatchCreateWorkspace: (workspaceName: string, workspaceTemplateName: string) => Promise, + dispatchCreateWorkspace: (workspaceName: string, workspaceTemplateName: string, initGitRepo?: boolean) => Promise, toast: (toasterMsg: string) => void, dispatchFetchWorkspaceDirectory: (path: string) => Promise, dispatchSwitchToWorkspace: (name: string) => Promise, diff --git a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx index 2d4010ca31..736811af00 100644 --- a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx +++ b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx @@ -45,8 +45,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => { await removeInputField(path) } - const dispatchCreateWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate) => { - await createWorkspace(workspaceName, workspaceTemplateName) + const dispatchCreateWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, initGitRepo?: boolean) => { + await createWorkspace(workspaceName, workspaceTemplateName, null, null, initGitRepo) } const dispatchFetchWorkspaceDirectory = async (path: string) => { diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index 91aa2c63ff..bdb9b9d1a3 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -19,6 +19,7 @@ export function Workspace () { const workspaceCreateInput = useRef() const workspaceCreateTemplateInput = useRef() const cloneUrlRef = useRef() + const initGitRepoRef = useRef() useEffect(() => { setCurrentWorkspace(localStorage.getItem('currentWorkspace') ? localStorage.getItem('currentWorkspace') : '') @@ -103,9 +104,10 @@ export function Workspace () { const workspaceName = workspaceCreateInput.current.value // @ts-ignore: Object is possibly 'null'. const workspaceTemplateName = workspaceCreateTemplateInput.current.value || 'remixDefault' + const initGitRepo = initGitRepoRef.current.checked try { - await global.dispatchCreateWorkspace(workspaceName, workspaceTemplateName) + await global.dispatchCreateWorkspace(workspaceName, workspaceTemplateName, initGitRepo) } catch (e) { global.modal('Create Workspace', e.message, 'OK', () => {}, '') console.error(e) @@ -168,6 +170,24 @@ export function Workspace () { +
+ {}} + /> + +
) }