mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-20 03:30:55 +03:00
Refactored initialization process to better facilitate auth if necessary
Date in user profile dialog now shows date
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
<strong><ng-container i18n="UID">UID:</ng-container></strong> {{postsService.user.uid}}
|
||||
</div>
|
||||
<div>
|
||||
<strong><ng-container i18n="Created">Created:</ng-container></strong> {{postsService.user.created ? postsService.user.created : 'N/A'}}
|
||||
<strong><ng-container i18n="Created">Created:</ng-container></strong> {{postsService.user.created ? (postsService.user.created | date) : 'N/A'}}
|
||||
</div>
|
||||
<div style="margin-top: 20px;">
|
||||
</div>
|
||||
|
||||
@@ -196,7 +196,6 @@ export class MainComponent implements OnInit {
|
||||
|
||||
selectedQuality = '';
|
||||
formats_loading = false;
|
||||
config_loaded = false;
|
||||
|
||||
@ViewChild('urlinput', { read: ElementRef }) urlInput: ElementRef;
|
||||
@ViewChildren('audiofilecard') audioFileCards: QueryList<FileCardComponent>;
|
||||
@@ -295,12 +294,11 @@ export class MainComponent implements OnInit {
|
||||
|
||||
// app initialization.
|
||||
ngOnInit() {
|
||||
if (this.postsService.config) {
|
||||
if (this.postsService.initialized) {
|
||||
this.configLoad();
|
||||
} else {
|
||||
this.postsService.config_reloaded.subscribe(changed => {
|
||||
if (changed && !this.config_loaded) {
|
||||
this.config_loaded = true;
|
||||
this.postsService.service_initialized.subscribe(init => {
|
||||
if (init) {
|
||||
this.configLoad();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -79,11 +79,11 @@ export class PlayerComponent implements OnInit {
|
||||
this.uuid = this.route.snapshot.paramMap.get('uuid');
|
||||
|
||||
// loading config
|
||||
if (this.postsService.config) {
|
||||
if (this.postsService.initialized) {
|
||||
this.processConfig();
|
||||
} else {
|
||||
this.postsService.config_reloaded.subscribe(changed => { // loads settings
|
||||
if (changed) {
|
||||
this.postsService.service_initialized.subscribe(init => { // loads settings
|
||||
if (init) {
|
||||
this.processConfig();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -36,6 +36,8 @@ export class PostsService implements CanActivate {
|
||||
|
||||
reload_config = new BehaviorSubject<boolean>(false);
|
||||
config_reloaded = new BehaviorSubject<boolean>(false);
|
||||
service_initialized = new BehaviorSubject<boolean>(false);
|
||||
initialized = false;
|
||||
|
||||
config = null;
|
||||
constructor(private http: HttpClient, private router: Router, @Inject(DOCUMENT) private document: Document,
|
||||
@@ -75,7 +77,7 @@ export class PostsService implements CanActivate {
|
||||
this.jwtAuth();
|
||||
}
|
||||
} else {
|
||||
this.config_reloaded.next(true);
|
||||
this.setInitialized();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -328,6 +330,9 @@ export class PostsService implements CanActivate {
|
||||
}),
|
||||
};
|
||||
|
||||
// needed to re-initialize parts of app after login
|
||||
this.config_reloaded.next(true);
|
||||
|
||||
if (this.router.url === '/login') {
|
||||
this.router.navigate(['/home']);
|
||||
}
|
||||
@@ -350,7 +355,7 @@ export class PostsService implements CanActivate {
|
||||
call.subscribe(res => {
|
||||
if (res['token']) {
|
||||
this.afterLogin(res['user'], res['token']);
|
||||
this.config_reloaded.next(true);
|
||||
this.setInitialized();
|
||||
}
|
||||
}, err => {
|
||||
if (err.status === 401) {
|
||||
@@ -403,6 +408,12 @@ export class PostsService implements CanActivate {
|
||||
this.openSnackBar('You must log in to access this page!');
|
||||
}
|
||||
|
||||
setInitialized() {
|
||||
this.service_initialized.next(true);
|
||||
this.initialized = true;
|
||||
this.config_reloaded.next(true);
|
||||
}
|
||||
|
||||
public openSnackBar(message: string, action: string = '') {
|
||||
this.snackBar.open(message, action, {
|
||||
duration: 2000,
|
||||
|
||||
@@ -49,8 +49,8 @@ export class SubscriptionComponent implements OnInit {
|
||||
if (this.route.snapshot.paramMap.get('id')) {
|
||||
this.id = this.route.snapshot.paramMap.get('id');
|
||||
|
||||
this.postsService.config_reloaded.subscribe(changed => {
|
||||
if (changed) {
|
||||
this.postsService.service_initialized.subscribe(init => {
|
||||
if (init) {
|
||||
this.getConfig();
|
||||
this.getSubscription();
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ export class SubscriptionsComponent implements OnInit {
|
||||
constructor(private dialog: MatDialog, public postsService: PostsService, private router: Router, private snackBar: MatSnackBar) { }
|
||||
|
||||
ngOnInit() {
|
||||
if (this.postsService.config) {
|
||||
if (this.postsService.initialized) {
|
||||
this.getSubscriptions();
|
||||
}
|
||||
this.postsService.config_reloaded.subscribe(changed => {
|
||||
if (changed) {
|
||||
this.postsService.service_initialized.subscribe(init => {
|
||||
if (init) {
|
||||
this.getSubscriptions();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user