-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/git-integration
- Loading branch information
Showing
19 changed files
with
380 additions
and
56 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/components/project/CloneProject/CloneProject.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.root { | ||
color: var(--color-warning); | ||
display: flex; | ||
align-items: center; | ||
cursor: pointer; | ||
animation: blinker 500ms infinite alternate; | ||
|
||
.saveIcon { | ||
width: 1.2rem; | ||
height: 1.2rem; | ||
} | ||
} | ||
|
||
.form { | ||
margin-top: 2rem; | ||
} | ||
|
||
@keyframes blinker { | ||
from { | ||
opacity: 70%; | ||
} | ||
to { | ||
opacity: 100%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import AppIcon from '@/components/ui/icon'; | ||
import { baseProjectPath, useProject } from '@/hooks/projectV2.hooks'; | ||
import fileSystem from '@/lib/fs'; | ||
import { Button, Form, Input, message, Modal, Tooltip } from 'antd'; | ||
import cloneDeep from 'lodash.clonedeep'; | ||
import { FC, useState } from 'react'; | ||
import s from './CloneProject.module.scss'; | ||
|
||
const CloneProject: FC = () => { | ||
const [isSaveModalOpen, setIsSaveModalOpen] = useState(false); | ||
const [isSaving, setIsSaving] = useState(false); | ||
const { activeProject, projectFiles, createProject } = useProject(); | ||
|
||
const storeAsNewProject = async ({ name }: { name: string }) => { | ||
try { | ||
setIsSaving(true); | ||
|
||
const files = cloneDeep(projectFiles); | ||
const finalFiles = []; | ||
for (const file of files) { | ||
if (file.path.includes('.ide')) { | ||
continue; | ||
} | ||
if (file.type === 'file') { | ||
file.content = (await fileSystem.readFile(file.path)) as string; | ||
} | ||
file.path = file.path.replace(`${activeProject?.path as string}/`, ''); | ||
finalFiles.push(file); | ||
} | ||
if (finalFiles.length === 0) { | ||
message.error('No files to save'); | ||
return; | ||
} | ||
|
||
await createProject({ | ||
name: name, | ||
language: activeProject?.language ?? 'tact', | ||
template: 'import', | ||
file: null, | ||
defaultFiles: finalFiles, | ||
}); | ||
setIsSaveModalOpen(false); | ||
fileSystem.clearVirtualFiles(); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
message.error(error.message); | ||
return; | ||
} | ||
message.error('Failed to save a project'); | ||
} finally { | ||
setIsSaving(false); | ||
} | ||
}; | ||
|
||
if (!activeProject || activeProject.path !== `${baseProjectPath}/temp`) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<Tooltip | ||
title={`The current project is not saved permanently. Click here to save it.`} | ||
> | ||
<div | ||
className={s.root} | ||
onClick={() => { | ||
setIsSaveModalOpen(true); | ||
}} | ||
> | ||
<AppIcon className={s.saveIcon} name="Save" /> | ||
</div> | ||
</Tooltip> | ||
<Modal | ||
className={s.modal} | ||
open={isSaveModalOpen} | ||
onCancel={() => { | ||
setIsSaveModalOpen(false); | ||
}} | ||
footer={null} | ||
> | ||
<Form | ||
className={`${s.form} app-form`} | ||
layout="vertical" | ||
onFinish={storeAsNewProject} | ||
> | ||
<Form.Item | ||
name="name" | ||
rules={[ | ||
{ required: true, message: 'Please enter the project name' }, | ||
]} | ||
> | ||
<Input placeholder="Project name" /> | ||
</Form.Item> | ||
|
||
<Form.Item> | ||
<Button | ||
className={`${s.btnAction} w-100 ant-btn-primary-gradient item-center-align`} | ||
loading={isSaving} | ||
type="primary" | ||
htmlType="submit" | ||
> | ||
<AppIcon name="Save" /> Save | ||
</Button> | ||
</Form.Item> | ||
</Form> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export default CloneProject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './CloneProject'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as CloneProject } from './CloneProject'; | ||
export { default as DownloadProject } from './DownloadProject'; | ||
export { default as MigrateToUnifiedFS } from './MigrateToUnifiedFS'; | ||
export { default as NewProject } from './NewProject'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.