-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract relative time component for reuse
- Loading branch information
Showing
6 changed files
with
94 additions
and
25 deletions.
There are no files selected for viewing
8 changes: 3 additions & 5 deletions
8
...res/in-app-notifications/entry/actors-line/in-app-notification-actors-line.component.html
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
5 changes: 5 additions & 0 deletions
5
...in-app-notifications/entry/relative-time/in-app-notification-relative-time.component.html
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,5 @@ | ||
<div | ||
class="op-ian-relative-time" | ||
[title]="fixedTime" | ||
[textContent]="relativeTime$ | async"> | ||
</div> |
6 changes: 6 additions & 0 deletions
6
...in-app-notifications/entry/relative-time/in-app-notification-relative-time.component.sass
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,6 @@ | ||
@import "helpers" | ||
|
||
.op-ian-relative-time | ||
@include text-shortener | ||
max-width: 100% | ||
line-height: 1rem |
63 changes: 63 additions & 0 deletions
63
...s/in-app-notifications/entry/relative-time/in-app-notification-relative-time.component.ts
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,63 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
Input, | ||
OnInit, | ||
ViewEncapsulation, | ||
} from '@angular/core'; | ||
import { TimezoneService } from 'core-app/core/datetime/timezone.service'; | ||
import { I18nService } from 'core-app/core/i18n/i18n.service'; | ||
import { INotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model'; | ||
import { Observable, timer } from 'rxjs'; | ||
import { distinctUntilChanged, map } from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'op-in-app-notification-relative-time', | ||
templateUrl: './in-app-notification-relative-time.component.html', | ||
styleUrls: ['./in-app-notification-relative-time.component.sass'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class InAppNotificationRelativeTimeComponent implements OnInit { | ||
@Input() notification:INotification; | ||
@Input() hasActorByLine:boolean = true; | ||
|
||
// Fixed notification time | ||
fixedTime:string; | ||
|
||
// Format relative elapsed time (n seconds/minutes/hours ago) | ||
// at an interval for auto updating | ||
relativeTime$:Observable<string>; | ||
|
||
text = { | ||
updated_by_at: (age:string):string => this.I18n.t( | ||
'js.notifications.center.text_update_date_by', | ||
{ date: age }, | ||
), | ||
}; | ||
|
||
constructor( | ||
private I18n:I18nService, | ||
private timezoneService:TimezoneService, | ||
) { } | ||
|
||
ngOnInit():void { | ||
this.buildTime(); | ||
} | ||
|
||
private buildTime() { | ||
this.fixedTime = this.timezoneService.formattedDatetime(this.notification.createdAt); | ||
this.relativeTime$ = timer(0, 10000) | ||
.pipe( | ||
map(() => { | ||
const time = this.timezoneService.formattedRelativeDateTime(this.notification.createdAt); | ||
if (this.hasActorByLine && this.notification._links.actor) { | ||
return this.text.updated_by_at(time); | ||
} | ||
|
||
return time; | ||
}), | ||
distinctUntilChanged(), | ||
); | ||
} | ||
} |
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