|
1 | 1 | import WaveSurfer from "wavesurfer.js"; |
2 | 2 |
|
3 | | -import { takeUntil, Subject, take } from "rxjs"; |
| 3 | +import { takeUntil, Subject, take, fromEvent, debounceTime } from "rxjs"; |
4 | 4 | import { |
5 | 5 | AfterViewInit, |
6 | 6 | Component, |
@@ -70,6 +70,14 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit { |
70 | 70 | this.wcStylingService.$wcStyleFonts.subscribe((font) => |
71 | 71 | this.addWCCustomFont(font), |
72 | 72 | ); |
| 73 | + fromEvent(window, "resize") |
| 74 | + .pipe(debounceTime(100), takeUntil(this.unsubscribe$)) // wait for 1 second after the last resize event |
| 75 | + .subscribe(() => { |
| 76 | + // When the window is resized, we want to reset the style window size |
| 77 | + // so that it does not get squeezed too small |
| 78 | + console.log("[DEBUG] window resized"); |
| 79 | + this.resetStyleWindowSize(); |
| 80 | + }); |
73 | 81 | } |
74 | 82 |
|
75 | 83 | async ngAfterViewInit(): Promise<void> { |
@@ -134,37 +142,39 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit { |
134 | 142 | this.startTour(); |
135 | 143 | } |
136 | 144 | if (this.handleElement) { |
137 | | - (this.handleElement.nativeElement as HTMLElement).addEventListener( |
138 | | - "drag", |
139 | | - (ev: DragEvent) => { |
| 145 | + fromEvent(this.handleElement.nativeElement, "dragend") |
| 146 | + .pipe(takeUntil(this.unsubscribe$), debounceTime(100)) |
| 147 | + .subscribe((event) => { |
| 148 | + const ev = event as DragEvent; |
140 | 149 | console.log("[DEBUG] dragged"); |
141 | 150 | if (this.styleElement.collapsed$.getValue()) { |
142 | 151 | this.resetStyleWindowSize(); |
143 | 152 | return; |
144 | 153 | } |
145 | | - if (ev.x < 600) return; // do not let the read along be squeezed past 600px width |
| 154 | + if (ev.x < 600) { |
| 155 | + return; |
| 156 | + } // do not let the read along be squeezed past 600px width |
| 157 | + if (window.innerWidth - ev.x < 400) return; // do not let the style window be squeezed past 600px width) |
146 | 158 | // When the handle is dragged, we want to resize the readalong and style containers |
147 | 159 | const styleEle = this.styleElement?.styleSection |
148 | 160 | .nativeElement as HTMLElement; |
149 | 161 | const readAlong = this.readalongContainerElement |
150 | 162 | ?.nativeElement as HTMLElement; |
151 | 163 | if (styleEle?.style) { |
152 | | - styleEle.style.width = `calc(100vw - ${ev.x}px)`; |
| 164 | + styleEle.style.width = `calc(100vw - ${ev.x + 50}px)`; |
153 | 165 | } |
154 | 166 |
|
155 | 167 | if (readAlong?.style) { |
156 | 168 | readAlong.style.width = `${ev.x}px`; |
157 | 169 | } |
158 | | - }, |
159 | | - ); |
160 | | - this.styleElement.collapsed$.subscribe((collapsed) => { |
161 | | - if (collapsed) { |
162 | | - this.resetStyleWindowSize(); |
163 | | - } |
164 | | - }); |
| 170 | + }); |
165 | 171 | } else { |
166 | 172 | this.resetStyleWindowSize(); |
167 | 173 | } |
| 174 | + this.styleElement.collapsed$.subscribe((collapsed) => { |
| 175 | + // When the style element is collapsed, we want to reset the style window size |
| 176 | + this.resetStyleWindowSize(); |
| 177 | + }); |
168 | 178 | } |
169 | 179 |
|
170 | 180 | ngOnInit(): void {} |
@@ -263,6 +273,9 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit { |
263 | 273 | } |
264 | 274 |
|
265 | 275 | async loadRasFile(file: File | Blob) { |
| 276 | + //reset css |
| 277 | + this.wcStylingService.$wcStyleInput.next(""); |
| 278 | + this.wcStylingService.$wcStyleFonts.next(""); |
266 | 279 | const text = await file.text(); |
267 | 280 | const readalong = await this.parseReadalong(text); |
268 | 281 | this.loadAudioIntoWavesurferElement(); |
@@ -556,7 +569,9 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit { |
556 | 569 | ?.nativeElement as HTMLElement; |
557 | 570 |
|
558 | 571 | if (window.innerWidth > 1199) { |
559 | | - styleEle.style.width = `65vh`; |
| 572 | + styleEle.style.width = this.styleElement.collapsed$.value |
| 573 | + ? `65vh` |
| 574 | + : "calc(30vw - 50px)"; |
560 | 575 | readAlong.style.width = `70vw`; |
561 | 576 | } else { |
562 | 577 | styleEle.style.width = `95vw`; |
|
0 commit comments