-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #879 from facebookresearch/make-submit-button-cust…
…omizable Added ability to customize `html-static-task-example` submit button
- Loading branch information
Showing
5 changed files
with
98 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.md | ||
**/build/* | ||
docs/web/static/python_api/* | ||
wrap_crowd_source.js |
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
33 changes: 33 additions & 0 deletions
33
mephisto/abstractions/blueprints/static_html_task/source/dev/hooks.js
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,33 @@ | ||
import { useState, useCallback, useEffect } from "react"; | ||
|
||
/** | ||
* This hook is to be used with events that are supposed to update state when they are consumed. | ||
* @param {string} configName | ||
* @param {any} defaultValue | ||
* @param {function} validatorFunction | ||
* @returns [any any] | ||
*/ | ||
export function useMephistoGlobalConfig( | ||
configName, | ||
defaultValue, | ||
validatorFunction | ||
) { | ||
const [configState, setConfigState] = useState(defaultValue ?? false); | ||
|
||
const handleEvent = useCallback( | ||
(eventValue) => { | ||
if (validatorFunction) { | ||
if (validatorFunction(eventValue)) { | ||
setConfigState(eventValue); | ||
} | ||
} else setConfigState(eventValue); | ||
}, | ||
[setConfigState] | ||
); | ||
|
||
useEffect(() => { | ||
window._MEPHISTO_CONFIG_.EVENT_EMITTER.on(configName, handleEvent); | ||
}, [setConfigState]); | ||
|
||
return [configState, setConfigState]; | ||
} |
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