0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-07 00:50:23 -05:00

feat(web): enhance date group title (#3094)

Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
Sergey Kondrikov 2023-07-03 15:04:46 +03:00 committed by GitHub
parent 8fd4edb206
commit 8e18acff85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,7 +9,6 @@
} from '$lib/stores/asset-interaction.store';
import { assetStore } from '$lib/stores/assets.store';
import { locale } from '$lib/stores/preferences.store';
import { getAssetRatio } from '$lib/utils/asset-utils';
import type { AssetResponseDto } from '@api';
import justifiedLayout from 'justified-layout';
import lodash from 'lodash-es';
@ -17,6 +16,8 @@
import CheckCircle from 'svelte-material-icons/CheckCircle.svelte';
import CircleOutline from 'svelte-material-icons/CircleOutline.svelte';
import { fly } from 'svelte/transition';
import { DateTime, Interval } from 'luxon';
import { getAssetRatio } from '$lib/utils/asset-utils';
import Thumbnail from '../assets/thumbnail/thumbnail.svelte';
export let assets: AssetResponseDto[];
@ -161,6 +162,41 @@
dispatch('selectAssetCandidates', { asset });
}
};
const formatGroupTitle = (date: DateTime): string => {
const today = DateTime.now().startOf('day');
// Today
if (today.hasSame(date, 'day')) {
return 'Today';
}
// Yesterday
if (Interval.fromDateTimes(date, today).length('days') == 1) {
return 'Yesterday';
}
// Last week
if (Interval.fromDateTimes(date, today).length('weeks') < 1) {
return date.toLocaleString({ weekday: 'long' });
}
// This year
if (today.hasSame(date, 'year')) {
return date.toLocaleString({
weekday: 'short',
month: 'short',
day: 'numeric',
});
}
return date.toLocaleString({
weekday: 'short',
month: 'short',
day: 'numeric',
year: 'numeric',
});
};
</script>
<section
@ -170,7 +206,7 @@
bind:clientWidth={viewportWidth}
>
{#each assetsGroupByDate as assetsInDateGroup, groupIndex (assetsInDateGroup[0].id)}
{@const dateGroupTitle = new Date(assetsInDateGroup[0].fileCreatedAt).toLocaleDateString($locale, groupDateFormat)}
{@const dateGroupTitle = formatGroupTitle(DateTime.fromISO(assetsInDateGroup[0].fileCreatedAt).startOf('day'))}
<!-- Asset Group By Date -->
<div
@ -204,7 +240,7 @@
</div>
{/if}
<span class="truncate" title={dateGroupTitle}>
<span class="first-letter:capitalize truncate" title={dateGroupTitle}>
{dateGroupTitle}
</span>
</p>