-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): improve range selection (#3193)
* Improve range selection * Add comments * Add PR feedback * Remove focus outline from select asset button --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
- Loading branch information
1 parent
ea64fdd
commit 93462aa
Showing
5 changed files
with
163 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { AssetResponseDto } from '@api'; | ||
import lodash from 'lodash-es'; | ||
import { DateTime, Interval } from 'luxon'; | ||
|
||
export const groupDateFormat: Intl.DateTimeFormatOptions = { | ||
weekday: 'short', | ||
month: 'short', | ||
day: 'numeric', | ||
year: 'numeric', | ||
}; | ||
|
||
export function 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(groupDateFormat); | ||
} | ||
|
||
export function splitBucketIntoDateGroups( | ||
assets: AssetResponseDto[], | ||
locale: string | undefined, | ||
): AssetResponseDto[][] { | ||
return lodash | ||
.chain(assets) | ||
.groupBy((a) => new Date(a.fileCreatedAt).toLocaleDateString(locale, groupDateFormat)) | ||
.sortBy((group) => assets.indexOf(group[0])) | ||
.value(); | ||
} |