-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generator): prompt for unsaved JSON when exporting JSON (#184)
- Loading branch information
1 parent
cf44e9a
commit ef77401
Showing
5 changed files
with
100 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 保存json通用hook | ||
* @Author: jiangxiaowei | ||
* @Date: 2022-04-02 15:34:29 | ||
* @Last Modified by: jiangxiaowei | ||
* @Last Modified time: 2022-04-02 15:34:29 | ||
*/ | ||
import { IsSavedAtom, schemaAtom, versionAtom } from '@generator/store' | ||
import { useSetRecoilState } from 'recoil' | ||
import { useCallback } from 'react' | ||
import { message } from 'antd' | ||
import type { UnitedSchema } from '@jdfed/utils' | ||
|
||
type SaveJson = (json: UnitedSchema) => void | ||
|
||
const useSaveJson = (): SaveJson => { | ||
const setUnitedSchema = useSetRecoilState(schemaAtom) | ||
const setIsSaved = useSetRecoilState(IsSavedAtom) | ||
const setVersion = useSetRecoilState(versionAtom) | ||
const saveJson = useCallback<SaveJson>( | ||
(json) => { | ||
setUnitedSchema(json) | ||
setVersion((number) => number + 1) | ||
setIsSaved(true) | ||
message.success('保存成功,真棒👍🏻', 2) | ||
}, | ||
[setIsSaved, setUnitedSchema, setVersion] | ||
) | ||
return saveJson | ||
} | ||
|
||
export default useSaveJson |
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