[frontend] Implement twitter start, stop
This commit is contained in:
parent
7df86eee43
commit
444b38e0e5
|
@ -26,7 +26,10 @@
|
|||
<mat-list-item *ngFor="let twitter of twitters">
|
||||
<div class="entry">
|
||||
@{{ twitter.username }}
|
||||
<mat-slide-toggle></mat-slide-toggle>
|
||||
<mat-slide-toggle
|
||||
[checked]="twitter.enabled === 1"
|
||||
(change)="onChange(twitter)"
|
||||
></mat-slide-toggle>
|
||||
<button
|
||||
mat-icon-button
|
||||
[matMenuTriggerFor]="menu"
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Observable } from 'rxjs';
|
|||
import { TwitterService } from 'src/app/core/api';
|
||||
import { TwitterInfoDialogComponent } from '../twitter-info-dialog/twitter-info-dialog.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
|
||||
@Component({
|
||||
selector: 'app-twitter-settings',
|
||||
|
@ -15,7 +16,8 @@ export class TwitterSettingsComponent implements OnInit {
|
|||
|
||||
constructor(
|
||||
private twitterService: TwitterService,
|
||||
public dialog: MatDialog
|
||||
public dialog: MatDialog,
|
||||
private snackBar: MatSnackBar
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
@ -46,4 +48,30 @@ export class TwitterSettingsComponent implements OnInit {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
onChange(twitter) {
|
||||
if (twitter.enabled === 0) {
|
||||
this.twitterService.startTwitter(twitter.id, this.hoodId).subscribe(
|
||||
() => {},
|
||||
(error) => {
|
||||
this.snackBar.open('Could not start. Check your settings.', 'Close', {
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
);
|
||||
} else if (twitter.enabled === 1) {
|
||||
this.twitterService.stopTwitter(twitter.id, this.hoodId).subscribe(
|
||||
() => {},
|
||||
(error) => {
|
||||
this.snackBar.open('Could not stop. Check your settings.', 'Close', {
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
// TODO yeah i know this is bad, implement disabling/enabling
|
||||
setTimeout(() => {
|
||||
this.reload();
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue