Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

chore(frontend): introduce `amLiveTimeAgo` pipe for dynamic time updates, replacing `amTimeAgo` where applicable

johaven725c5dd6dacc
diff --git a/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.html b/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.html
index d5a71f72..1d2cfeb2 100644
--- a/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.html
+++ b/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.html
@@ -26,7 +26,7 @@
<span>{{ c.showedPath }}</span>
</span>
</span>
- <span class="recent-item-card__time">{{ c.modifiedAt | amTimeAgo }}</span>
+ <span class="recent-item-card__time">{{ c.modifiedAt | amLiveTimeAgo }}</span>
</button>
} @empty {
<div class="recent-empty-state">
diff --git a/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.ts b/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.ts
index 2b3fd539..18c1116e 100644
--- a/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.ts
+++ b/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.ts
@@ -4,7 +4,6 @@ import { FaIconComponent } from '@fortawesome/angular-fontawesome'
import { faCommentDots } from '@fortawesome/free-regular-svg-icons'
import { faMagnifyingGlassMinus, faMagnifyingGlassPlus, faTrashAlt } from '@fortawesome/free-solid-svg-icons'
import { L10nTranslateDirective } from 'angular-l10n'
-import { TimeAgoPipe } from '../../../../common/pipes/time-ago.pipe'
import { TAB_MENU } from '../../../../layout/layout.interfaces'
import { LayoutService } from '../../../../layout/layout.service'
import { StoreService } from '../../../../store/store.service'
@@ -12,10 +11,11 @@ import { SPACES_PATH } from '../../../spaces/spaces.constants'
import { UserAvatarComponent } from '../../../users/components/utils/user-avatar.component'
import { CommentRecentModel } from '../../models/comment-recent.model'
import { CommentsService } from '../../services/comments.service'
+import { LiveTimeAgoPipe } from '../../../../common/pipes/time-ago-live.pipe'
@Component({
selector: 'app-comments-recents-widget',
- imports: [L10nTranslateDirective, FaIconComponent, TimeAgoPipe, UserAvatarComponent],
+ imports: [L10nTranslateDirective, FaIconComponent, UserAvatarComponent, LiveTimeAgoPipe],
templateUrl: './comments-recents-widget.component.html',
styleUrl: './comments-recents-widget.component.scss'
})
diff --git a/frontend/src/app/applications/files/components/sidebar/files-tasks.component.html b/frontend/src/app/applications/files/components/sidebar/files-tasks.component.html
index 15460f3d..1d5f0626 100644
--- a/frontend/src/app/applications/files/components/sidebar/files-tasks.component.html
+++ b/frontend/src/app/applications/files/components/sidebar/files-tasks.component.html
@@ -88,7 +88,7 @@
<span>{{ item.value | toBytes:2 }}</span>
}
@case ('endedAt') {
- <span>{{ item.value | amDateFormat:'L HH:mm' }}</span>
+ <span>{{ item.value | amTimeAgo:true }}</span>
}
@default {
<span>{{ item.value }}</span>
diff --git a/frontend/src/app/applications/files/components/sidebar/files-tasks.component.ts b/frontend/src/app/applications/files/components/sidebar/files-tasks.component.ts
index 7f73cdb0..3504f2c9 100644
--- a/frontend/src/app/applications/files/components/sidebar/files-tasks.component.ts
+++ b/frontend/src/app/applications/files/components/sidebar/files-tasks.component.ts
@@ -23,17 +23,17 @@ import { ProgressbarComponent } from 'ngx-bootstrap/progressbar'
import { TooltipModule } from 'ngx-bootstrap/tooltip'
import { Subscription } from 'rxjs'
import { AutoResizeDirective } from '../../../../common/directives/auto-resize.directive'
-import { TimeDateFormatPipe } from '../../../../common/pipes/time-date-format.pipe'
import { ToBytesPipe } from '../../../../common/pipes/to-bytes.pipe'
import { StoreService } from '../../../../store/store.service'
import { SPACES_PATH } from '../../../spaces/spaces.constants'
import type { FileTaskView, TaskProgressItem } from '../../interfaces/file-task-view.interface'
import { FilesTasksService } from '../../services/files-tasks.service'
import { FilesService } from '../../services/files.service'
+import { TimeAgoPipe } from '../../../../common/pipes/time-ago.pipe'
@Component({
selector: 'app-files-tasks',
- imports: [FaIconComponent, L10nTranslatePipe, AutoResizeDirective, TooltipModule, ProgressbarComponent, TimeDateFormatPipe, ToBytesPipe],
+ imports: [FaIconComponent, L10nTranslatePipe, AutoResizeDirective, TooltipModule, ProgressbarComponent, ToBytesPipe, TimeAgoPipe],
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: 'files-tasks.component.html'
})
@@ -114,6 +114,22 @@ export class FilesTasksComponent implements OnDestroy {
this.updateHasCancellableTasks()
}
+ openTask(task: FileTask) {
+ if (task.status !== FileTaskStatus.SUCCESS) return
+ if (task.type === FILE_OPERATION.COMPRESS && task.props.compressInDirectory === false) {
+ this.filesService.downloadTaskArchive(task.id)
+ return
+ } else if (task.type === FILE_OPERATION.DELETE) {
+ if (task.path.startsWith(SPACES_PATH.FILES)) {
+ task.path = task.path.replace(SPACES_PATH.FILES, SPACES_PATH.TRASH)
+ } else if (task.path.startsWith(SPACES_PATH.SHARES)) {
+ // cannot access to the space referenced by the share
+ return
+ }
+ }
+ this.router.navigate([`${SPACES_PATH.SPACES}/${task.path}`], { queryParams: { select: task.name } }).catch(console.error)
+ }
+
private sortTasksForDisplay(tasks: FileTask[]): FileTaskView[] {
return tasks
.map((task: FileTask, index: number) => ({ index, task: this.createTaskView(task) }))
@@ -172,20 +188,4 @@ export class FilesTasksComponent implements OnDestroy {
private updateHasCancellableTasks() {
this.hasCancellableTasks = this.tasks.some((task: FileTaskView) => task.ui.cancellable)
}
-
- openTask(task: FileTask) {
- if (task.status !== FileTaskStatus.SUCCESS) return
- if (task.type === FILE_OPERATION.COMPRESS && task.props.compressInDirectory === false) {
- this.filesService.downloadTaskArchive(task.id)
- return
- } else if (task.type === FILE_OPERATION.DELETE) {
- if (task.path.startsWith(SPACES_PATH.FILES)) {
- task.path = task.path.replace(SPACES_PATH.FILES, SPACES_PATH.TRASH)
- } else if (task.path.startsWith(SPACES_PATH.SHARES)) {
- // cannot access to the space referenced by the share
- return
- }
- }
- this.router.navigate([`${SPACES_PATH.SPACES}/${task.path}`], { queryParams: { select: task.name } }).catch(console.error)
- }
}
diff --git a/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.html b/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.html
index 3b5d4f6f..eaf2ce6e 100644
--- a/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.html
+++ b/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.html
@@ -26,7 +26,7 @@
<span>{{ f.showedPath }}</span>
</span>
</span>
- <span class="recent-item-card__time">{{ f.mtime | amTimeAgo }}</span>
+ <span class="recent-item-card__time">{{ f.mtime | amLiveTimeAgo }}</span>
</button>
} @empty {
<div class="recent-empty-state">
diff --git a/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.ts b/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.ts
index e53e7d48..ba3b04aa 100644
--- a/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.ts
+++ b/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.ts
@@ -4,15 +4,15 @@ import { FaIconComponent } from '@fortawesome/angular-fontawesome'
import { faFileLines } from '@fortawesome/free-regular-svg-icons'
import { faMagnifyingGlassMinus, faMagnifyingGlassPlus, faTrashAlt } from '@fortawesome/free-solid-svg-icons'
import { L10nTranslateDirective } from 'angular-l10n'
-import { TimeAgoPipe } from '../../../../common/pipes/time-ago.pipe'
import { StoreService } from '../../../../store/store.service'
import { SPACES_PATH } from '../../../spaces/spaces.constants'
import { FileRecentModel } from '../../models/file-recent.model'
import { FilesService } from '../../services/files.service'
+import { LiveTimeAgoPipe } from '../../../../common/pipes/time-ago-live.pipe'
@Component({
selector: 'app-files-recents-widget',
- imports: [L10nTranslateDirective, FaIconComponent, TimeAgoPipe],
+ imports: [L10nTranslateDirective, FaIconComponent, LiveTimeAgoPipe],
templateUrl: './files-recents-widget.component.html',
styleUrl: './files-recents-widget.component.scss'
})
diff --git a/frontend/src/app/applications/sync/components/sync-paths.component.html b/frontend/src/app/applications/sync/components/sync-paths.component.html
index 3e2763ab..28ad70c6 100644
--- a/frontend/src/app/applications/sync/components/sync-paths.component.html
+++ b/frontend/src/app/applications/sync/components/sync-paths.component.html
@@ -215,7 +215,7 @@
@case ('lastSync') {
<span class="{{th.value.newly ? 'badge sync-newly-' + s[th.value.newly] : ''}}">
@if (s.newly) {
- {{ s.settings.lastSync | amTimeAgo:true }}
+ {{ s.settings.lastSync | amLiveTimeAgo:true }}
} @else {
{{ 'never' | translate:locale.language }}
}
diff --git a/frontend/src/app/applications/sync/components/sync-paths.component.ts b/frontend/src/app/applications/sync/components/sync-paths.component.ts
index e97f4d95..90922a77 100644
--- a/frontend/src/app/applications/sync/components/sync-paths.component.ts
+++ b/frontend/src/app/applications/sync/components/sync-paths.component.ts
@@ -32,7 +32,6 @@ import { AutoResizeDirective } from '../../../common/directives/auto-resize.dire
import { TableHeaderConfig } from '../../../common/interfaces/table.interface'
import { CapitalizePipe } from '../../../common/pipes/capitalize.pipe'
import { SearchFilterPipe } from '../../../common/pipes/search.pipe'
-import { TimeAgoPipe } from '../../../common/pipes/time-ago.pipe'
import { originalOrderKeyValue } from '../../../common/utils/functions'
import { SortSettings, SortTable } from '../../../common/utils/sort-table'
import { LayoutService } from '../../../layout/layout.service'
@@ -47,6 +46,7 @@ import { SyncPathReportDialogComponent } from './dialogs/sync-path-report.dialog
import { SyncPathSettingsDialogComponent } from './dialogs/sync-path-settings.dialog.component'
import { SyncPathDirectionIconComponent } from './utils/sync-path-direction-icon.component'
import { SyncPathSchedulerComponent } from './utils/sync-path-scheduler.component'
+import { LiveTimeAgoPipe } from '../../../common/pipes/time-ago-live.pipe'
@Component({
selector: 'app-sync-paths',
@@ -61,12 +61,12 @@ import { SyncPathSchedulerComponent } from './utils/sync-path-scheduler.componen
SearchFilterPipe,
SyncPathDirectionIconComponent,
FaIconComponent,
- TimeAgoPipe,
KeyValuePipe,
L10nTranslateDirective,
SyncPathSchedulerComponent,
VirtualScrollComponent,
- CapitalizePipe
+ CapitalizePipe,
+ LiveTimeAgoPipe
],
templateUrl: 'sync-paths.component.html'
})
diff --git a/frontend/src/app/common/pipes/time-ago-live.pipe.ts b/frontend/src/app/common/pipes/time-ago-live.pipe.ts
new file mode 100644
index 00000000..a0a7a863
--- /dev/null
+++ b/frontend/src/app/common/pipes/time-ago-live.pipe.ts
@@ -0,0 +1,99 @@
+import { ChangeDetectorRef, inject, NgZone, OnDestroy, Pipe, PipeTransform } from '@angular/core'
+import { Dayjs } from 'dayjs/esm'
+import { dJs } from '../utils/time'
+
+@Pipe({ name: 'amLiveTimeAgo', pure: false })
+export class LiveTimeAgoPipe implements PipeTransform, OnDestroy {
+ private readonly cdRef = inject(ChangeDetectorRef)
+ private ngZone = inject(NgZone)
+ private currentTimer: number | null
+ private lastTime: number
+ private lastValue: any
+ private lastOmitSuffix?: boolean
+ private lastLocale?: string
+ private lastText: string
+ private formatFn: (d: Dayjs) => string
+
+ format(d: Dayjs) {
+ return d.from(dJs(), this.lastOmitSuffix)
+ }
+
+ transform(value: any, omitSuffix?: boolean, formatFn?: (m: Dayjs) => string): string {
+ if (this.hasChanged(value, omitSuffix)) {
+ this.lastTime = this.getTime(value)
+ this.lastValue = value
+ this.lastOmitSuffix = omitSuffix
+ this.lastLocale = this.getLocale(value)
+ this.formatFn = formatFn || this.format.bind(this)
+ this.removeTimer()
+ this.createTimer()
+ this.lastText = this.formatFn(dJs(value))
+ } else {
+ this.createTimer()
+ }
+
+ return this.lastText
+ }
+
+ ngOnDestroy() {
+ this.removeTimer()
+ }
+
+ private createTimer() {
+ if (this.currentTimer !== null) {
+ return
+ }
+
+ const dayjsInstance = dJs(this.lastValue)
+ const timeToUpdate = this.getSecondsUntilUpdate(dayjsInstance) * 1000
+
+ this.currentTimer = this.ngZone.runOutsideAngular(() => {
+ if (typeof window !== 'undefined') {
+ return window.setTimeout(() => {
+ this.lastText = this.formatFn(dJs(this.lastValue))
+
+ this.currentTimer = null
+ this.ngZone.run(() => this.cdRef.markForCheck())
+ }, timeToUpdate)
+ } else {
+ return null
+ }
+ })
+ }
+
+ private removeTimer() {
+ if (this.currentTimer) {
+ window.clearTimeout(this.currentTimer)
+ this.currentTimer = null
+ }
+ }
+
+ private getSecondsUntilUpdate(dayJsInstance: Dayjs) {
+ const howOld = Math.abs(dJs().diff(dayJsInstance, 'minute'))
+ if (howOld < 5) {
+ return 60
+ } else if (howOld < 180) {
+ return 300
+ } else {
+ return 3600
+ }
+ }
+
+ private hasChanged(value: any, omitSuffix?: boolean): boolean {
+ return this.getTime(value) !== this.lastTime || this.getLocale(value) !== this.lastLocale || omitSuffix !== this.lastOmitSuffix
+ }
+
+ private getTime(value: any): number {
+ if (value instanceof Date) {
+ return value.getTime()
+ } else if (dJs.isDayjs(value)) {
+ return value.valueOf()
+ } else {
+ return dJs(value).valueOf()
+ }
+ }
+
+ private getLocale(value: any): string | null {
+ return dJs.isDayjs(value) ? value.locale() : dJs.locale()
+ }
+}
diff --git a/frontend/src/app/common/pipes/time-ago.pipe.ts b/frontend/src/app/common/pipes/time-ago.pipe.ts
index 8f962e66..9ed4be93 100644
--- a/frontend/src/app/common/pipes/time-ago.pipe.ts
+++ b/frontend/src/app/common/pipes/time-ago.pipe.ts
@@ -1,101 +1,20 @@
-import { ChangeDetectorRef, inject, NgZone, OnDestroy, Pipe, PipeTransform } from '@angular/core'
+import { Pipe, PipeTransform } from '@angular/core'
import { Dayjs } from 'dayjs/esm'
import { dJs } from '../utils/time'
-@Pipe({ name: 'amTimeAgo', pure: false })
-export class TimeAgoPipe implements PipeTransform, OnDestroy {
- private readonly cdRef = inject(ChangeDetectorRef)
- private ngZone = inject(NgZone)
- private currentTimer: number | null
- private lastTime: number
- private lastValue: any
- private lastOmitSuffix: boolean
- private lastLocale?: string
- private lastText: string
- private formatFn: (d: Dayjs) => string
-
- format(d: Dayjs) {
- return d.from(dJs(), this.lastOmitSuffix)
- }
-
+@Pipe({ name: 'amTimeAgo', pure: true })
+export class TimeAgoPipe implements PipeTransform {
transform(value: any, omitSuffix?: boolean, formatFn?: (m: Dayjs) => string): string {
- if (this.hasChanged(value, omitSuffix)) {
- this.lastTime = this.getTime(value)
- this.lastValue = value
- this.lastOmitSuffix = omitSuffix
- this.lastLocale = this.getLocale(value)
- this.formatFn = formatFn || this.format.bind(this)
- this.removeTimer()
- this.createTimer()
- this.lastText = this.formatFn(dJs(value))
- } else {
- this.createTimer()
+ if (!value) {
+ return ''
}
- return this.lastText
- }
-
- ngOnDestroy() {
- this.removeTimer()
- }
+ const dayjsValue = dJs(value)
- private createTimer() {
- if (this.currentTimer) {
- return
+ if (!dayjsValue.isValid()) {
+ return ''
}
- const dayjsInstance = dJs(this.lastValue)
- const timeToUpdate = this.getSecondsUntilUpdate(dayjsInstance) * 1000
-
- this.currentTimer = this.ngZone.runOutsideAngular(() => {
- if (typeof window !== 'undefined') {
- return window.setTimeout(() => {
- this.lastText = this.formatFn(dJs(this.lastValue))
-
- this.currentTimer = null
- this.ngZone.run(() => this.cdRef.markForCheck())
- }, timeToUpdate)
- } else {
- return null
- }
- })
- }
-
- private removeTimer() {
- if (this.currentTimer) {
- window.clearTimeout(this.currentTimer)
- this.currentTimer = null
- }
- }
-
- private getSecondsUntilUpdate(dayJsInstance: Dayjs) {
- const howOld = Math.abs(dJs().diff(dayJsInstance, 'minute'))
- if (howOld < 1) {
- return 1
- } else if (howOld < 60) {
- return 30
- } else if (howOld < 180) {
- return 300
- } else {
- return 3600
- }
- }
-
- private hasChanged(value: any, omitSuffix?: boolean): boolean {
- return this.getTime(value) !== this.lastTime || this.getLocale(value) !== this.lastLocale || omitSuffix !== this.lastOmitSuffix
- }
-
- private getTime(value: any): number {
- if (value instanceof Date) {
- return value.getTime()
- } else if (dJs.isDayjs(value)) {
- return value.valueOf()
- } else {
- return dJs(value).valueOf()
- }
- }
-
- private getLocale(value: any): string | null {
- return dJs.isDayjs(value) ? value.locale() : dJs.locale()
+ return formatFn ? formatFn(dayjsValue) : dayjsValue.from(dJs(), omitSuffix)
}
}