Skip to content

Commit

Permalink
Improved URL syncing between Admin and Explore (#15640)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aileen authored Oct 21, 2022
1 parent 50c9214 commit 6c9f8ec
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ghost/admin/app/components/gh-explore-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export default class GhExploreIframe extends Component {
}

_handleSiteDataUpdate(data) {
this.explore.siteData = data.siteData;
this.explore.siteData = data?.siteData ?? {};
}
}
2 changes: 1 addition & 1 deletion ghost/admin/app/controllers/explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions ghost/admin/app/routes/explore.js
Original file line number Diff line number Diff line change
@@ -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');
}
}
25 changes: 21 additions & 4 deletions ghost/admin/app/routes/explore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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});
}
}
}
Expand Down

0 comments on commit 6c9f8ec

Please sign in to comment.