Skip to content

Commit a41fa2c

Browse files
committed
feat - scrollstrategy noop for angular dialogs
thus the annoying expanding effect of the dialogs is removed
1 parent 302685d commit a41fa2c

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

frontend/src/app/app.component.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import { Bookmark } from './core/model/bookmark';
2020
import { Router } from '@angular/router';
2121
import { AddToHistoryService } from './core/user/add-to-history.service';
2222
import { environment } from '../environments/environment';
23+
import { ScrollStrategyOptions } from '@angular/cdk/overlay';
24+
import { ScrollStrategy } from '@angular/cdk/overlay/scroll/scroll-strategy';
25+
import { LoginDialogHelperService } from './core/login-dialog-helper.service';
2326

2427
@Component({
2528
selector: 'app-root',
@@ -45,17 +48,21 @@ export class AppComponent implements OnInit {
4548
favIcon: HTMLLinkElement = document.querySelector('#favicon');
4649
readonly environment = environment;
4750

51+
scrollStrategy: ScrollStrategy;
52+
4853
constructor(private keycloakService: KeycloakService,
4954
private userInfoStore: UserInfoStore,
5055
private userDataStore: UserDataStore,
5156
private userDataHistoryStore: UserDataHistoryStore,
5257
private userDataPinnedStore: UserDataPinnedStore,
5358
private historyDialog: MatDialog,
5459
private loginDialog: MatDialog,
60+
private loginDialogHelperService: LoginDialogHelperService,
5561
private cookieService: CookieService,
5662
private feedbackService: FeedbackService,
5763
protected router: Router,
58-
private addToHistoryService: AddToHistoryService) {
64+
private addToHistoryService: AddToHistoryService,
65+
private readonly scrollStrategyOptions: ScrollStrategyOptions) {
5966
this.innerWidth = 100;
6067
}
6168

@@ -86,18 +93,13 @@ export class AppComponent implements OnInit {
8693
)
8794
}
8895
});
96+
this.scrollStrategy = this.scrollStrategyOptions.noop();
8997
}
9098

9199
@HostListener('window:keydown.control.p', ['$event'])
92100
showPinned(event: KeyboardEvent) {
93101
if (!this.userIsLoggedIn) {
94-
const dialogConfig = new MatDialogConfig();
95-
96-
dialogConfig.disableClose = true;
97-
dialogConfig.autoFocus = true;
98-
dialogConfig.data = {
99-
message: 'You need to be logged in to see the Pinned Bookmarks popup'
100-
};
102+
const dialogConfig = this.loginDialogHelperService.loginDialogConfig('You need to be logged in to see the Pinned Bookmarks popup');
101103

102104
this.loginDialog.open(LoginRequiredDialogComponent, dialogConfig);
103105
} else {
@@ -108,6 +110,7 @@ export class AppComponent implements OnInit {
108110
dialogConfig.autoFocus = true;
109111
dialogConfig.width = this.getRelativeWidth();
110112
dialogConfig.height = this.getRelativeHeight();
113+
dialogConfig.scrollStrategy = this.scrollStrategy;
111114
dialogConfig.data = {
112115
bookmarks$: this.userDataPinnedStore.getPinnedBookmarks$(this.userId, 1),
113116
title: '<i class="fas fa-thumbtack"></i> Pinned'
@@ -143,13 +146,7 @@ export class AppComponent implements OnInit {
143146
@HostListener('window:keydown.control.h', ['$event'])
144147
showHistory(event: KeyboardEvent) {
145148
if (!this.userIsLoggedIn) {
146-
const dialogConfig = new MatDialogConfig();
147-
148-
dialogConfig.disableClose = true;
149-
dialogConfig.autoFocus = true;
150-
dialogConfig.data = {
151-
message: 'You need to be logged in to see the History Bookmarks popup'
152-
};
149+
const dialogConfig = this.loginDialogHelperService.loginDialogConfig('You need to be logged in to see the History Bookmarks popup');
153150

154151
this.loginDialog.open(LoginRequiredDialogComponent, dialogConfig);
155152
} else {
@@ -160,6 +157,7 @@ export class AppComponent implements OnInit {
160157
dialogConfig.autoFocus = true;
161158
dialogConfig.width = this.getRelativeWidth();
162159
dialogConfig.height = this.getRelativeHeight();
160+
dialogConfig.scrollStrategy = this.scrollStrategy;
163161
dialogConfig.data = {
164162
bookmarks$: this.userDataHistoryStore.getAllHistory$(this.userId),
165163
title: '<i class="fas fa-history"></i> History'

frontend/src/app/core/login-dialog-helper.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import { Injectable } from '@angular/core';
22
import { MatDialogConfig } from '@angular/material/dialog';
3+
import { ScrollStrategyOptions } from '@angular/cdk/overlay';
4+
import { ScrollStrategy } from '@angular/cdk/overlay/scroll/scroll-strategy';
35

46
@Injectable()
57
export class LoginDialogHelperService {
8+
9+
scrollStrategy: ScrollStrategy;
10+
11+
constructor(private readonly scrollStrategyOptions: ScrollStrategyOptions) {
12+
this.scrollStrategy = this.scrollStrategyOptions.noop();
13+
}
14+
615
loginDialogConfig(message: string) {
716
const dialogConfig = new MatDialogConfig();
817

918
dialogConfig.disableClose = true;
1019
dialogConfig.autoFocus = true;
20+
dialogConfig.scrollStrategy = this.scrollStrategy;
1121
dialogConfig.data = {
1222
message: message
1323
};

frontend/src/app/shared/bookmark-list-element/bookmark-list-element.component.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import { NavigationEnd, Router } from '@angular/router';
2626
import { LoginDialogHelperService } from '../../core/login-dialog-helper.service';
2727
import { AddToHistoryService } from '../../core/user/add-to-history.service';
2828
import { Clipboard } from '@angular/cdk/clipboard';
29+
import { ScrollStrategy } from '@angular/cdk/overlay/scroll/scroll-strategy';
30+
import { ScrollStrategyOptions } from '@angular/cdk/overlay';
2931

3032
@Component({
3133
selector: 'app-bookmark-list-element',
@@ -67,6 +69,8 @@ export class BookmarkListElementComponent extends TagFollowingBaseComponent impl
6769

6870
copyLinkButtonText = '';
6971

72+
scrollStrategy: ScrollStrategy;
73+
7074
constructor(private router: Router,
7175
private playYoutubeDialog: MatDialog,
7276
public loginDialog: MatDialog,
@@ -85,7 +89,8 @@ export class BookmarkListElementComponent extends TagFollowingBaseComponent impl
8589
private loginDialogHelperService: LoginDialogHelperService,
8690
private myBookmarksStore: MyBookmarksStore,
8791
public addToHistoryService: AddToHistoryService,
88-
private clipboard: Clipboard) {
92+
private clipboard: Clipboard,
93+
private readonly scrollStrategyOptions: ScrollStrategyOptions) {
8994
super(loginDialog, userDataWatchedTagsStore);
9095

9196
// START force reload on same root - solution taken from https://github.com/angular/angular/issues/13831
@@ -103,6 +108,8 @@ export class BookmarkListElementComponent extends TagFollowingBaseComponent impl
103108
});
104109
// END force reload on same root - solution taken from https://github.com/angular/angular/issues/13831
105110
// apparently still an issue around the topic - need to keep an eye on it - https://github.com/angular/angular/issues/21115
111+
112+
this.scrollStrategy = this.scrollStrategyOptions.noop();
106113
}
107114

108115
ngOnInit(): void {
@@ -123,16 +130,17 @@ export class BookmarkListElementComponent extends TagFollowingBaseComponent impl
123130
dialogConfig.disableClose = false;
124131
dialogConfig.autoFocus = true;
125132

126-
let relativeWidth = (this.innerWidth * 80) / 100; // take up to 80% of the screen size
133+
let relativeWidth = (this.innerWidth * 70) / 100; // take up to 80% of the screen size
127134
if (this.innerWidth > 1500) {
128-
relativeWidth = (1500 * 80) / 100;
135+
relativeWidth = (1500 * 70) / 100;
129136
} else {
130-
relativeWidth = (this.innerWidth * 80) / 100;
137+
relativeWidth = (this.innerWidth * 70) / 100;
131138
}
132139

133140
const relativeHeight = (relativeWidth * 9) / 16 + 120; // 16:9 to which we add 120 px for the dialog action buttons ("close")
134141
dialogConfig.width = relativeWidth + 'px';
135142
dialogConfig.height = relativeHeight + 'px';
143+
dialogConfig.scrollStrategy = this.scrollStrategy;
136144

137145
dialogConfig.data = {
138146
bookmark: bookmark,
@@ -187,6 +195,7 @@ export class BookmarkListElementComponent extends TagFollowingBaseComponent impl
187195
const dialogConfig = new MatDialogConfig();
188196
dialogConfig.disableClose = true;
189197
dialogConfig.autoFocus = true;
198+
dialogConfig.scrollStrategy = this.scrollStrategy;
190199
dialogConfig.data = {
191200
bookmark: bookmark,
192201
userData$: this.userData$
@@ -243,6 +252,7 @@ export class BookmarkListElementComponent extends TagFollowingBaseComponent impl
243252
dialogConfig.disableClose = true;
244253
dialogConfig.autoFocus = true;
245254
dialogConfig.minWidth = 380;
255+
dialogConfig.scrollStrategy = this.scrollStrategy;
246256
dialogConfig.data = {
247257
bookmark: bookmark,
248258
userIsLoggedIn: this.userIsLoggedIn,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Codever",
3-
"version": "6.4.0",
3+
"version": "6.5.0",
44
"description": "Codever - bookmarks and snippets manager for developers & co",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1",

0 commit comments

Comments
 (0)