Skip to content

Commit

Permalink
fix: various fixes on subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Dec 19, 2024
1 parent c8ce8fe commit e21ae72
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,5 @@
>
<ng-icon name="iconoirBadgeCheck"></ng-icon>
</gn-ui-button> -->
<md-editor-publish-button
[publishWarning]="publishWarning"
></md-editor-publish-button>
<md-editor-publish-button></md-editor-publish-button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import {
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TopToolbarComponent {
@Input() publishWarning = []
protected SaveStatus = [
'draft_only', // => when creating a record
'record_up_to_date', // => when the record was just published (ie saved on the server)
Expand Down
13 changes: 3 additions & 10 deletions apps/metadata-editor/src/app/edit/edit-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,21 @@
</aside>
<div class="flex flex-col h-full w-full">
<div class="w-full h-auto shrink-0 relative">
<<<<<<< HEAD
<md-editor-top-toolbar></md-editor-top-toolbar>
<div class="absolute top-full left-0 w-2/3 z-50 pointer-events-none">
=======
<md-editor-top-toolbar
[publishWarning]="hasRecordChanged$ | async"
></md-editor-top-toolbar>
<div class="absolute top-full left-0 w-2/3 z-10 pointer-events-none">
>>>>>>> 4aeaddd7f (feat: warning in toolbar)
<gn-ui-notifications-container></gn-ui-notifications-container>
</div>
</div>
<div class="grow overflow-auto p-[32px]" #scrollContainer>
<div class="container-lg mx-auto flex flex-col gap-[32px]">
<div *ngIf="hasRecordChanged$ | async as hasChanged">
<div
*ngIf="hasChanged.length > 0"
*ngIf="hasChanged.user && hasChanged.date"
class="p-4 border border-primary bg-primary-lightest rounded-lg text-center"
translate
[translateParams]="{
date: hasChanged[0],
user: hasChanged[1]
date: formatDate(hasChanged.date),
user: hasChanged.user
}"
data-test="draft-alert"
>
Expand Down
18 changes: 17 additions & 1 deletion apps/metadata-editor/src/app/edit/edit-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ export class EditPageComponent implements OnInit, OnDestroy {
})
)

this.subscription.add(
this.facade.record$.subscribe((record) => {
this.facade.checkHasRecordChanged(record)
})
)

// if we're on the /create route, go to /edit/{uuid} on first change
if (this.route.snapshot.routeConfig?.path.includes('create')) {
this.subscription.add(
Expand Down Expand Up @@ -165,7 +171,7 @@ export class EditPageComponent implements OnInit, OnDestroy {

this.subscription.add(
this.facade.record$.subscribe((record) => {
this.facade.hasRecordChangedSinceDraft(record)
this.facade.checkHasRecordChanged(record)
})
)
}
Expand Down Expand Up @@ -199,4 +205,14 @@ export class EditPageComponent implements OnInit, OnDestroy {
top: 0,
})
}

formatDate(date: Date): string {
return date.toLocaleDateString(this.translateService.currentLang, {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
})
}
}

0 comments on commit e21ae72

Please sign in to comment.