Skip to content

Commit cba9e31

Browse files
Merge pull request #30 from codeplaysoftware/playground-add-fullscreen-mode
Misc Small Improvements
2 parents 0538c19 + 1a1857c commit cba9e31

File tree

3 files changed

+75
-24
lines changed

3 files changed

+75
-24
lines changed

src/app/pages/playground/playground.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<span class="material-symbols-outlined">settings</span></a>
2626

2727
@if (fullscreenMode()) {
28-
<a (click)="onToggleFullscreen()" title="exit fullscreen mode">
28+
<a (click)="onToggleFullscreen()" title="Exit fullscreen mode">
2929
<span class="material-symbols-outlined">fullscreen_exit</span></a>
3030
} @else {
3131
<a (click)="onToggleFullscreen()" title="Enter fullscreen mode">

src/app/pages/playground/playground.component.ts

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
import {
2020
ChangeDetectionStrategy,
21-
Component, Inject,
21+
Component, effect, Inject,
2222
OnDestroy, OnInit, Renderer2,
2323
signal,
2424
Signal,
2525
ViewChild,
2626
WritableSignal
2727
} from '@angular/core';
28-
import { CommonModule, NgOptimizedImage } from '@angular/common';
28+
import { CommonModule, DOCUMENT, NgOptimizedImage } from '@angular/common';
2929
import { LoadingState } from '../../shared/LoadingState';
3030
import { LoadingComponent } from '../../shared/components/loading/loading.component';
3131
import { MonacoEditorModule } from 'ngx-monaco-editor-v2';
@@ -46,7 +46,7 @@ import { PlatformInfoPopupComponent } from './shared/platform-info-popup/platfor
4646
import { SearchablePage } from '../../shared/components/site-wide-search/SearchablePage';
4747
import { StateService } from '../../shared/services/state.service';
4848
import { toSignal } from '@angular/core/rxjs-interop';
49-
import { ActivatedRoute } from '@angular/router';
49+
import { ActivatedRoute, Params, Router } from '@angular/router';
5050
import { SharePopupComponent } from './shared/share-popup/share-popup.component';
5151
import { LoadAndSavePopupComponent } from './shared/load-and-save-popup/load-and-save-popup.component';
5252
import { LOCAL_STORAGE, StorageService } from 'ngx-webstorage-service';
@@ -105,6 +105,9 @@ export class PlaygroundComponent implements SearchablePage, OnInit, OnDestroy {
105105
* @param stateService
106106
* @param activatedRoute
107107
* @param storageService
108+
* @param document
109+
* @param renderer
110+
* @param router
108111
*/
109112
constructor(
110113
protected titleService: Title,
@@ -115,7 +118,9 @@ export class PlaygroundComponent implements SearchablePage, OnInit, OnDestroy {
115118
protected stateService: StateService,
116119
protected activatedRoute: ActivatedRoute,
117120
@Inject(LOCAL_STORAGE) protected storageService: StorageService,
118-
protected renderer: Renderer2
121+
@Inject(DOCUMENT) protected document: Document,
122+
protected renderer: Renderer2,
123+
protected router: Router
119124
) {
120125
this.titleService.setTitle('Playground - SYCL.tech');
121126
this.meta.addTag({ name: 'keywords', content: this.getKeywords().join(', ') });
@@ -124,6 +129,31 @@ export class PlaygroundComponent implements SearchablePage, OnInit, OnDestroy {
124129
this.showMonacoEditor.set(this.platformService.isClient());
125130
this.compilationResult$ = new BehaviorSubject<CompilationResultModel | undefined>(undefined);
126131
this.compilationResult = toSignal(this.compilationResult$, { initialValue: undefined });
132+
133+
// Effect to handle full screen mode
134+
effect(() => {
135+
const fs = this.fullscreenMode();
136+
137+
const topNav = document.body.querySelectorAll('nav');
138+
const topFooter = document.body.querySelectorAll('footer');
139+
140+
if (topNav.length == 0 || topFooter.length == 0) {
141+
return;
142+
}
143+
144+
if (fs) {
145+
this.renderer.addClass(topNav[0], 'hidden');
146+
this.renderer.addClass(topFooter[0], 'hidden');
147+
} else {
148+
this.renderer.removeClass(topNav[0], 'hidden');
149+
this.renderer.removeClass(topFooter[0], 'hidden');
150+
}
151+
152+
// Update query params with fs value
153+
const queryParams: Params = { fs: fs ? true : null };
154+
this.router.navigate([], {
155+
relativeTo: this.activatedRoute, queryParams, queryParamsHandling: 'merge'}).then();
156+
});
127157
}
128158

129159
/**
@@ -159,6 +189,11 @@ export class PlaygroundComponent implements SearchablePage, OnInit, OnDestroy {
159189
take(1)
160190
).subscribe();
161191
}
192+
193+
// Enable full screen mode if its set via params
194+
if (params['fs'] === 'true') {
195+
this.fullscreenMode.set(true);
196+
}
162197
}),
163198
take(1)
164199
).subscribe();
@@ -439,7 +474,8 @@ export class PlaygroundComponent implements SearchablePage, OnInit, OnDestroy {
439474
*/
440475
onShareSample() {
441476
this.popupReference = this.popupService.create(SharePopupComponent, {
442-
'code': this.code()
477+
'code': this.code(),
478+
'fullScreen': this.fullscreenMode()
443479
}, true);
444480
}
445481

@@ -475,20 +511,5 @@ export class PlaygroundComponent implements SearchablePage, OnInit, OnDestroy {
475511
*/
476512
onToggleFullscreen() {
477513
this.fullscreenMode.set(!this.fullscreenMode());
478-
479-
const topNav = document.body.querySelectorAll('nav');
480-
const topFooter = document.body.querySelectorAll('footer');
481-
482-
if (topNav.length == 0 || topFooter.length == 0) {
483-
return ;
484-
}
485-
486-
if (this.fullscreenMode()) {
487-
this.renderer.addClass(topNav[0], 'hidden');
488-
this.renderer.addClass(topFooter[0], 'hidden');
489-
} else {
490-
this.renderer.removeClass(topNav[0], 'hidden');
491-
this.renderer.removeClass(topFooter[0], 'hidden');
492-
}
493514
}
494515
}

src/app/pages/playground/shared/share-popup/share-popup.component.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616
*
1717
*--------------------------------------------------------------------------------------------*/
1818

19-
import { ChangeDetectionStrategy, Component, Inject, signal, Signal, WritableSignal } from '@angular/core';
19+
import {
20+
ChangeDetectionStrategy,
21+
Component,
22+
computed,
23+
Inject,
24+
signal,
25+
Signal,
26+
WritableSignal
27+
} from '@angular/core';
2028
import { PopupReference } from '../../../../shared/components/popup/PopupService';
2129
import { PlaygroundService } from '../../../../shared/services/models/playground.service';
2230
import { LoadingState } from '../../../../shared/LoadingState';
@@ -43,9 +51,11 @@ export class SharePopupComponent {
4351
protected readonly LoadingState = LoadingState;
4452

4553
protected readonly code: Signal<string>;
54+
protected readonly syclTechUrl: Signal<string>;
55+
protected readonly fullscreenMode: Signal<boolean>;
56+
4657
protected readonly loading: WritableSignal<LoadingState> = signal(LoadingState.LOADING);
4758
protected readonly compilerExplorerUrl: WritableSignal<string | undefined> = signal(undefined);
48-
protected readonly syclTechUrl: WritableSignal<string | undefined> = signal(undefined);
4959

5060
/**
5161
* Constructor.
@@ -57,11 +67,11 @@ export class SharePopupComponent {
5767
protected playgroundService: PlaygroundService
5868
) {
5969
this.code = signal(this.popupReference.data['code']);
70+
this.fullscreenMode = signal(this.popupReference.data['fullScreen']);
6071

6172
this.playgroundService.createCodeSampleUrl(this.code()).pipe(
6273
tap((url) => {
6374
this.compilerExplorerUrl.set(url);
64-
this.syclTechUrl.set(url.replace('https://godbolt.org/z/', 'https://sycl.tech/playground?s='));
6575
this.loading.set(LoadingState.LOAD_SUCCESS);
6676
}),
6777
catchError(() => {
@@ -70,6 +80,26 @@ export class SharePopupComponent {
7080
}),
7181
take(1)
7282
).subscribe();
83+
84+
// Update the sycl.tech url based on compiler explorer url
85+
this.syclTechUrl = computed(() => {
86+
const compilerExplorerUrl = this.compilerExplorerUrl();
87+
const fullscreenMode = this.fullscreenMode();
88+
let syclTechUrl = '';
89+
90+
if (compilerExplorerUrl == undefined) {
91+
return '';
92+
}
93+
94+
syclTechUrl = compilerExplorerUrl
95+
.replace('https://godbolt.org/z/', 'https://sycl.tech/playground?s=');
96+
97+
if (fullscreenMode) {
98+
syclTechUrl += '&fs=true';
99+
}
100+
101+
return syclTechUrl;
102+
});
73103
}
74104

75105
/**

0 commit comments

Comments
 (0)