mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-03-13 19:42:33 +00:00
fix navigation issue
This commit is contained in:
parent
1560f25f1b
commit
2ba7341e2b
@ -17,7 +17,6 @@ export const AppViewer = React.forwardRef(({ app , hide}, iframeRef) => {
|
||||
const { document, window: frameWindow } = useFrame();
|
||||
const {path, history, changeCurrentIndex} = useQortalMessageListener(frameWindow, iframeRef, app?.tabId)
|
||||
const [url, setUrl] = useState('')
|
||||
console.log('historyreact', history)
|
||||
|
||||
useEffect(()=> {
|
||||
setUrl(`${getBaseApiReact()}/render/${app?.service}/${app?.name}${app?.path != null ? `/${app?.path}` : ''}?theme=dark&identifier=${(app?.identifier != null && app?.identifier != 'null') ? app?.identifier : ''}`)
|
||||
@ -53,16 +52,14 @@ export const AppViewer = React.forwardRef(({ app , hide}, iframeRef) => {
|
||||
|
||||
// Signal non-manual navigation
|
||||
iframeRef.current.contentWindow.postMessage(
|
||||
{ action: 'PERFORMING_NON_MANUAL' }, '*'
|
||||
{ action: 'PERFORMING_NON_MANUAL', currentIndex: previousPageIndex}, '*'
|
||||
);
|
||||
console.log('previousPageIndex', previousPageIndex)
|
||||
// Update the current index locally
|
||||
changeCurrentIndex(previousPageIndex);
|
||||
|
||||
// Create a navigation promise with a 200ms timeout
|
||||
const navigationPromise = new Promise((resolve, reject) => {
|
||||
function handleNavigationSuccess(event) {
|
||||
console.log('listeninghandlenav', event)
|
||||
if (event.data?.action === 'NAVIGATION_SUCCESS' && event.data.path === previousPath) {
|
||||
frameWindow.removeEventListener('message', handleNavigationSuccess);
|
||||
resolve();
|
||||
@ -86,12 +83,10 @@ export const AppViewer = React.forwardRef(({ app , hide}, iframeRef) => {
|
||||
// Execute navigation promise and handle timeout fallback
|
||||
try {
|
||||
await navigationPromise;
|
||||
console.log('Navigation succeeded within 200ms.');
|
||||
} catch (error) {
|
||||
iframeRef.current.contentWindow.postMessage(
|
||||
{ action: 'PERFORMING_NON_MANUAL' }, '*'
|
||||
);
|
||||
setUrl(`${getBaseApiReact()}/render/${app?.service}/${app?.name}${app?.previousPath != null ? previousPath : ''}?theme=dark&identifier=${(app?.identifier != null && app?.identifier != 'null') ? app?.identifier : ''}&time=${new Date().getMilliseconds()}&isManualNavigation=false`)
|
||||
|
||||
|
||||
setUrl(`${getBaseApiReact()}/render/${app?.service}/${app?.name}${previousPath != null ? previousPath : ''}?theme=dark&identifier=${(app?.identifier != null && app?.identifier != 'null') ? app?.identifier : ''}&time=${new Date().getMilliseconds()}&isManualNavigation=false`)
|
||||
// iframeRef.current.contentWindow.location.href = previousPath; // Fallback URL update
|
||||
}
|
||||
} else {
|
||||
@ -119,7 +114,6 @@ export const AppViewer = React.forwardRef(({ app , hide}, iframeRef) => {
|
||||
|
||||
|
||||
if (iframeRef.current && iframeRef.current.contentWindow) {
|
||||
console.log('iframeRef.contentWindow', iframeRef.current.contentWindow);
|
||||
iframeRef.current.contentWindow.postMessage(
|
||||
{ action: 'NAVIGATE_FORWARD'},
|
||||
'*'
|
||||
|
@ -349,6 +349,7 @@ isDOMContentLoaded: false
|
||||
})
|
||||
}, [])
|
||||
|
||||
|
||||
const resetHistory = useCallback(()=> {
|
||||
setHistory({
|
||||
customQDNHistoryPaths: [],
|
||||
@ -361,7 +362,6 @@ isDOMContentLoaded: false
|
||||
useEffect(() => {
|
||||
|
||||
const listener = async (event) => {
|
||||
console.log('eventreactt', event)
|
||||
// event.preventDefault(); // Prevent default behavior
|
||||
// event.stopImmediatePropagation(); // Stop other listeners from firing
|
||||
|
||||
@ -426,15 +426,13 @@ isDOMContentLoaded: false
|
||||
setHistory((prev)=> {
|
||||
const copyPrev = {...prev}
|
||||
if((copyPrev?.customQDNHistoryPaths || []).at(-1) === (event?.data?.payload?.customQDNHistoryPaths || []).at(-1)) {
|
||||
console.log('customQDNHistoryPaths.length', prev?.customQDNHistoryPaths.length)
|
||||
return {
|
||||
...prev,
|
||||
currentIndex: prev.customQDNHistoryPaths.length - 1 === -1 ? 0 : prev.customQDNHistoryPaths.length - 1
|
||||
}
|
||||
}
|
||||
const copyHistory = {...prev}
|
||||
const paths = [...(copyHistory?.customQDNHistoryPaths || []), ...(event?.data?.payload?.customQDNHistoryPaths || [])]
|
||||
console.log('paths', paths)
|
||||
const paths = [...(copyHistory?.customQDNHistoryPaths.slice(0, copyHistory.currentIndex + 1) || []), ...(event?.data?.payload?.customQDNHistoryPaths || [])]
|
||||
return {
|
||||
...prev,
|
||||
customQDNHistoryPaths: paths,
|
||||
|
Loading…
x
Reference in New Issue
Block a user