From 0d5e54371340ee6621b734ae4eab81e155c684d0 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 29 Apr 2021 09:39:40 +0200 Subject: [PATCH] MOBILE-3742 links: Support choose site when clicking links --- .../choose-site-modal/choose-site-modal.html} | 10 ++--- .../choose-site-modal/choose-site-modal.ts} | 42 +++++++------------ .../components.module.ts} | 21 ++++------ .../contentlinks/contentlinks.module.ts | 8 +++- .../services/contentlinks-helper.ts | 13 +++++- 5 files changed, 45 insertions(+), 49 deletions(-) rename src/core/features/contentlinks/{pages/choose-site/choose-site.html => components/choose-site-modal/choose-site-modal.html} (84%) rename src/core/features/contentlinks/{pages/choose-site/choose-site.ts => components/choose-site-modal/choose-site-modal.ts} (78%) rename src/core/features/contentlinks/{pages/choose-site/choose-site.module.ts => components/components.module.ts} (68%) diff --git a/src/core/features/contentlinks/pages/choose-site/choose-site.html b/src/core/features/contentlinks/components/choose-site-modal/choose-site-modal.html similarity index 84% rename from src/core/features/contentlinks/pages/choose-site/choose-site.html rename to src/core/features/contentlinks/components/choose-site-modal/choose-site-modal.html index c68f92535..c9e2a7de9 100644 --- a/src/core/features/contentlinks/pages/choose-site/choose-site.html +++ b/src/core/features/contentlinks/components/choose-site-modal/choose-site-modal.html @@ -4,6 +4,11 @@ {{ 'core.contentlinks.chooseaccount' | translate }} + + + + + @@ -27,11 +32,6 @@

{{site.siteUrl}}

- - - {{ 'core.login.cancel' | translate }} - -
diff --git a/src/core/features/contentlinks/pages/choose-site/choose-site.ts b/src/core/features/contentlinks/components/choose-site-modal/choose-site-modal.ts similarity index 78% rename from src/core/features/contentlinks/pages/choose-site/choose-site.ts rename to src/core/features/contentlinks/components/choose-site-modal/choose-site-modal.ts index 29c38d202..a71ea2f32 100644 --- a/src/core/features/contentlinks/pages/choose-site/choose-site.ts +++ b/src/core/features/contentlinks/components/choose-site-modal/choose-site-modal.ts @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, OnInit } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { CoreSiteBasicInfo, CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { Translate } from '@singletons'; +import { ModalController, Translate } from '@singletons'; import { CoreContentLinksAction } from '../../services/contentlinks-delegate'; import { CoreContentLinksHelper } from '../../services/contentlinks-helper'; import { CoreError } from '@classes/errors/error'; @@ -27,12 +27,13 @@ import { CoreNavigator } from '@services/navigator'; * @todo Include routing and testing. */ @Component({ - selector: 'page-core-content-links-choose-site', - templateUrl: 'choose-site.html', + selector: 'core-content-links-choose-site-modal', + templateUrl: 'choose-site-modal.html', }) -export class CoreContentLinksChooseSitePage implements OnInit { +export class CoreContentLinksChooseSiteModalComponent implements OnInit { + + @Input() url!: string; - url!: string; sites: CoreSiteBasicInfo[] = []; loaded = false; protected action?: CoreContentLinksAction; @@ -42,12 +43,10 @@ export class CoreContentLinksChooseSitePage implements OnInit { * Component being initialized. */ async ngOnInit(): Promise { - const url = CoreNavigator.getRouteParam('url'); - if (!url) { - return this.leaveView(); + if (!this.url) { + return this.closeModal(); } - this.url = url; let siteIds: string[] | undefined = []; try { @@ -75,25 +74,20 @@ export class CoreContentLinksChooseSitePage implements OnInit { this.sites = await CoreSites.getSites(siteIds); } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'core.contentlinks.errornosites', true); - this.leaveView(); + this.closeModal(); } this.loaded = true; } - /** - * Cancel. - */ - cancel(): void { - this.leaveView(); - } - /** * Perform the action on a certain site. * * @param siteId Site ID. */ - siteClicked(siteId: string): void { + async siteClicked(siteId: string): Promise { + await ModalController.dismiss(); + if (this.isRootURL) { CoreNavigator.navigateToSiteHome({ siteId }); } else if (this.action) { @@ -102,14 +96,10 @@ export class CoreContentLinksChooseSitePage implements OnInit { } /** - * Cancel and leave the view. + * Close the modal. */ - protected async leaveView(): Promise { - try { - await CoreSites.logout(); - } finally { - await CoreNavigator.navigate('/login/sites', { reset: true }); - } + closeModal(): void { + ModalController.dismiss(); } } diff --git a/src/core/features/contentlinks/pages/choose-site/choose-site.module.ts b/src/core/features/contentlinks/components/components.module.ts similarity index 68% rename from src/core/features/contentlinks/pages/choose-site/choose-site.module.ts rename to src/core/features/contentlinks/components/components.module.ts index 51b3e16a5..99ac28edd 100644 --- a/src/core/features/contentlinks/pages/choose-site/choose-site.module.ts +++ b/src/core/features/contentlinks/components/components.module.ts @@ -12,26 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; - import { CoreSharedModule } from '@/core/shared.module'; -import { CoreContentLinksChooseSitePage } from './choose-site'; - -const routes: Routes = [ - { - path: '', - component: CoreContentLinksChooseSitePage, - }, -]; +import { NgModule } from '@angular/core'; +import { CoreContentLinksChooseSiteModalComponent } from './choose-site-modal/choose-site-modal'; @NgModule({ declarations: [ - CoreContentLinksChooseSitePage, + CoreContentLinksChooseSiteModalComponent, ], imports: [ - RouterModule.forChild(routes), CoreSharedModule, ], + exports: [ + CoreContentLinksChooseSiteModalComponent, + ], }) -export class CoreContentLinksChooseSitePageModule {} +export class CoreContentLinksComponentsModule {} diff --git a/src/core/features/contentlinks/contentlinks.module.ts b/src/core/features/contentlinks/contentlinks.module.ts index 127464bfe..a46c2e828 100644 --- a/src/core/features/contentlinks/contentlinks.module.ts +++ b/src/core/features/contentlinks/contentlinks.module.ts @@ -13,7 +13,7 @@ // limitations under the License. import { NgModule, Type } from '@angular/core'; - +import { CoreContentLinksComponentsModule } from './components/components.module'; import { CoreContentLinksDelegateService } from './services/contentlinks-delegate'; import { CoreContentLinksHelperProvider } from './services/contentlinks-helper'; @@ -22,5 +22,9 @@ export const CORE_CONTENTLINKS_SERVICES: Type[] = [ CoreContentLinksHelperProvider, ]; -@NgModule({}) +@NgModule({ + imports: [ + CoreContentLinksComponentsModule, + ], +}) export class CoreContentLinksModule {} diff --git a/src/core/features/contentlinks/services/contentlinks-helper.ts b/src/core/features/contentlinks/services/contentlinks-helper.ts index 306ac53d5..feb965da8 100644 --- a/src/core/features/contentlinks/services/contentlinks-helper.ts +++ b/src/core/features/contentlinks/services/contentlinks-helper.ts @@ -17,9 +17,10 @@ import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreContentLinksDelegate, CoreContentLinksAction } from './contentlinks-delegate'; import { CoreSite } from '@classes/site'; -import { makeSingleton, Translate } from '@singletons'; +import { makeSingleton, ModalController, Translate } from '@singletons'; import { CoreNavigator } from '@services/navigator'; import { Params } from '@angular/router'; +import { CoreContentLinksChooseSiteModalComponent } from '../components/choose-site-modal/choose-site-modal'; /** * Service that provides some features regarding content links. @@ -111,7 +112,15 @@ export class CoreContentLinksHelperProvider { * @todo set correct root. */ async goToChooseSite(url: string): Promise { - await CoreNavigator.navigate('CoreContentLinksChooseSitePage @todo', { params: { url }, reset: true }); + const modal = await ModalController.create({ + component: CoreContentLinksChooseSiteModalComponent, + componentProps: { + url: url, + }, + cssClass: 'core-modal-fullscreen', + }); + + await modal.present(); } /**