Skip to content

Commit

Permalink
fix: team logotype on highscore list (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsbergPhilip authored Nov 15, 2024
1 parent 1fcd94e commit 80af67a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
7 changes: 4 additions & 3 deletions packages/backend/src/models/highscore-public.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ export class HighscorePublicDto implements IHighscoreDto {
@IsOptional()
team: string | null = null;

@ApiProperty()
teamLogotype!: string;
@ApiPropertyOptional({ nullable: true })
@IsOptional()
teamLogotype: string | null = null;

public static fromEntity(entity: IHighscore): HighscorePublicDto {
return {
botName: entity.bot!.name,
score: entity.score,
seasonId: entity.seasonId,
team: entity.bot!.team?.name ?? null,
teamLogotype: entity.bot!.team!.logotypeUrl,
teamLogotype: entity.bot!.team?.logotypeUrl ?? null,
};
}
}
18 changes: 12 additions & 6 deletions packages/frontend/src/components/HighScoreTable.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IHighscoreDto } from '@etimo/diamonds2-types';
import { FC, memo } from 'react';
import { useHighScore } from '../hooks/useHighScore';
import { Spinner } from './Spinner';
Expand All @@ -9,6 +10,16 @@ type HighScoreProps = {
export const HighScoreTable: FC<HighScoreProps> = memo((props) => {
const { seasonId } = props;

const logotype = (item: IHighscoreDto) => {
if (item.teamLogotype) {
return <img src={item.teamLogotype} alt="school-logo" />;
}
if (item.team) {
return item.team;
}
return '';
};

if (!seasonId) {
return <Spinner />;
}
Expand All @@ -20,12 +31,7 @@ export const HighScoreTable: FC<HighScoreProps> = memo((props) => {
data={highscore.map((item) => {
return {
name: item.botName,
team:
item.teamLogotype !== '' ? (
<img src={item.teamLogotype} alt="school-logo" />
) : (
item.team
),
team: logotype(item),
score: item.score,
};
})}
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/dto/highscore-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export interface IHighscoreDto {
score: number;
seasonId: string;
team: string | null;
teamLogotype: string;
teamLogotype: string | null;
}

0 comments on commit 80af67a

Please sign in to comment.