aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-18 12:12:14 +0100
committerChocobozzz <me@florianbigard.com>2020-11-18 12:12:14 +0100
commit4166caabc6f439a7db7d1e15d64f74b8b694fc6b (patch)
treedbe524c212ea30fdd4843985fa693d22521bbd27 /client/src/app/shared
parent875f0610e42fad6046cc731fed1953cb0a451f38 (diff)
downloadPeerTube-4166caabc6f439a7db7d1e15d64f74b8b694fc6b.tar.gz
PeerTube-4166caabc6f439a7db7d1e15d64f74b8b694fc6b.tar.zst
PeerTube-4166caabc6f439a7db7d1e15d64f74b8b694fc6b.zip
Clearer periods in videos list
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/shared-main/angular/from-now.pipe.ts12
-rw-r--r--client/src/app/shared/shared-video-miniature/abstract-video-list.ts82
2 files changed, 49 insertions, 45 deletions
diff --git a/client/src/app/shared/shared-main/angular/from-now.pipe.ts b/client/src/app/shared/shared-main/angular/from-now.pipe.ts
index 5d85590bb..5e7832807 100644
--- a/client/src/app/shared/shared-main/angular/from-now.pipe.ts
+++ b/client/src/app/shared/shared-main/angular/from-now.pipe.ts
@@ -8,27 +8,27 @@ export class FromNowPipe implements PipeTransform {
8 const argDate = new Date(arg) 8 const argDate = new Date(arg)
9 const seconds = Math.floor((Date.now() - argDate.getTime()) / 1000) 9 const seconds = Math.floor((Date.now() - argDate.getTime()) / 1000)
10 10
11 let interval = Math.floor(seconds / 31536000) 11 let interval = Math.round(seconds / 31536000)
12 if (interval > 1) return $localize`${interval} years ago` 12 if (interval > 1) return $localize`${interval} years ago`
13 if (interval === 1) return $localize`${interval} year ago` 13 if (interval === 1) return $localize`${interval} year ago`
14 14
15 interval = Math.floor(seconds / 2592000) 15 interval = Math.round(seconds / 2592000)
16 if (interval > 1) return $localize`${interval} months ago` 16 if (interval > 1) return $localize`${interval} months ago`
17 if (interval === 1) return $localize`${interval} month ago` 17 if (interval === 1) return $localize`${interval} month ago`
18 18
19 interval = Math.floor(seconds / 604800) 19 interval = Math.round(seconds / 604800)
20 if (interval > 1) return $localize`${interval} weeks ago` 20 if (interval > 1) return $localize`${interval} weeks ago`
21 if (interval === 1) return $localize`${interval} week ago` 21 if (interval === 1) return $localize`${interval} week ago`
22 22
23 interval = Math.floor(seconds / 86400) 23 interval = Math.round(seconds / 86400)
24 if (interval > 1) return $localize`${interval} days ago` 24 if (interval > 1) return $localize`${interval} days ago`
25 if (interval === 1) return $localize`${interval} day ago` 25 if (interval === 1) return $localize`${interval} day ago`
26 26
27 interval = Math.floor(seconds / 3600) 27 interval = Math.round(seconds / 3600)
28 if (interval > 1) return $localize`${interval} hours ago` 28 if (interval > 1) return $localize`${interval} hours ago`
29 if (interval === 1) return $localize`${interval} hour ago` 29 if (interval === 1) return $localize`${interval} hour ago`
30 30
31 interval = Math.floor(seconds / 60) 31 interval = Math.round(seconds / 60)
32 if (interval >= 1) return $localize`${interval} min ago` 32 if (interval >= 1) return $localize`${interval} min ago`
33 33
34 return $localize`just now` 34 return $localize`just now`
diff --git a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts
index 1b5b8a64b..da05e15fb 100644
--- a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts
+++ b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts
@@ -14,7 +14,7 @@ import {
14} from '@app/core' 14} from '@app/core'
15import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' 15import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook'
16import { GlobalIconName } from '@app/shared/shared-icons' 16import { GlobalIconName } from '@app/shared/shared-icons'
17import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' 17import { isLastMonth, isLastWeek, isThisMonth, isToday, isYesterday } from '@shared/core-utils/miscs/date'
18import { ServerConfig, VideoSortField } from '@shared/models' 18import { ServerConfig, VideoSortField } from '@shared/models'
19import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' 19import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type'
20import { Syndication, Video } from '../shared-main' 20import { Syndication, Video } from '../shared-main'
@@ -24,9 +24,10 @@ enum GroupDate {
24 UNKNOWN = 0, 24 UNKNOWN = 0,
25 TODAY = 1, 25 TODAY = 1,
26 YESTERDAY = 2, 26 YESTERDAY = 2,
27 LAST_WEEK = 3, 27 THIS_WEEK = 3,
28 LAST_MONTH = 4, 28 THIS_MONTH = 4,
29 OLDER = 5 29 LAST_MONTH = 5,
30 OLDER = 6
30} 31}
31 32
32@Directive() 33@Directive()
@@ -111,7 +112,8 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor
111 [GroupDate.UNKNOWN]: null, 112 [GroupDate.UNKNOWN]: null,
112 [GroupDate.TODAY]: $localize`Today`, 113 [GroupDate.TODAY]: $localize`Today`,
113 [GroupDate.YESTERDAY]: $localize`Yesterday`, 114 [GroupDate.YESTERDAY]: $localize`Yesterday`,
114 [GroupDate.LAST_WEEK]: $localize`Last week`, 115 [GroupDate.THIS_WEEK]: $localize`This week`,
116 [GroupDate.THIS_MONTH]: $localize`This month`,
115 [GroupDate.LAST_MONTH]: $localize`Last month`, 117 [GroupDate.LAST_MONTH]: $localize`Last month`,
116 [GroupDate.OLDER]: $localize`Older` 118 [GroupDate.OLDER]: $localize`Older`
117 } 119 }
@@ -214,46 +216,48 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor
214 buildGroupedDateLabels () { 216 buildGroupedDateLabels () {
215 let currentGroupedDate: GroupDate = GroupDate.UNKNOWN 217 let currentGroupedDate: GroupDate = GroupDate.UNKNOWN
216 218
217 for (const video of this.videos) { 219 const periods = [
218 const publishedDate = video.publishedAt 220 {
219 221 value: GroupDate.TODAY,
220 if (currentGroupedDate <= GroupDate.TODAY && isToday(publishedDate)) { 222 validator: (d: Date) => isToday(d)
221 if (currentGroupedDate === GroupDate.TODAY) continue 223 },
222 224 {
223 currentGroupedDate = GroupDate.TODAY 225 value: GroupDate.YESTERDAY,
224 this.groupedDates[ video.id ] = currentGroupedDate 226 validator: (d: Date) => isYesterday(d)
225 continue 227 },
226 } 228 {
227 229 value: GroupDate.THIS_WEEK,
228 if (currentGroupedDate <= GroupDate.YESTERDAY && isYesterday(publishedDate)) { 230 validator: (d: Date) => isLastWeek(d)
229 if (currentGroupedDate === GroupDate.YESTERDAY) continue 231 },
230 232 {
231 currentGroupedDate = GroupDate.YESTERDAY 233 value: GroupDate.THIS_MONTH,
232 this.groupedDates[ video.id ] = currentGroupedDate 234 validator: (d: Date) => isThisMonth(d)
233 continue 235 },
236 {
237 value: GroupDate.LAST_MONTH,
238 validator: (d: Date) => isLastMonth(d)
239 },
240 {
241 value: GroupDate.OLDER,
242 validator: () => true
234 } 243 }
244 ]
235 245
236 if (currentGroupedDate <= GroupDate.LAST_WEEK && isLastWeek(publishedDate)) { 246 for (const video of this.videos) {
237 if (currentGroupedDate === GroupDate.LAST_WEEK) continue 247 const publishedDate = video.publishedAt
238
239 currentGroupedDate = GroupDate.LAST_WEEK
240 this.groupedDates[ video.id ] = currentGroupedDate
241 continue
242 }
243 248
244 if (currentGroupedDate <= GroupDate.LAST_MONTH && isLastMonth(publishedDate)) { 249 for (let i = 0; i < periods.length; i++) {
245 if (currentGroupedDate === GroupDate.LAST_MONTH) continue 250 const period = periods[i]
246 251
247 currentGroupedDate = GroupDate.LAST_MONTH 252 if (currentGroupedDate <= period.value && period.validator(publishedDate)) {
248 this.groupedDates[ video.id ] = currentGroupedDate
249 continue
250 }
251 253
252 if (currentGroupedDate <= GroupDate.OLDER) { 254 if (currentGroupedDate !== period.value) {
253 if (currentGroupedDate === GroupDate.OLDER) continue 255 currentGroupedDate = period.value
256 this.groupedDates[ video.id ] = currentGroupedDate
257 }
254 258
255 currentGroupedDate = GroupDate.OLDER 259 break
256 this.groupedDates[ video.id ] = currentGroupedDate 260 }
257 } 261 }
258 } 262 }
259 } 263 }