...
 
Commits (2)
<ng-container *ngIf="channel; else loader">
<ng-container *ngIf="!channel.pro; else isProChannel">
<ng-container *ngIf="!channel.pro || isOwner; else isProChannel">
<m-channel #channelComponent></m-channel>
</ng-container>
<ng-template #isProChannel>
......
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable, Subscription } from 'rxjs';
import { Client } from '../../services/api/client';
import { MindsUser } from '../../interfaces/entities';
import { MindsChannelResponse } from '../../interfaces/responses';
import { ChannelComponent } from '../channels/channel.component';
import { ProChannelComponent } from '../pro/channel/channel.component';
import { Session } from '../../services/session';
@Component({
selector: 'm-channel-container',
......@@ -28,7 +29,9 @@ export class ChannelContainerComponent implements OnInit, OnDestroy {
constructor(
protected route: ActivatedRoute,
protected router: Router,
protected client: Client,
protected session: Session,
) {
}
......@@ -66,10 +69,20 @@ export class ChannelContainerComponent implements OnInit, OnDestroy {
try {
const response: MindsChannelResponse = await this.client.get(`api/v1/channel/${this.username}`) as MindsChannelResponse;
this.channel = response.channel;
// NOTE: Temporary workaround until channel component supports children routes
if (!window.Minds.pro && this.channel.pro && !this.isOwner) {
this.router.navigate(['/pro', this.channel.username], { replaceUrl: true });
}
} catch (e) {
console.error(e);
}
this.inProgress = false;
}
get isOwner() {
const currentUser = this.session.getLoggedInUser();
return this.channel && currentUser && this.channel.guid == currentUser.guid;
}
}
......@@ -186,7 +186,12 @@ export class ProChannelComponent implements OnInit, AfterViewInit, OnDestroy {
if (!this.channel.subscribed) {
if (!this.session.isLoggedIn()) {
this.router.navigate(this.channelService.getRouterLink('signup'));
this.router.navigate(
window.Minds.pro ?
this.channelService.getRouterLink('signup') :
['/login']
);
return false;
}
......
......@@ -8,6 +8,7 @@ import { ProContentModalComponent } from './content-modal/modal.component';
import { OverlayModalService } from '../../../services/ux/overlay-modal';
import { BlogView } from "../../blogs/view/view";
import { Session } from '../../../services/session';
import { ActivatedRoute } from '@angular/router';
export type RouterLinkToType = 'home' | 'all' | 'feed' | 'videos' | 'images' | 'articles' | 'communities' | 'donate' | 'signup';
......@@ -24,6 +25,7 @@ export class ProChannelService {
protected client: Client,
protected entitiesService: EntitiesService,
protected session: Session,
protected route: ActivatedRoute,
) {
}
......@@ -125,7 +127,13 @@ export class ProChannelService {
}
getRouterLink(to: RouterLinkToType, params?: { [key: string]: any }): any[] {
const route: any[] = ['/'];
let root = '/';
if (this.route.parent) {
root = this.route.parent.pathFromRoot.map(route => route.snapshot.url.map(urlSegment => urlSegment.toString()).join('')).join('/');
}
const route: any[] = [root];
if (!window.Minds.pro) {
route.push(this.currentChannel.username);
......@@ -154,7 +162,7 @@ export class ProChannelService {
break;
case 'signup':
route.push('signup');
route.push('login');
break;
}
......
......@@ -68,6 +68,10 @@ routes.push({
path: 'settings',
component: ProSettingsComponent,
},
{
path: ':username',
...channelRoute
}
]
});
......
......@@ -290,7 +290,7 @@
class="m-btn m-link-btn m-btn--slim m-pro--settings--preview-btn"
[routerLink]="previewRoute"
i18n
>Go to your channel</a>
>View your Pro channel</a>
</div>
</form>
</ng-container>
......
......@@ -96,7 +96,7 @@ export class ProSettingsComponent implements OnInit {
}
get previewRoute() {
return ['/', this.session.getLoggedInUser().username];
return ['/pro', this.session.getLoggedInUser().username];
}
onDragStart(event: DragEvent) {
......