From b3435a9232f09f7b9eabed428cf97163fdd5ee03 Mon Sep 17 00:00:00 2001 From: PhPrinz <48761034+PhPrinz@users.noreply.github.com> Date: Fri, 7 Jun 2024 12:54:24 +0200 Subject: [PATCH] Fix home for courses with less scenarios, refactor utf8 decoding (#207) * fix course overview if courses only have one scenario * use and improve existing atou function instead of new function --------- Co-authored-by: Philip Prinz --- src/app/home.component.html | 5 ++++- src/app/home.component.scss | 4 ++++ src/app/services/verification.service.ts | 14 ++------------ src/app/unicode.ts | 9 ++++++++- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/app/home.component.html b/src/app/home.component.html index 4c8fce80..4f71100a 100644 --- a/src/app/home.component.html +++ b/src/app/home.component.html @@ -104,7 +104,10 @@

Select a scenario

-
+

{{ c.name | atob }}

diff --git a/src/app/home.component.scss b/src/app/home.component.scss index 47fef6ac..e8f5e00a 100644 --- a/src/app/home.component.scss +++ b/src/app/home.component.scss @@ -13,3 +13,7 @@ cds-icon[shape='clock'] { color: black; } + +.course-container { + width: 100%; +} diff --git a/src/app/services/verification.service.ts b/src/app/services/verification.service.ts index 8282a2c8..10440b12 100644 --- a/src/app/services/verification.service.ts +++ b/src/app/services/verification.service.ts @@ -10,6 +10,7 @@ import { BehaviorSubject, throwError } from 'rxjs'; import { catchError, tap } from 'rxjs/operators'; import { HttpErrorResponse } from '@angular/common/http'; import { VMService } from './vm.service'; +import { atou } from '../unicode'; @Injectable() export class VerificationService { @@ -98,7 +99,7 @@ export class VerificationService { private publishNewVerificationResults(response: ServerResponse) { const newVerificationList = JSON.parse( - decodeResponse(response.content), + atou(response.content), ) as unknown as TaskVerificationResponse[]; newVerificationList.forEach( (newTaskVerification: TaskVerificationResponse) => { @@ -120,14 +121,3 @@ export class VerificationService { this._verifications.next(this._verifications.value); } } - -function decodeResponse(responseContent: string) { - const text = atob(responseContent); - const length = text.length; - const bytes = new Uint8Array(length); - for (let i = 0; i < length; i++) { - bytes[i] = text.charCodeAt(i); - } - const decoder = new TextDecoder(); // default is utf-8 - return decoder.decode(bytes); -} diff --git a/src/app/unicode.ts b/src/app/unicode.ts index 6df32a99..4d684462 100644 --- a/src/app/unicode.ts +++ b/src/app/unicode.ts @@ -1,5 +1,12 @@ export function atou(b64: string) { - return decodeURIComponent(escape(atob(b64))); + const text = atob(b64); + const length = text.length; + const bytes = new Uint8Array(length); + for (let i = 0; i < length; i++) { + bytes[i] = text.charCodeAt(i); + } + const decoder = new TextDecoder(); // default is utf-8 + return decoder.decode(bytes); } export function utoa(data: string) {