diff --git a/src/addons/calendar/pages/edit-event/edit-event.page.ts b/src/addons/calendar/pages/edit-event/edit-event.page.ts index 71ee3feb1..e78fe1adb 100644 --- a/src/addons/calendar/pages/edit-event/edit-event.page.ts +++ b/src/addons/calendar/pages/edit-event/edit-event.page.ts @@ -570,7 +570,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy { } } - if (this.svComponent?.isOn()) { + if (this.svComponent?.outletActivated) { // Empty form. this.hasOffline = false; this.form.reset(this.originalData); diff --git a/src/addons/calendar/pages/event/event.page.ts b/src/addons/calendar/pages/event/event.page.ts index eced37428..5a1597ca1 100644 --- a/src/addons/calendar/pages/event/event.page.ts +++ b/src/addons/calendar/pages/event/event.page.ts @@ -96,7 +96,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { this.notificationsEnabled = CoreLocalNotifications.instance.isAvailable(); this.siteHomeId = CoreSites.instance.getCurrentSiteHomeId(); this.currentSiteId = CoreSites.instance.getCurrentSiteId(); - this.isSplitViewOn = this.svComponent?.isOn(); + this.isSplitViewOn = this.svComponent?.outletActivated; // Check if site supports editing and deleting. No need to check allowed types, event.canedit already does it. this.canEdit = AddonCalendar.instance.canEditEventsInSite(); diff --git a/src/addons/calendar/pages/list/list.page.ts b/src/addons/calendar/pages/list/list.page.ts index 9eb4f0936..b45b49595 100644 --- a/src/addons/calendar/pages/list/list.page.ts +++ b/src/addons/calendar/pages/list/list.page.ts @@ -121,9 +121,9 @@ export class AddonCalendarListPage implements OnInit, OnDestroy { this.refreshEvents(true, false).finally(() => { // In tablet mode try to open the event (only if it's an online event). - if (this.splitviewCtrl?.isOn() && data.eventId > 0) { + if (this.splitviewCtrl?.outletActivated && data.eventId > 0) { this.gotoEvent(data.eventId); - } else if (this.splitviewCtrl?.isOn()) { + } else if (this.splitviewCtrl?.outletActivated) { // Discussion added, clear details page. this.emptySplitView(); } @@ -133,7 +133,7 @@ export class AddonCalendarListPage implements OnInit, OnDestroy { // Listen for new event discarded event. When it does, reload the data. this.discardedObserver = CoreEvents.on(AddonCalendarProvider.NEW_EVENT_DISCARDED_EVENT, () => { - if (this.splitviewCtrl?.isOn()) { + if (this.splitviewCtrl?.outletActivated) { // Discussion added, clear details page. this.emptySplitView(); } @@ -155,7 +155,8 @@ export class AddonCalendarListPage implements OnInit, OnDestroy { this.eventsLoaded = false; this.refreshEvents(); - if (this.splitviewCtrl?.isOn() && this.eventId && data && data.deleted && data.deleted.indexOf(this.eventId) != -1) { + if (this.splitviewCtrl?.outletActivated && + this.eventId && data && data.deleted && data.deleted.indexOf(this.eventId) != -1) { // Current selected event was deleted. Clear details. this.emptySplitView(); } @@ -168,7 +169,8 @@ export class AddonCalendarListPage implements OnInit, OnDestroy { this.refreshEvents(); } - if (this.splitviewCtrl?.isOn() && this.eventId && data && data.deleted && data.deleted.indexOf(this.eventId) != -1) { + if (this.splitviewCtrl?.outletActivated && + this.eventId && data && data.deleted && data.deleted.indexOf(this.eventId) != -1) { // Current selected event was deleted. Clear details. this.emptySplitView(); } @@ -185,7 +187,7 @@ export class AddonCalendarListPage implements OnInit, OnDestroy { this.hasOffline = true; } else { // Event deleted, clear the details if needed and refresh the view. - if (this.splitviewCtrl?.isOn()) { + if (this.splitviewCtrl?.outletActivated) { this.emptySplitView(); } @@ -255,7 +257,7 @@ export class AddonCalendarListPage implements OnInit, OnDestroy { await this.fetchData(false, true, false); - if (!this.eventId && this.splitviewCtrl?.isOn() && this.events.length > 0) { + if (!this.eventId && this.splitviewCtrl?.outletActivated && this.events.length > 0) { // Take first online event and load it. If no online event, load the first offline. if (this.onlineEvents[0]) { this.gotoEvent(this.onlineEvents[0].id); diff --git a/src/addons/mod/forum/pages/discussion/discussion.page.ts b/src/addons/mod/forum/pages/discussion/discussion.page.ts index 16cf9a311..3f04001d3 100644 --- a/src/addons/mod/forum/pages/discussion/discussion.page.ts +++ b/src/addons/mod/forum/pages/discussion/discussion.page.ts @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, OnDestroy, ViewChild, OnInit, AfterViewInit, ElementRef } from '@angular/core'; +import { Component, OnDestroy, ViewChild, OnInit, AfterViewInit, ElementRef, Optional } from '@angular/core'; +import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreUser } from '@features/user/services/user'; import { CanLeave } from '@guards/can-leave'; @@ -106,7 +107,10 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes protected ratingSyncObserver?: CoreEventObserver; protected changeDiscObserver?: CoreEventObserver; - constructor(protected elementRef: ElementRef) {} + constructor( + @Optional() protected splitView: CoreSplitViewComponent, + protected elementRef: ElementRef, + ) {} get isMobile(): boolean { return CoreScreen.instance.isMobile; @@ -216,12 +220,11 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes if (typeof data.deleted != 'undefined' && data.deleted) { if (!data.post?.parentid) { - // @todo - // if (this.svComponent && this.svComponent.isOn()) { - // this.svComponent.emptyDetails(); - // } else { - // this.navCtrl.pop(); - // } + if (this.splitView?.outletActivated) { + CoreNavigator.instance.navigate('../'); + } else { + CoreNavigator.instance.back(); + } } else { this.discussionLoaded = false; this.refreshPosts(); diff --git a/src/addons/mod/forum/pages/new-discussion/new-discussion.page.ts b/src/addons/mod/forum/pages/new-discussion/new-discussion.page.ts index 35708874e..e813bb990 100644 --- a/src/addons/mod/forum/pages/new-discussion/new-discussion.page.ts +++ b/src/addons/mod/forum/pages/new-discussion/new-discussion.page.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, OnDestroy, ViewChild, ElementRef, OnInit } from '@angular/core'; +import { Component, OnDestroy, ViewChild, ElementRef, OnInit, Optional } from '@angular/core'; import { FileEntry } from '@ionic-native/file/ngx'; import { FormControl } from '@angular/forms'; import { CoreEvents, CoreEventObserver } from '@singletons/events'; @@ -38,7 +38,7 @@ import { IonRefresher } from '@ionic/angular'; import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreTextUtils } from '@services/utils/text'; import { CanLeave } from '@guards/can-leave'; -import { CoreScreen } from '@services/screen'; +import { CoreSplitViewComponent } from '@components/split-view/split-view'; type NewDiscussionData = { subject: string; @@ -96,6 +96,8 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea protected originalData?: Partial; protected forceLeave = false; + constructor(@Optional() protected splitView: CoreSplitViewComponent) {} + /** * Component being initialized. */ @@ -433,9 +435,7 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea CoreSites.instance.getCurrentSiteId(), ); - if (CoreScreen.instance.isMobile) { - CoreNavigator.instance.back(); - } else { + if (this.splitView?.outletActivated) { // Empty form. this.hasOffline = false; this.newDiscussion.subject = ''; @@ -444,6 +444,8 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea this.newDiscussion.postToAllGroups = false; this.messageEditor.clearText(); this.originalData = CoreUtils.instance.clone(this.newDiscussion); + } else { + CoreNavigator.instance.back(); } } diff --git a/src/core/components/split-view/split-view.ts b/src/core/components/split-view/split-view.ts index 153817f65..27af0425a 100644 --- a/src/core/components/split-view/split-view.ts +++ b/src/core/components/split-view/split-view.ts @@ -46,6 +46,10 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy { return this.outletRouteSubject.value; } + get outletActivated(): boolean { + return this.contentOutlet.isActivated; + } + get outletRouteObservable(): Observable { return this.outletRouteSubject.asObservable(); } @@ -118,13 +122,4 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy { return CoreSplitViewMode.MenuAndContent; } - /** - * Check if both panels are shown. It depends on screen width. - * - * @return If split view is enabled. - */ - isOn(): boolean { - return this.contentOutlet.isActivated; - } - }