Skip to content

Commit 1b12f03

Browse files
committed
Merge branch 'wysiwyg' of https://github.com/codelab-fun/codelab into feature/side-panel-selection
� Conflicts: � apps/codelab/src/app/admin/content/presentation-editor/content.component.ts � apps/codelab/src/app/admin/content/presentation-editor/services/content.service.ts � apps/codelab/src/app/admin/content/presentation-editor/side-panel/side-panel.component.html
2 parents 4a8aba6 + 5340597 commit 1b12f03

File tree

17 files changed

+114
-65
lines changed

17 files changed

+114
-65
lines changed

apps/codelab/src/app/admin/content/presentation-editor/content.component.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Component } from '@angular/core';
2+
import { ContentService } from './services/content.service';
23
import { ActivatedRoute } from '@angular/router';
3-
4+
import { map } from 'rxjs/operators';
45
import { combineLatest } from 'rxjs';
5-
import { map, shareReplay } from 'rxjs/operators';
6-
7-
import { ContentService } from './content.service';
86
import { ContentPresentation } from './types';
7+
import { NavigationService } from './services/navigation.service';
98

109
@Component({
1110
selector: 'slides-content',
@@ -14,32 +13,36 @@ import { ContentPresentation } from './types';
1413
})
1514
export class ContentComponent {
1615
readonly presentation$ = combineLatest([
17-
this.activeRoute.params,
16+
this.navigationService.selectedPresentationId$,
1817
this.contentService.state$
1918
]).pipe(
20-
map(([params, presentations]) => {
19+
map(([presentationId, presentations]) => {
20+
debugger;
2121
return presentations.find(
22-
(p: ContentPresentation) => p.id === params.presentation
22+
(p: ContentPresentation) => p.id === presentationId
2323
);
24-
}),
25-
shareReplay(1)
24+
})
2625
);
2726

2827
currentSlideIndex$ = this.contentService.currentSlideIndex$;
2928

3029
currentSlide$ = combineLatest([
31-
this.activeRoute.params,
30+
this.navigationService.selectedSlide$,
3231
this.presentation$
3332
]).pipe(
34-
map(([params, presentation]) => {
35-
return presentation.slides[params.slide || 0];
33+
map(([slide, presentation]) => {
34+
debugger;
35+
return presentation.slides[slide || 0];
3636
})
3737
);
3838

3939
constructor(
4040
readonly contentService: ContentService,
41+
readonly navigationService: NavigationService,
4142
readonly activeRoute: ActivatedRoute
42-
) {}
43+
) {
44+
this.contentService.state$.subscribe(a => console.log());
45+
}
4346

4447
addSlide(presentationId: string) {
4548
this.contentService.addSlide(presentationId);

apps/codelab/src/app/admin/content/presentation-editor/content.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AngularFirestoreModule } from '@angular/fire/firestore';
66
import { DragDropModule } from '@angular/cdk/drag-drop';
77
import { RouterModule } from '@angular/router';
88
import { SidePanelModule } from './side-panel/side-panel.module';
9-
import { ContentService } from './content.service';
9+
import { ContentService } from './services/content.service';
1010
import { MatIconModule } from '@angular/material/icon';
1111
import { MatButtonModule } from '@angular/material/button';
1212
import { Observable, OperatorFunction } from 'rxjs';
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
import { Component, HostListener } from '@angular/core';
2-
import { ContentService } from '../content.service';
2+
import { NavigationService } from '../services/navigation.service';
3+
import { ContentService } from '../services/content.service';
34

45
@Component({
56
selector: 'slides-preview',
67
templateUrl: './preview.component.html',
78
styleUrls: ['./preview.component.css']
89
})
910
export class PreviewComponent {
10-
constructor(readonly contentService: ContentService) {}
11+
constructor(
12+
readonly navigationService: NavigationService,
13+
readonly contentService: ContentService
14+
) {}
15+
1116
presentationId = 'TBD';
1217

1318
@HostListener('window:keydown.arrowleft')
1419
previousSlide() {
15-
this.contentService.previousSlide(this.presentationId);
20+
this.navigationService.previousSlide(this.presentationId);
1621
}
1722

1823
@HostListener('window:keydown.arrowright')
1924
nextSlide() {
20-
this.contentService.nextSlide(this.presentationId);
25+
this.navigationService.nextSlide(this.presentationId);
2126
}
2227
}

apps/codelab/src/app/admin/content/presentation-editor/content.service.ts renamed to apps/codelab/src/app/admin/content/presentation-editor/services/content.service.ts

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ import { AngularFirestore } from '@angular/fire/firestore';
33
import { ActivatedRoute, Router } from '@angular/router';
44
import { Location } from '@angular/common';
55
import { BehaviorSubject, merge, Subject } from 'rxjs';
6-
import { auditTime, map, scan, share, takeUntil } from 'rxjs/operators';
7-
import { ContentBlock, ContentPresentation } from './types';
6+
import {
7+
auditTime,
8+
map,
9+
scan,
10+
share,
11+
shareReplay,
12+
takeUntil
13+
} from 'rxjs/operators';
814
import { nanoid } from 'nanoid';
915
import * as firebase from 'firebase';
10-
import { reducer } from './reducer';
16+
import { ContentBlock, ContentPresentation } from '../types';
17+
import { reducer } from '../reducer';
1118

1219
const DOC_KEY = 'presentations';
1320

@@ -31,8 +38,8 @@ export class ContentService implements OnDestroy {
3138
private readonly localActions$ = new Subject();
3239

3340
readonly appliedActions = new Set();
34-
const;
35-
allActions2$ = merge(
41+
42+
readonly allActions$ = merge(
3643
this.presentations$.pipe(
3744
map((presentations: ContentPresentation[] = []) => ({
3845
type: 'init',
@@ -42,11 +49,11 @@ export class ContentService implements OnDestroy {
4249
this.localActions$
4350
);
4451

45-
public readonly state$ = this.allActions2$.pipe(
52+
public readonly state$ = this.allActions$.pipe(
4653
scan((state: ContentPresentation[], action: any) => {
4754
return reducer(state, action);
4855
}, {}),
49-
share()
56+
shareReplay(1)
5057
);
5158

5259
constructor(
@@ -75,17 +82,6 @@ export class ContentService implements OnDestroy {
7582
this.onDestroy.complete();
7683
}
7784

78-
// TODO: Move this out
79-
goToSlide(presentationId: string, index: number) {
80-
if (index >= 0) {
81-
this.currentSlideSubject.next(index);
82-
this.router.navigateByUrl('admin/content/' + presentationId + '/' + index);
83-
// this.location.replaceState(
84-
// 'admin/content/' + presentationId + '/' + index
85-
// );
86-
}
87-
}
88-
8985
dispatch(presentationId, action) {
9086
const a = {
9187
...action,
@@ -97,16 +93,6 @@ export class ContentService implements OnDestroy {
9793
this.localActions$.next(a);
9894
}
9995

100-
// TODO: Move out
101-
nextSlide(presentationId: string) {
102-
this.goToSlide(presentationId, this.currentSlideIndex$.value + 1);
103-
}
104-
105-
// TODO: Move out
106-
previousSlide(presentationId: string) {
107-
this.goToSlide(presentationId, this.currentSlideIndex$.value - 1);
108-
}
109-
11096
addSlide(presentationId: string) {
11197
const index = this.currentSlideIndex$.value;
11298
const action = {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Injectable } from '@angular/core';
2+
import { BehaviorSubject } from 'rxjs';
3+
import { ActivatedRoute, Router } from '@angular/router';
4+
import { Location } from '@angular/common';
5+
import { take } from 'rxjs/operators';
6+
7+
@Injectable({
8+
providedIn: 'root'
9+
})
10+
export class NavigationService {
11+
private readonly selectedSlideSubject = new BehaviorSubject(0);
12+
private readonly selectedPresentationIdSubject = new BehaviorSubject<
13+
string | undefined
14+
>(undefined);
15+
public selectedSlide$ = this.selectedSlideSubject.asObservable();
16+
public selectedPresentationId$ = this.selectedPresentationIdSubject.asObservable();
17+
18+
constructor(
19+
readonly route: ActivatedRoute,
20+
readonly router: Router,
21+
readonly location: Location
22+
) {
23+
// TODO(kirjs): need a better way
24+
const params =
25+
router.routerState.snapshot.root.firstChild.firstChild.firstChild.params;
26+
this.selectedPresentationIdSubject.next(params.presentation);
27+
this.selectedSlideSubject.next(params.slide);
28+
}
29+
30+
goToPresentation(presentationId: string) {
31+
this.selectedPresentationIdSubject.next(presentationId);
32+
this.router.navigate(['admin', 'content', presentationId, '0']);
33+
}
34+
35+
goToSlide(presentationId: string, index: number) {
36+
if (index >= 0) {
37+
this.selectedSlideSubject.next(index);
38+
this.location.replaceState(
39+
'admin/content/' + presentationId + '/' + index
40+
);
41+
}
42+
}
43+
44+
nextSlide(presentationId: string) {
45+
this.goToSlide(presentationId, this.selectedSlideSubject.value + 1);
46+
}
47+
48+
previousSlide(presentationId: string) {
49+
this.goToSlide(presentationId, this.selectedSlideSubject.value - 1);
50+
}
51+
}

apps/codelab/src/app/admin/content/presentation-editor/side-panel/side-panel.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div (cdkDropListDropped)='reorder.emit($event)' cdkDropList >
55
<button
66
inert
7-
(click)='this.contentService.goToSlide(presentationId, i)'
7+
(click)='this.navigationService.goToSlide(presentationId, i)'
88
*ngFor='let slide of slides; let i = index'
99
[class.selected]='i === currentSlideIndex'
1010
class='slide-wrapper'

apps/codelab/src/app/admin/content/presentation-editor/side-panel/side-panel.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
import { Location } from '@angular/common';
99

1010
import { ActivatedRoute, Router } from '@angular/router';
11-
import { ContentService } from '../content.service';
11+
import { ContentService } from '../services/content.service';
12+
import { NavigationService } from '../services/navigation.service';
1213

1314
@Component({
1415
selector: 'slides-side-panel',
@@ -25,7 +26,8 @@ export class SidePanelComponent {
2526
readonly location: Location,
2627
readonly route: ActivatedRoute,
2728
readonly router: Router,
28-
readonly contentService: ContentService
29+
readonly contentService: ContentService,
30+
readonly navigationService: NavigationService
2931
) {}
3032

3133
addSlide() {
@@ -34,11 +36,11 @@ export class SidePanelComponent {
3436

3537
@HostListener('keydown.arrowdown')
3638
nextSlide() {
37-
this.contentService.nextSlide(this.presentationId);
39+
this.navigationService.nextSlide(this.presentationId);
3840
}
3941

4042
@HostListener('keydown.arrowup')
4143
prevSlide() {
42-
this.contentService.previousSlide(this.presentationId);
44+
this.navigationService.previousSlide(this.presentationId);
4345
}
4446
}

apps/codelab/src/app/admin/content/presentation-editor/slide-editor/action-bar/action-bar.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, EventEmitter, Input, Output } from '@angular/core';
22
import { ContentBlock, ContentSlide } from '../../types';
3-
import { ContentService } from '../../content.service';
3+
import { ContentService } from '../../services/content.service';
44

55
@Component({
66
selector: 'slides-action-bar',

apps/codelab/src/app/admin/content/presentation-editor/slide-editor/slide-editor.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, EventEmitter, Input, Output } from '@angular/core';
2-
import { ContentService } from '../content.service';
2+
import { ContentService } from '../services/content.service';
33
import { assertIsHtmlBlock, ContentBlock, ContentSlide } from '../types';
44

55
@Component({

apps/codelab/src/app/admin/content/presentation-editor/slide-editor/slide-meta-editor/slide-meta-editor.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, Input, OnInit } from '@angular/core';
2-
import { ContentService } from '../../content.service';
2+
import { ContentService } from '../../services/content.service';
33

44
@Component({
55
selector: 'slides-slide-meta-editor',

0 commit comments

Comments
 (0)