browsing refactoring

This commit is contained in:
Nicolas Constant 2020-06-14 03:07:44 -04:00
parent fa0d89276a
commit c30ba1483a
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
9 changed files with 70 additions and 141 deletions

View File

@ -0,0 +1,25 @@
import { Output, EventEmitter, OnInit, OnDestroy } from '@angular/core';
import { OpenThreadEvent } from '../../services/tools.service';
export abstract class BrowseBase implements OnInit, OnDestroy {
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
abstract ngOnInit();
abstract ngOnDestroy();
browseAccount(accountName: string): void {
this.browseAccountEvent.next(accountName);
}
browseHashtag(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}
browseThread(openThreadEvent: OpenThreadEvent): void {
this.browseThreadEvent.next(openThreadEvent);
}
}

View File

@ -10,8 +10,9 @@ import { ToolsService, OpenThreadEvent } from '../../services/tools.service';
import { StatusWrapper } from '../../models/common.model';
import { Status } from '../../services/models/mastodon.interfaces';
import { TimeLineModeEnum } from '../../states/settings.state';
import { BrowseBase } from './browse-base';
export abstract class TimelineBase implements OnInit, OnDestroy {
export abstract class TimelineBase extends BrowseBase {
isLoading = true;
protected maxReached = false;
isThread = false;
@ -33,10 +34,6 @@ export abstract class TimelineBase implements OnInit, OnDestroy {
protected hideReplies: boolean;
protected hideBots: boolean;
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
@Input() goToTop: Observable<void>;
@Input() userLocked = true;
@ -47,6 +44,7 @@ export abstract class TimelineBase implements OnInit, OnDestroy {
protected readonly toolsService: ToolsService,
protected readonly notificationService: NotificationService,
protected readonly mastodonService: MastodonWrapperService) {
super();
}
abstract ngOnInit();
@ -95,18 +93,6 @@ export abstract class TimelineBase implements OnInit, OnDestroy {
this.isProcessingInfiniteScroll = false;
});
}
browseAccount(accountName: string): void {
this.browseAccountEvent.next(accountName);
}
browseHashtag(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}
browseThread(openThreadEvent: OpenThreadEvent): void {
this.browseThreadEvent.next(openThreadEvent);
}
applyGoToTop(): boolean {
this.statusProcessOnGoToTop();

View File

@ -8,13 +8,14 @@ import { NotificationService } from '../../../../services/notification.service';
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { Conversation } from '../../../../services/models/mastodon.interfaces';
import { AccountInfo } from '../../../../states/accounts.state';
import { BrowseBase } from '../../../common/browse-base';
@Component({
selector: 'app-direct-messages',
templateUrl: './direct-messages.component.html',
styleUrls: ['../../../stream/stream-statuses/stream-statuses.component.scss', './direct-messages.component.scss']
})
export class DirectMessagesComponent implements OnInit {
export class DirectMessagesComponent extends BrowseBase {
faUserFriends = faUserFriends;
conversations: ConversationWrapper[] = [];
@ -25,10 +26,6 @@ export class DirectMessagesComponent implements OnInit {
private isProcessingInfiniteScroll: boolean;
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
private maxReached = false;
private _account: AccountWrapper;
@ -46,11 +43,16 @@ export class DirectMessagesComponent implements OnInit {
constructor(
private readonly toolsService: ToolsService,
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonWrapperService) { }
private readonly mastodonService: MastodonWrapperService) {
super();
}
ngOnInit() {
}
ngOnDestroy() {
}
private reset() {
this.isLoading = true;
this.conversations.length = 0;
@ -114,18 +116,6 @@ export class DirectMessagesComponent implements OnInit {
});
}
browseAccount(accountName: string): void {
this.browseAccountEvent.next(accountName);
}
browseHashtag(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}
browseThread(openThreadEvent: OpenThreadEvent): void {
this.browseThreadEvent.next(openThreadEvent);
}
applyGoToTop(): boolean {
const stream = this.statustream.nativeElement as HTMLElement;
setTimeout(() => {

View File

@ -1,4 +1,4 @@
import { Component, OnInit, OnDestroy, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { faAt, faUserPlus } from "@fortawesome/free-solid-svg-icons";
import { faBell, faEnvelope, faUser, faStar, faBookmark } from "@fortawesome/free-regular-svg-icons";
import { Subscription } from 'rxjs';
@ -15,6 +15,7 @@ import { NotificationsComponent } from './notifications/notifications.component'
import { MentionsComponent } from './mentions/mentions.component';
import { DirectMessagesComponent } from './direct-messages/direct-messages.component';
import { FavoritesComponent } from './favorites/favorites.component';
import { BrowseBase } from '../../common/browse-base';
@Component({
@ -22,7 +23,7 @@ import { FavoritesComponent } from './favorites/favorites.component';
templateUrl: './manage-account.component.html',
styleUrls: ['./manage-account.component.scss']
})
export class ManageAccountComponent implements OnInit, OnDestroy {
export class ManageAccountComponent extends BrowseBase {
faAt = faAt;
faBell = faBell;
faEnvelope = faEnvelope;
@ -38,10 +39,6 @@ export class ManageAccountComponent implements OnInit, OnDestroy {
userAccount: Account;
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
@Input('account')
set account(acc: AccountWrapper) {
this._account = acc;
@ -60,7 +57,9 @@ export class ManageAccountComponent implements OnInit, OnDestroy {
private readonly toolsService: ToolsService,
private readonly mastodonService: MastodonWrapperService,
private readonly notificationService: NotificationService,
private readonly userNotificationService: UserNotificationService) { }
private readonly userNotificationService: UserNotificationService) {
super();
}
ngOnInit() {
}
@ -159,10 +158,6 @@ export class ManageAccountComponent implements OnInit, OnDestroy {
return false;
}
browseAccount(accountName: string): void {
this.browseAccountEvent.next(accountName);
}
browseLocalAccount(): boolean {
var accountName = `@${this.account.info.username}@${this.account.info.instance}`;
this.browseAccountEvent.next(accountName);
@ -173,12 +168,4 @@ export class ManageAccountComponent implements OnInit, OnDestroy {
window.open(this.userAccount.url, '_blank');
return false;
}
browseHashtag(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}
browseThread(openThreadEvent: OpenThreadEvent): void {
this.browseThreadEvent.next(openThreadEvent);
}
}

View File

@ -1,39 +1,29 @@
import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
import { Component, Input } from '@angular/core';
import { faUserPlus } from "@fortawesome/free-solid-svg-icons";
import { NotificationWrapper } from '../notifications.component';
import { OpenThreadEvent, ToolsService } from '../../../../../services/tools.service';
import { ToolsService } from '../../../../../services/tools.service';
import { Account } from '../../../../../services/models/mastodon.interfaces';
import { BrowseBase } from '../../../../../components/common/browse-base';
@Component({
selector: 'app-notification',
templateUrl: './notification.component.html',
styleUrls: ['./notification.component.scss']
})
export class NotificationComponent implements OnInit {
export class NotificationComponent extends BrowseBase {
faUserPlus = faUserPlus;
@Input() notification: NotificationWrapper;
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
constructor(private readonly toolsService: ToolsService) { }
constructor(private readonly toolsService: ToolsService) {
super();
}
ngOnInit() {
}
browseAccount(accountName: string): void {
this.browseAccountEvent.next(accountName);
}
browseHashtag(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}
browseThread(openThreadEvent: OpenThreadEvent): void {
this.browseThreadEvent.next(openThreadEvent);
ngOnDestroy() {
}
openAccount(account: Account): boolean {

View File

@ -1,4 +1,4 @@
import { Component, OnInit, Input, ViewChild, ElementRef, OnDestroy, Output, EventEmitter } from '@angular/core';
import { Component, Input, ViewChild, ElementRef } from '@angular/core';
import { Subscription } from 'rxjs';
import { AccountWrapper } from '../../../../models/account.models';
@ -8,22 +8,19 @@ import { Notification, Account } from '../../../../services/models/mastodon.inte
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { NotificationService } from '../../../../services/notification.service';
import { AccountInfo } from '../../../../states/accounts.state';
import { OpenThreadEvent, ToolsService } from '../../../../services/tools.service';
import { ToolsService } from '../../../../services/tools.service';
import { BrowseBase } from '../../../../components/common/browse-base';
@Component({
selector: 'app-notifications',
templateUrl: './notifications.component.html',
styleUrls: ['./notifications.component.scss']
})
export class NotificationsComponent implements OnInit, OnDestroy {
export class NotificationsComponent extends BrowseBase {
notifications: NotificationWrapper[] = [];
private isProcessingInfiniteScroll: boolean;
isLoading = false;
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
@Input('account')
set account(acc: AccountWrapper) {
this._account = acc;
@ -44,7 +41,9 @@ export class NotificationsComponent implements OnInit, OnDestroy {
private readonly toolsService: ToolsService,
private readonly notificationService: NotificationService,
private readonly userNotificationService: UserNotificationService,
private readonly mastodonService: MastodonWrapperService) { }
private readonly mastodonService: MastodonWrapperService) {
super();
}
ngOnInit() {
}
@ -127,18 +126,6 @@ export class NotificationsComponent implements OnInit, OnDestroy {
});
}
browseAccount(accountName: string): void {
this.browseAccountEvent.next(accountName);
}
browseHashtag(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}
browseThread(openThreadEvent: OpenThreadEvent): void {
this.browseThreadEvent.next(openThreadEvent);
}
applyGoToTop(): boolean {
const stream = this.statustream.nativeElement as HTMLElement;
setTimeout(() => {

View File

@ -10,13 +10,14 @@ import { NotificationWrapper } from '../../floating-column/manage-account/notifi
import { AccountInfo } from '../../../states/accounts.state';
import { NotificationService } from '../../../services/notification.service';
import { StreamingService, StatusUpdate, EventEnum } from '../../../services/streaming.service';
import { BrowseBase } from '../../common/browse-base';
@Component({
selector: 'app-stream-notifications',
templateUrl: './stream-notifications.component.html',
styleUrls: ['./stream-notifications.component.scss']
})
export class StreamNotificationsComponent implements OnInit, OnDestroy {
export class StreamNotificationsComponent extends BrowseBase {
displayingNotifications = true;
displayingMentions = false;
@ -26,10 +27,6 @@ export class StreamNotificationsComponent implements OnInit, OnDestroy {
@Input() streamElement: StreamElement;
@Input() goToTop: Observable<void>;
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
@ViewChild('notificationstream') public notificationstream: ElementRef;
@ViewChild('mentionstream') public mentionstream: ElementRef;
@ -53,7 +50,9 @@ export class StreamNotificationsComponent implements OnInit, OnDestroy {
private readonly notificationService: NotificationService,
private readonly userNotificationService: UserNotificationService,
private readonly mastodonService: MastodonService,
private readonly toolsService: ToolsService) { }
private readonly toolsService: ToolsService) {
super();
}
ngOnInit() {
this.goToTopSubscription = this.goToTop.subscribe(() => {
@ -265,16 +264,4 @@ export class StreamNotificationsComponent implements OnInit, OnDestroy {
}, 0);
return false;
}
browseAccount(accountName: string): void {
this.browseAccountEvent.next(accountName);
}
browseHashtag(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}
browseThread(openThreadEvent: OpenThreadEvent): void {
this.browseThreadEvent.next(openThreadEvent);
}
}

View File

@ -12,13 +12,14 @@ import { StatusComponent } from '../status/status.component';
import scrollIntoView from 'scroll-into-view-if-needed';
import { UserNotificationService, UserNotification } from '../../../services/user-notification.service';
import { TimeLineModeEnum } from '../../../states/settings.state';
import { BrowseBase } from '../../common/browse-base';
@Component({
selector: 'app-thread',
templateUrl: '../stream-statuses/stream-statuses.component.html',
styleUrls: ['../stream-statuses/stream-statuses.component.scss']
})
export class ThreadComponent implements OnInit, OnDestroy {
export class ThreadComponent extends BrowseBase {
statuses: StatusWrapper[] = [];
displayError: string;
isLoading = true;
@ -32,10 +33,6 @@ export class ThreadComponent implements OnInit, OnDestroy {
private lastThreadEvent: OpenThreadEvent;
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
@Input() refreshEventEmitter: EventEmitter<any>;
@Input() goToTopEventEmitter: EventEmitter<any>;
@ -61,7 +58,9 @@ export class ThreadComponent implements OnInit, OnDestroy {
private readonly notificationService: NotificationService,
private readonly userNotificationService: UserNotificationService,
private readonly toolsService: ToolsService,
private readonly mastodonService: MastodonWrapperService) { }
private readonly mastodonService: MastodonWrapperService) {
super();
}
ngOnInit() {
let settings = this.toolsService.getSettings();
@ -282,18 +281,6 @@ export class ThreadComponent implements OnInit, OnDestroy {
//Do nothing
}
browseAccount(accountName: string): void {
this.browseAccountEvent.next(accountName);
}
browseHashtag(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}
browseThread(openThreadEvent: OpenThreadEvent): void {
this.browseThreadEvent.next(openThreadEvent);
}
removeCw(): boolean {
const statuses = this.statusChildren.toArray();
statuses.forEach(x => {

View File

@ -13,13 +13,14 @@ import { AccountInfo } from '../../../states/accounts.state';
import { StatusWrapper, OpenMediaEvent } from '../../../models/common.model';
import { EmojiConverter, EmojiTypeEnum } from '../../../tools/emoji.tools';
import { NavigationService } from '../../../services/navigation.service';
import { BrowseBase } from '../../common/browse-base';
@Component({
selector: 'app-user-profile',
templateUrl: './user-profile.component.html',
styleUrls: ['./user-profile.component.scss']
})
export class UserProfileComponent implements OnInit {
export class UserProfileComponent extends BrowseBase {
private emojiConverter = new EmojiConverter();
faUser = faUser;
@ -64,10 +65,6 @@ export class UserProfileComponent implements OnInit {
@ViewChild('statusstream') public statustream: ElementRef;
@ViewChild('profilestatuses') public profilestatuses: ElementRef;
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
@Input() refreshEventEmitter: EventEmitter<any>;
@Input() goToTopEventEmitter: EventEmitter<any>;
@ -83,6 +80,7 @@ export class UserProfileComponent implements OnInit {
private readonly mastodonService: MastodonWrapperService,
private readonly toolsService: ToolsService) {
super();
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
}
@ -282,14 +280,6 @@ export class UserProfileComponent implements OnInit {
return false;
}
browseHashtag(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}
browseThread(openThreadEvent: OpenThreadEvent): void {
this.browseThreadEvent.next(openThreadEvent);
}
follow(): boolean {
const userAccount = this.toolsService.getSelectedAccounts()[0];
this.toolsService.findAccount(userAccount, this.lastAccountName)