@@ -17,184 +17,198 @@ import { Search, UserData } from './core/model/user-data';
17
17
import { Observable } from 'rxjs' ;
18
18
import { map } from 'rxjs/operators' ;
19
19
import { Bookmark } from './core/model/bookmark' ;
20
- import { AddToHistoryService } from './core/user/add-to-history.service ' ;
20
+ import { Router } from '@angular/router ' ;
21
21
22
22
@Component ( {
23
- selector : 'app-root' ,
24
- templateUrl : './app.component.html' ,
25
- styleUrls : [ './app.component.scss' ] ,
23
+ selector : 'app-root' ,
24
+ templateUrl : './app.component.html' ,
25
+ styleUrls : [ './app.component.scss' ] ,
26
26
} )
27
27
export class AppComponent implements OnInit {
28
28
29
- url = 'https://www.codever.land' ;
30
- innerWidth : any ;
31
-
32
- userIsLoggedIn = false ;
33
- userId : string ;
34
-
35
- userData$ : Observable < UserData > ;
36
- showAcknowledgeMigrationHeader = false ;
37
- latestSearches$ : Observable < Search [ ] > ;
38
- latestVisitedBookmarks$ : Observable < Bookmark [ ] > ;
39
-
40
- private hoveringLastSearches : boolean [ ] = [ ] ;
41
- private hoveringLastVisited : boolean [ ] = [ false , false , false , false , false , false , false , false , false , false ] ;
42
-
43
- constructor ( private keycloakService : KeycloakService ,
44
- private userInfoStore : UserInfoStore ,
45
- private userDataStore : UserDataStore ,
46
- private userDataHistoryStore : UserDataHistoryStore ,
47
- private userDataPinnedStore : UserDataPinnedStore ,
48
- private historyDialog : MatDialog ,
49
- private loginDialog : MatDialog ,
50
- private cookieService : CookieService ,
51
- private feedbackService : FeedbackService ,
52
- private addToHistoryService : AddToHistoryService ) {
53
- this . innerWidth = 100 ;
29
+ url = 'https://www.codever.land' ;
30
+ innerWidth : any ;
31
+
32
+ userIsLoggedIn = false ;
33
+ userId : string ;
34
+
35
+ userData$ : Observable < UserData > ;
36
+ showAcknowledgeMigrationHeader = false ;
37
+ latestSearches$ : Observable < Search [ ] > ;
38
+ latestVisitedBookmarks$ : Observable < Bookmark [ ] > ;
39
+
40
+ private hoveringLastSearches : boolean [ ] = [ ] ;
41
+ private hoveringLastVisited : boolean [ ] = [ false , false , false , false , false , false , false , false , false , false ] ;
42
+
43
+ constructor ( private keycloakService : KeycloakService ,
44
+ private userInfoStore : UserInfoStore ,
45
+ private userDataStore : UserDataStore ,
46
+ private userDataHistoryStore : UserDataHistoryStore ,
47
+ private userDataPinnedStore : UserDataPinnedStore ,
48
+ private historyDialog : MatDialog ,
49
+ private loginDialog : MatDialog ,
50
+ private cookieService : CookieService ,
51
+ private feedbackService : FeedbackService ,
52
+ protected router : Router ) {
53
+ this . innerWidth = 100 ;
54
+ }
55
+
56
+ ngOnInit ( ) : void {
57
+ const acknowledgedCodeverMigration = this . cookieService . readCookie ( 'acknowledge-codever-migration' ) ;
58
+ if ( acknowledgedCodeverMigration !== 'true' ) {
59
+ this . showAcknowledgeMigrationHeader = true ;
54
60
}
55
61
56
- ngOnInit ( ) : void {
57
- const acknowledgedCodeverMigration = this . cookieService . readCookie ( 'acknowledge-codever-migration' ) ;
58
- if ( acknowledgedCodeverMigration !== 'true' ) {
59
- this . showAcknowledgeMigrationHeader = true ;
60
- }
61
-
62
- this . keycloakService . isLoggedIn ( ) . then ( isLoggedIn => {
63
- if ( isLoggedIn ) {
64
- this . userIsLoggedIn = true ;
65
- this . userInfoStore . getUserInfo$ ( ) . subscribe ( userInfo => {
66
- this . userId = userInfo . sub ;
67
- this . latestVisitedBookmarks$ = this . userDataHistoryStore . getHistory$ ( this . userId , 1 ) ;
68
- } ) ;
69
- this . userData$ = this . userDataStore . getUserData$ ( ) ;
70
- this . latestSearches$ = this . userData$ . pipe (
71
- map ( userData => {
72
- for ( let i = 0 ; i < 10 ; i ++ ) {
73
- this . hoveringLastSearches . push ( false ) ;
74
- }
75
- return userData . searches . slice ( 0 , 10 ) ;
76
- } )
77
- )
78
- }
62
+ this . keycloakService . isLoggedIn ( ) . then ( isLoggedIn => {
63
+ if ( isLoggedIn ) {
64
+ this . userIsLoggedIn = true ;
65
+ this . userInfoStore . getUserInfo$ ( ) . subscribe ( userInfo => {
66
+ this . userId = userInfo . sub ;
67
+ this . latestVisitedBookmarks$ = this . userDataHistoryStore . getHistory$ ( this . userId , 1 ) ;
79
68
} ) ;
80
- }
81
-
82
- @HostListener ( 'window:keydown.control.p' , [ '$event' ] )
83
- showPinned ( event : KeyboardEvent ) {
84
- if ( ! this . userIsLoggedIn ) {
85
- const dialogConfig = new MatDialogConfig ( ) ;
86
-
87
- dialogConfig . disableClose = true ;
88
- dialogConfig . autoFocus = true ;
89
- dialogConfig . data = {
90
- message : 'You need to be logged in to see the Pinned Bookmarks popup'
91
- } ;
92
-
93
- this . loginDialog . open ( LoginRequiredDialogComponent , dialogConfig ) ;
94
- } else {
95
- event . preventDefault ( ) ;
96
- const dialogConfig = new MatDialogConfig ( ) ;
97
-
98
- dialogConfig . disableClose = false ;
99
- dialogConfig . autoFocus = true ;
100
- dialogConfig . width = this . getRelativeWidth ( ) ;
101
- dialogConfig . height = this . getRelativeHeight ( ) ;
102
- dialogConfig . data = {
103
- bookmarks$ : this . userDataPinnedStore . getPinnedBookmarks$ ( this . userId , 1 ) ,
104
- title : '<i class="fas fa-thumbtack"></i> Pinned'
105
- } ;
106
-
107
- const dialogRef = this . historyDialog . open ( HotKeysDialogComponent , dialogConfig ) ;
108
- dialogRef . afterClosed ( ) . subscribe (
109
- data => {
110
- console . log ( 'Dialog output:' , data ) ;
111
- }
112
- ) ;
69
+ this . userData$ = this . userDataStore . getUserData$ ( ) ;
70
+ this . latestSearches$ = this . userData$ . pipe (
71
+ map ( userData => {
72
+ for ( let i = 0 ; i < 10 ; i ++ ) {
73
+ this . hoveringLastSearches . push ( false ) ;
74
+ }
75
+ return userData . searches . slice ( 0 , 10 ) ;
76
+ } )
77
+ )
78
+ }
79
+ } ) ;
80
+ }
81
+
82
+ @HostListener ( 'window:keydown.control.p' , [ '$event' ] )
83
+ showPinned ( event : KeyboardEvent ) {
84
+ if ( ! this . userIsLoggedIn ) {
85
+ const dialogConfig = new MatDialogConfig ( ) ;
86
+
87
+ dialogConfig . disableClose = true ;
88
+ dialogConfig . autoFocus = true ;
89
+ dialogConfig . data = {
90
+ message : 'You need to be logged in to see the Pinned Bookmarks popup'
91
+ } ;
92
+
93
+ this . loginDialog . open ( LoginRequiredDialogComponent , dialogConfig ) ;
94
+ } else {
95
+ event . preventDefault ( ) ;
96
+ const dialogConfig = new MatDialogConfig ( ) ;
97
+
98
+ dialogConfig . disableClose = false ;
99
+ dialogConfig . autoFocus = true ;
100
+ dialogConfig . width = this . getRelativeWidth ( ) ;
101
+ dialogConfig . height = this . getRelativeHeight ( ) ;
102
+ dialogConfig . data = {
103
+ bookmarks$ : this . userDataPinnedStore . getPinnedBookmarks$ ( this . userId , 1 ) ,
104
+ title : '<i class="fas fa-thumbtack"></i> Pinned'
105
+ } ;
106
+
107
+ const dialogRef = this . historyDialog . open ( HotKeysDialogComponent , dialogConfig ) ;
108
+ dialogRef . afterClosed ( ) . subscribe (
109
+ data => {
110
+ console . log ( 'Dialog output:' , data ) ;
113
111
}
112
+ ) ;
114
113
}
114
+ }
115
115
116
- private getRelativeWidth ( ) {
117
- let relativeWidth = ( window . innerWidth * 80 ) / 100 ;
118
- if ( window . innerWidth > 1500 ) {
119
- relativeWidth = ( 1500 * 80 ) / 100 ;
120
- }
121
-
122
- return relativeWidth + 'px' ;
116
+ private getRelativeWidth ( ) {
117
+ let relativeWidth = ( window . innerWidth * 80 ) / 100 ;
118
+ if ( window . innerWidth > 1500 ) {
119
+ relativeWidth = ( 1500 * 80 ) / 100 ;
123
120
}
124
121
125
- private getRelativeHeight ( ) {
126
- let relativeHeight = ( window . innerHeight * 80 ) / 100 ;
127
- if ( window . innerHeight > 1200 ) {
128
- relativeHeight = ( 1200 * 80 ) / 100 ;
129
- }
122
+ return relativeWidth + 'px' ;
123
+ }
130
124
131
- return relativeHeight + 'px' ;
125
+ private getRelativeHeight ( ) {
126
+ let relativeHeight = ( window . innerHeight * 80 ) / 100 ;
127
+ if ( window . innerHeight > 1200 ) {
128
+ relativeHeight = ( 1200 * 80 ) / 100 ;
132
129
}
133
130
134
- @HostListener ( 'window:keydown.control.h' , [ '$event' ] )
135
- showHistory ( event : KeyboardEvent ) {
136
- if ( ! this . userIsLoggedIn ) {
137
- const dialogConfig = new MatDialogConfig ( ) ;
138
-
139
- dialogConfig . disableClose = true ;
140
- dialogConfig . autoFocus = true ;
141
- dialogConfig . data = {
142
- message : 'You need to be logged in to see the History Bookmarks popup'
143
- } ;
144
-
145
- this . loginDialog . open ( LoginRequiredDialogComponent , dialogConfig ) ;
146
- } else {
147
- event . preventDefault ( ) ;
148
- const dialogConfig = new MatDialogConfig ( ) ;
149
-
150
- dialogConfig . disableClose = false ;
151
- dialogConfig . autoFocus = true ;
152
- dialogConfig . width = this . getRelativeWidth ( ) ;
153
- dialogConfig . height = this . getRelativeHeight ( ) ;
154
- dialogConfig . data = {
155
- bookmarks$ : this . userDataHistoryStore . getAllHistory$ ( this . userId ) ,
156
- title : '<i class="fas fa-history"></i> History'
157
- } ;
158
-
159
- const dialogRef = this . historyDialog . open ( HotKeysDialogComponent , dialogConfig ) ;
160
- dialogRef . afterClosed ( ) . subscribe (
161
- data => {
162
- console . log ( 'Dialog output:' , data ) ;
163
- }
164
- ) ;
131
+ return relativeHeight + 'px' ;
132
+ }
133
+
134
+ @HostListener ( 'window:keydown.control.h' , [ '$event' ] )
135
+ showHistory ( event : KeyboardEvent ) {
136
+ if ( ! this . userIsLoggedIn ) {
137
+ const dialogConfig = new MatDialogConfig ( ) ;
138
+
139
+ dialogConfig . disableClose = true ;
140
+ dialogConfig . autoFocus = true ;
141
+ dialogConfig . data = {
142
+ message : 'You need to be logged in to see the History Bookmarks popup'
143
+ } ;
144
+
145
+ this . loginDialog . open ( LoginRequiredDialogComponent , dialogConfig ) ;
146
+ } else {
147
+ event . preventDefault ( ) ;
148
+ const dialogConfig = new MatDialogConfig ( ) ;
149
+
150
+ dialogConfig . disableClose = false ;
151
+ dialogConfig . autoFocus = true ;
152
+ dialogConfig . width = this . getRelativeWidth ( ) ;
153
+ dialogConfig . height = this . getRelativeHeight ( ) ;
154
+ dialogConfig . data = {
155
+ bookmarks$ : this . userDataHistoryStore . getAllHistory$ ( this . userId ) ,
156
+ title : '<i class="fas fa-history"></i> History'
157
+ } ;
158
+
159
+ const dialogRef = this . historyDialog . open ( HotKeysDialogComponent , dialogConfig ) ;
160
+ dialogRef . afterClosed ( ) . subscribe (
161
+ data => {
162
+ console . log ( 'Dialog output:' , data ) ;
165
163
}
164
+ ) ;
166
165
}
166
+ }
167
167
168
- public acknowledgeCodeverRebranding ( response : string ) {
169
- this . cookieService . createCookie ( 'acknowledge-codever-migration' , 'true' , 365 ) ;
170
- this . showAcknowledgeMigrationHeader = false ;
168
+ public acknowledgeCodeverRebranding ( response : string ) {
169
+ this . cookieService . createCookie ( 'acknowledge-codever-migration' , 'true' , 365 ) ;
170
+ this . showAcknowledgeMigrationHeader = false ;
171
171
172
- const iziToastSettings : IziToastSettings = {
173
- title : 'Thank you for your feedback' ,
174
- timeout : 3000 ,
175
- position : 'topRight'
176
- }
177
- iziToast . success ( iziToastSettings ) ;
178
-
179
- const feedback : Feedback = {
180
- question : 'Bookmarks.dev rebranding to Codever' ,
181
- userResponse : response ,
182
- userId : this . userId ? this . userId : null ,
183
- userAgent : navigator . userAgent
184
- }
185
-
186
- this . feedbackService . createFeedback ( feedback ) . subscribe ( ) ;
172
+ const iziToastSettings : IziToastSettings = {
173
+ title : 'Thank you for your feedback' ,
174
+ timeout : 3000 ,
175
+ position : 'topRight'
187
176
}
177
+ iziToast . success ( iziToastSettings ) ;
188
178
189
- acknowledgeWelcomeMessage ( ) {
190
- this . userDataStore . updateWelcomeAcknowledge$ ( ) ;
179
+ const feedback : Feedback = {
180
+ question : 'Bookmarks.dev rebranding to Codever' ,
181
+ userResponse : response ,
182
+ userId : this . userId ? this . userId : null ,
183
+ userAgent : navigator . userAgent
191
184
}
192
185
193
- resetHoveringLastSearches ( ) {
194
- this . hoveringLastSearches . forEach ( item => item = false ) ;
195
- }
186
+ this . feedbackService . createFeedback ( feedback ) . subscribe ( ) ;
187
+ }
188
+
189
+ acknowledgeWelcomeMessage ( ) {
190
+ this . userDataStore . updateWelcomeAcknowledge$ ( ) ;
191
+ }
192
+
193
+ resetHoveringLastSearches ( ) {
194
+ this . hoveringLastSearches . forEach ( item => item = false ) ;
195
+ }
196
+
197
+ resetHoveringLastVisited ( ) {
198
+ this . hoveringLastVisited . forEach ( item => item = false ) ;
199
+ }
196
200
197
- resetHoveringLastVisited ( ) {
198
- this . hoveringLastVisited . forEach ( item => item = false ) ;
201
+ navigateToBookmarkDetails ( bookmark : Bookmark ) : void {
202
+ let link = [ `./my-bookmarks/${ bookmark . _id } /details` ] ;
203
+ if ( bookmark . public ) {
204
+ link = [ `./bookmarks/${ bookmark . _id } /details` ] ;
199
205
}
206
+ this . router . navigate ( link , {
207
+ state : { bookmark : bookmark }
208
+ } ) ;
209
+ }
210
+
211
+ goToMainLink ( bookmark : Bookmark ) {
212
+ window . open ( bookmark . location , '_blank' ) ;
213
+ }
200
214
}
0 commit comments