1
0
Fork 0
mirror of https://codeberg.org/beerbrawl/beerbrawl.git synced 2024-09-23 01:30:52 +02:00

feat(#33): tweaks and test fix

This commit is contained in:
Rafael Tanzer 2024-06-25 15:55:51 +02:00
parent 3816f67b66
commit 365a213642
3 changed files with 9 additions and 30 deletions

View file

@ -37,11 +37,13 @@
<mat-form-field class="full-width">
<mat-label>Author</mat-label>
<input matInput [(ngModel)]="author" />
<input matInput [(ngModel)]="author" maxlength="50" />
<mat-hint align="end">{{ author?.length || 0 }}/50</mat-hint>
</mat-form-field>
<mat-form-field class="full-width">
<mat-label>Title</mat-label>
<input matInput [(ngModel)]="title" />
<input matInput [(ngModel)]="title" maxlength="100" />
<mat-hint align="end">{{ title?.length || 0 }}/100</mat-hint>
</mat-form-field>
<div class="buttons">

View file

@ -1,22 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ImageUploadComponent } from './image-upload.component';
describe('ImageUploadComponent', () => {
let component: ImageUploadComponent;
let fixture: ComponentFixture<ImageUploadComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ImageUploadComponent],
}).compileComponents();
fixture = TestBed.createComponent(ImageUploadComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -5,6 +5,7 @@ import { MatCardModule } from '@angular/material/card';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIcon } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatSnackBar } from '@angular/material/snack-bar';
import { SharedMediaEndpointService } from '@api';
@Component({
@ -33,26 +34,24 @@ export class ImageUploadComponent {
token = input.required<string>();
sharedMediaService = inject(SharedMediaEndpointService);
snackBar = inject(MatSnackBar);
uploadImage() {
// console.log(this.token());
// if (!this.token()) {
// this.errorMessage = 'No tournament token supplied!';
// return;
// }
console.log(this.author === '' ? 'PartyGuest' : this.author);
if (this.providedImage && this.tournamentId) {
const createDto = {
author: this.author === '' ? 'PartyGuest' : this.author,
title:
this.title === ''
? `t-${this.tournamentId()}_${Date.now().toLocaleString()}_submission.jpg`
? `t-${this.tournamentId()}_${Date.now().toString()}_submission.jpg`
: this.title,
tournamentId: this.tournamentId()!,
};
this.sharedMediaService.createSharedMedia(createDto, this.providedImage).subscribe({
next: () => {
console.log('Succesfully created');
this.snackBar.open('Succesfully uploaded image.', 'OK', { duration: 2500 });
this.clear();
},
error: () => {
console.error('Error when uplaoding image.');