Improved URL syncing between Admin and Explore (#15640)

no issue

Improve the route communication between Ghost Admin and Ghost Explore to
reflect route changes in the URL and correctly navigate to Explore sub
routes
This commit is contained in:
Aileen Booker 2022-10-21 11:48:18 +01:00 committed by GitHub
parent 50c92142d4
commit 6c9f8ec32d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 6 deletions

View File

@ -45,6 +45,6 @@ export default class GhExploreIframe extends Component {
}
_handleSiteDataUpdate(data) {
this.explore.siteData = data.siteData;
this.explore.siteData = data?.siteData ?? {};
}
}

View File

@ -20,6 +20,7 @@ export default class ExploreController extends Controller {
@action
closeConnect() {
if (this.explore.isIframeTransition) {
this.explore.sendRouteUpdate({path: '/explore'});
this.router.transitionTo('/explore');
} else {
this.router.transitionTo('/dashboard');
@ -43,7 +44,6 @@ export default class ExploreController extends Controller {
// to the submit page and fetch the required site data
setTimeout(() => {
this.explore.toggleExploreWindow(true);
this.router.transitionTo('explore');
}, 500);
} else {
// Ghost Explore URL to submit a new site

View File

@ -0,0 +1,10 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {inject as service} from '@ember/service';
export default class ExploreRoute extends AuthenticatedRoute {
@service store;
model() {
return this.store.findAll('integration');
}
}

View File

@ -2,7 +2,7 @@ import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
export default class ExploreRoute extends AuthenticatedRoute {
export default class ExploreIndexRoute extends AuthenticatedRoute {
@service explore;
@service store;
@service router;
@ -43,10 +43,27 @@ export default class ExploreRoute extends AuthenticatedRoute {
if (destinationUrl?.includes('/explore')) {
isExploreTransition = true;
this.explore.isIframeTransition = isExploreTransition;
// Send the updated route to the iframe
if (transition?.to?.params?.sub) {
this.explore.sendRouteUpdate({path: transition.to.params.sub});
if (destinationUrl?.includes('/explore/submit')) {
// only show the submit page if the site is already submitted
// and redirect to the connect page if not.
if (Object.keys(this?.explore?.siteData).length >= 1) {
this.controllerFor('explore').submitExploreSite();
} else {
transition.abort();
return this.router.transitionTo('explore.connect');
}
} else {
let path = destinationUrl.replace(/explore\//, '');
path = path === '/' ? '/explore/' : path;
if (destinationUrl?.includes('/explore/about')) {
window.open(`${this.explore.exploreUrl}about/`, '_blank').focus();
path = '/explore/';
}
// Send the updated route to the iframe
this.explore.sendRouteUpdate({path});
}
}
}