Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): improve alt text #7596

Merged
merged 13 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions mobile/openapi/doc/MapMarkerResponseDto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 39 additions & 3 deletions mobile/openapi/lib/model/map_marker_response_dto.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions mobile/openapi/test/map_marker_response_dto_test.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion open-api/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -8291,6 +8291,14 @@
},
"MapMarkerResponseDto": {
"properties": {
"city": {
"nullable": true,
"type": "string"
},
"country": {
"nullable": true,
"type": "string"
},
"id": {
"type": "string"
},
Expand All @@ -8301,12 +8309,19 @@
"lon": {
"format": "double",
"type": "number"
},
"state": {
"nullable": true,
"type": "string"
}
},
"required": [
"city",
"country",
"id",
"lat",
"lon"
"lon",
"state"
],
"type": "object"
},
Expand Down
3 changes: 3 additions & 0 deletions open-api/typescript-sdk/src/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,12 @@ export type AssetJobsDto = {
name: AssetJobName;
};
export type MapMarkerResponseDto = {
city: string | null;
country: string | null;
id: string;
lat: number;
lon: number;
state: string | null;
};
export type MemoryLaneResponseDto = {
assets: AssetResponseDto[];
Expand Down
27 changes: 11 additions & 16 deletions server/src/domain/asset/asset.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,27 +286,22 @@ describe(AssetService.name, () => {

describe('getMapMarkers', () => {
it('should get geo information of assets', async () => {
const asset = assetStub.withLocation;
const marker = {
id: asset.id,
lat: asset.exifInfo!.latitude!,
lon: asset.exifInfo!.longitude!,
city: asset.exifInfo!.city,
state: asset.exifInfo!.state,
country: asset.exifInfo!.country,
};
partnerMock.getAll.mockResolvedValue([]);
assetMock.getMapMarkers.mockResolvedValue(
[assetStub.withLocation].map((asset) => ({
id: asset.id,

/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
lat: asset.exifInfo!.latitude!,

/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
lon: asset.exifInfo!.longitude!,
})),
);
assetMock.getMapMarkers.mockResolvedValue([marker]);

const markers = await sut.getMapMarkers(authStub.user1, {});

expect(markers).toHaveLength(1);
expect(markers[0]).toEqual({
id: assetStub.withLocation.id,
lat: 100,
lon: 100,
});
expect(markers[0]).toEqual(marker);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ export class MapMarkerResponseDto {

@ApiProperty({ format: 'double' })
lon!: number;

@ApiProperty()
city!: string | null;

@ApiProperty()
state!: string | null;

@ApiProperty()
country!: string | null;
}
9 changes: 7 additions & 2 deletions server/src/domain/repositories/asset.repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { AssetSearchOneToOneRelationOptions, AssetSearchOptions, SearchExploreItem } from '@app/domain';
import {
AssetSearchOneToOneRelationOptions,
AssetSearchOptions,
ReverseGeocodeResult,
SearchExploreItem,
} from '@app/domain';
import { AssetEntity, AssetJobStatusEntity, AssetType, ExifEntity } from '@app/infra/entities';
import { FindOptionsRelations, FindOptionsSelect } from 'typeorm';
import { Paginated, PaginationOptions } from '../domain.util';
Expand All @@ -25,7 +30,7 @@ export interface MapMarkerSearchOptions {
fileCreatedAfter?: Date;
}

export interface MapMarker {
export interface MapMarker extends ReverseGeocodeResult {
id: string;
lat: number;
lon: number;
Expand Down
10 changes: 6 additions & 4 deletions server/src/infra/repositories/asset.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ export class AssetRepository implements IAssetRepository {
select: {
id: true,
exifInfo: {
city: true,
state: true,
country: true,
latitude: true,
longitude: true,
},
Expand All @@ -532,12 +535,11 @@ export class AssetRepository implements IAssetRepository {

return assets.map((asset) => ({
id: asset.id,

/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
lat: asset.exifInfo!.latitude!,

/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
lon: asset.exifInfo!.longitude!,
city: asset.exifInfo!.city,
state: asset.exifInfo!.state,
country: asset.exifInfo!.country,
}));
}

Expand Down
3 changes: 3 additions & 0 deletions server/test/fixtures/asset.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ export const assetStub = {
latitude: 100,
longitude: 100,
fileSizeInByte: 23_456,
city: 'test-city',
state: 'test-state',
country: 'test-country',
} as ExifEntity,
deletedAt: null,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ describe('AlbumCard component', () => {
const detailsText = `${count} items` + (shared ? ' . Shared' : '');

expect(albumImgElement).toHaveAttribute('src');
expect(albumImgElement).toHaveAttribute('alt', album.id);
expect(albumImgElement).toHaveAttribute('alt', album.albumName);

await waitFor(() => expect(albumImgElement).toHaveAttribute('src'));

expect(albumImgElement).toHaveAttribute('alt', album.id);
expect(albumImgElement).toHaveAttribute('alt', album.albumName);
expect(sdkMock.getAssetThumbnail).not.toHaveBeenCalled();

expect(albumNameElement).toHaveTextContent(album.albumName);
Expand All @@ -74,11 +74,11 @@ describe('AlbumCard component', () => {
const albumImgElement = sut.getByTestId('album-image');
const albumNameElement = sut.getByTestId('album-name');
const albumDetailsElement = sut.getByTestId('album-details');
expect(albumImgElement).toHaveAttribute('alt', album.id);
expect(albumImgElement).toHaveAttribute('alt', album.albumName);

await waitFor(() => expect(albumImgElement).toHaveAttribute('src', thumbnailUrl));

expect(albumImgElement).toHaveAttribute('alt', album.id);
expect(albumImgElement).toHaveAttribute('alt', album.albumName);
expect(sdkMock.getAssetThumbnail).toHaveBeenCalledTimes(1);
expect(sdkMock.getAssetThumbnail).toHaveBeenCalledWith({
id: 'thumbnailIdOne',
Expand Down
4 changes: 2 additions & 2 deletions web/src/lib/components/album-page/album-card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<img
loading={preload ? 'eager' : 'lazy'}
src={imageData}
alt={album.id}
alt={album.albumName}
class="z-0 h-full w-full rounded-xl object-cover transition-all duration-300 hover:shadow-lg"
data-testid="album-image"
draggable="false"
Expand All @@ -82,7 +82,7 @@
loading={preload ? 'eager' : 'lazy'}
src="$lib/assets/no-thumbnail.png"
sizes="min(271px,186px)"
alt={album.id}
alt={album.albumName}
class="z-0 h-full w-full rounded-xl object-cover transition-all duration-300 hover:shadow-lg"
data-testid="album-image"
draggable="false"
Expand Down
4 changes: 2 additions & 2 deletions web/src/lib/components/asset-viewer/activity-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
<img
class="rounded-lg w-[75px] h-[75px] object-cover"
src={getAssetThumbnailUrl(reaction.assetId, ThumbnailFormat.Webp)}
alt="comment-thumbnail"
alt="Profile picture of {reaction.user.name}, who commented on this asset"
/>
</div>
{/if}
Expand Down Expand Up @@ -241,7 +241,7 @@
<img
class="rounded-lg w-[75px] h-[75px] object-cover"
src={getAssetThumbnailUrl(reaction.assetId, ThumbnailFormat.Webp)}
alt="like-thumbnail"
alt="Profile picture of {reaction.user.name}, who liked this asset"
/>
</div>
{/if}
Expand Down
11 changes: 10 additions & 1 deletion web/src/lib/components/asset-viewer/detail-panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,16 @@
{:then component}
<svelte:component
this={component.default}
mapMarkers={[{ lat: latlng.lat, lon: latlng.lng, id: asset.id }]}
mapMarkers={[
{
lat: latlng.lat,
lon: latlng.lng,
id: asset.id,
city: asset.exifInfo?.city ?? null,
state: asset.exifInfo?.state ?? null,
country: asset.exifInfo?.country ?? null,
},
]}
center={latlng}
zoom={15}
simplified
Expand Down
3 changes: 2 additions & 1 deletion web/src/lib/components/asset-viewer/photo-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { fade } from 'svelte/transition';
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
import { NotificationType, notificationController } from '../shared-components/notification/notification';
import { getAltText } from '$lib/utils/thumbnail-util';

export let asset: AssetResponseDto;
export let element: HTMLDivElement | undefined = undefined;
Expand Down Expand Up @@ -133,7 +134,7 @@
bind:this={$photoViewer}
transition:fade={{ duration: haveFadeTransition ? 150 : 0 }}
src={assetData}
alt={asset.id}
alt={getAltText(asset)}
class="h-full w-full object-contain"
draggable="false"
/>
Expand Down