Skip to content

Commit

Permalink
Fix home for courses with less scenarios, refactor utf8 decoding (hob…
Browse files Browse the repository at this point in the history
…byfarm#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 <[email protected]>
  • Loading branch information
PhPrinz and Philip Prinz authored Jun 7, 2024
1 parent eed3005 commit b3435a9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/app/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ <h3>Select a scenario</h3>
</div>
</ng-container>

<div class="clr-row" *ngIf="courses.length > 0 && ctx.valid">
<div
class="clr-row course-container"
*ngIf="courses.length > 0 && ctx.valid"
>
<div class="clr-col-12">
<ng-container *ngFor="let c of courses">
<h3 class="course-header">{{ c.name | atob }}</h3>
Expand Down
4 changes: 4 additions & 0 deletions src/app/home.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
cds-icon[shape='clock'] {
color: black;
}

.course-container {
width: 100%;
}
14 changes: 2 additions & 12 deletions src/app/services/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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);
}
9 changes: 8 additions & 1 deletion src/app/unicode.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit b3435a9

Please sign in to comment.