-
Notifications
You must be signed in to change notification settings - Fork 1
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 #835 from CodeForAfrica/bugfix/url-navigation
@civicsignalblog /Fix navigation URL
- Loading branch information
Showing
8 changed files
with
156 additions
and
21 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 +1 @@ | ||
FROM codeforafrica/codeforafrica-ui:0.1.7 | ||
FROM codeforafrica/codeforafrica-ui:0.1.8 |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { subscribe, unsubscribe, ready } from "@payloadcms/live-preview"; | ||
import { useCallback, useEffect, useState, useRef } from "react"; | ||
|
||
export const useLivePreview = (props) => { | ||
const { depth = 0, initialData, serverURL } = props; | ||
const [data, setData] = useState(initialData); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const hasSentReadyMessage = useRef(false); | ||
|
||
const onChange = useCallback((mergedData) => { | ||
// When a change is made, the `onChange` callback will be called with the merged data | ||
// Set this merged data into state so that React will re-render the UI | ||
setData(mergedData); | ||
setIsLoading(false); | ||
}, []); | ||
|
||
useEffect(() => { | ||
// Listen for `window.postMessage` events from the Admin panel | ||
// When a change is made, the `onChange` callback will be called with the merged data | ||
const subscription = subscribe({ | ||
callback: onChange, | ||
depth, | ||
initialData, | ||
serverURL, | ||
}); | ||
|
||
// Once subscribed, send a `ready` message back up to the Admin panel | ||
// This will indicate that the front-end is ready to receive messages | ||
if (!hasSentReadyMessage.current) { | ||
hasSentReadyMessage.current = true; | ||
|
||
ready({ | ||
serverURL, | ||
}); | ||
} | ||
|
||
// When the component unmounts, unsubscribe from the `window.postMessage` events | ||
return () => { | ||
unsubscribe(subscription); | ||
}; | ||
}, [serverURL, onChange, depth, initialData, hasSentReadyMessage]); | ||
|
||
useEffect(() => { | ||
setData(initialData); | ||
}, [initialData]); | ||
|
||
return { | ||
data, | ||
isLoading, | ||
}; | ||
}; | ||
|
||
export default useLivePreview; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.