-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fork project link * add forking to state * fork project with url param * check projectId not projectName
- Loading branch information
Showing
13 changed files
with
114 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import React from 'react' | ||
import { useRefEditorState } from './store/store-hook' | ||
import { persistentModelFromEditorModel } from './store/editor-state' | ||
import { useDispatch } from './store/dispatch-context' | ||
import { setForking } from './actions/action-creators' | ||
|
||
export function useTriggerForkProject(): () => void { | ||
const dispatch = useDispatch() | ||
|
||
const storeRef = useRefEditorState((store) => store) | ||
return React.useCallback(async () => { | ||
dispatch([setForking(true)]) | ||
const store = storeRef.current | ||
store.persistence.fork(store.editor.projectName, persistentModelFromEditorModel(store.editor)) | ||
}, [storeRef]) | ||
}, [storeRef, dispatch]) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react' | ||
import { useTriggerForkProject } from './persistence-hooks' | ||
import { Substores, useEditorState } from './store/store-hook' | ||
|
||
export const ForkSearchParamKey = 'fork' | ||
|
||
export const ProjectForkFlow = React.memo(() => { | ||
const searchParams = new URLSearchParams(window.location.search) | ||
const shouldFork = searchParams.get(ForkSearchParamKey) === 'true' | ||
|
||
const projectId = useEditorState( | ||
Substores.restOfEditor, | ||
(store) => store.editor.id, | ||
'ProjectForkFlow projectId', | ||
) | ||
|
||
const triggerForkProject = useTriggerForkProject() | ||
|
||
React.useEffect(() => { | ||
if (shouldFork && projectId != null) { | ||
triggerForkProject() | ||
} | ||
}, [shouldFork, triggerForkProject, projectId]) | ||
|
||
return null | ||
}) | ||
|
||
ProjectForkFlow.displayName = 'ProjectForkFlow' |
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