mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-03 03:55:26 +03:00
ec14f78ba3
- We don't actually utilise the history handling for Explore, as it's not a full screen modal and therefore don't need passing in previous routes before opening the iframe - Removed usage of `did-insert` livecycle hook and reverted to usage of `contructor` and `willDestroy` instead to add and remove message event listener
81 lines
2.8 KiB
JavaScript
81 lines
2.8 KiB
JavaScript
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default class ExploreIndexRoute extends AuthenticatedRoute {
|
|
@service explore;
|
|
@service store;
|
|
@service router;
|
|
@service feature;
|
|
|
|
beforeModel(transition) {
|
|
super.beforeModel(...arguments);
|
|
|
|
// Usage of query param to ensure that sites can be submitted across
|
|
// older versions of Ghost where the `connect` part lives in the
|
|
// explore route directly. By using the query param, we avoid causing
|
|
// a 404 and handle the redirect here.
|
|
if (transition.to?.queryParams?.new === 'true') {
|
|
this.explore.isIframeTransition = false;
|
|
return this.router.transitionTo('explore.connect');
|
|
}
|
|
|
|
// Ensure the explore window is set to open
|
|
if (transition.to?.localName === 'index') {
|
|
this.explore.isIframeTransition = true;
|
|
this.explore.openExploreWindow();
|
|
}
|
|
}
|
|
|
|
model() {
|
|
return this.store.findAll('integration');
|
|
}
|
|
|
|
@action
|
|
willTransition(transition) {
|
|
let isExploreTransition = false;
|
|
|
|
if (transition) {
|
|
let destinationUrl = (typeof transition.to === 'string')
|
|
? transition.to
|
|
: (transition.intent
|
|
? transition.intent.url
|
|
: '');
|
|
|
|
if (destinationUrl?.includes('/explore')) {
|
|
isExploreTransition = true;
|
|
this.explore.isIframeTransition = isExploreTransition;
|
|
|
|
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});
|
|
}
|
|
}
|
|
}
|
|
|
|
this.explore.toggleExploreWindow(isExploreTransition);
|
|
}
|
|
|
|
buildRouteInfoMetadata() {
|
|
return {
|
|
titleToken: 'Explore'
|
|
};
|
|
}
|
|
}
|