Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions src/app/components/actionbar/actionbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@
<!-- Publishing option -->
@if (isAuthenticated() && isEditingAllowed() && isDetailPage()) {
<div>
@if (isPublished()) {
<button
mat-flat-button
color="primary"
[matTooltip]="'Published. Click to unpublish!' | translate"
(click)="togglePublished()"
>
<mat-icon>flip_to_back</mat-icon>
{{ 'Unpublish' | translate }}
</button>
} @else {
<button
mat-flat-button
color="primary"
[matTooltip]="'Not public. Click to publish!' | translate"
(click)="togglePublished()"
>
<mat-icon>publish</mat-icon>
{{ 'Publish!' | translate }}
</button>
}
<button
mat-flat-button
color="primary"
[matTooltip]="
(isPublished() ? 'Published. Click to unpublish!' : 'Not public. Click to publish!')
| translate
"
[disabled]="isUpdatingPublishState()"
(click)="togglePublished()"
>
@if (isUpdatingPublishState()) {
<mat-progress-spinner mode="indeterminate" diameter="14" />
<span>{{ 'Updating' | translate }}...</span>
} @else {
<mat-icon [fontIcon]="isPublished() ? 'flip_to_back' : 'publish'" />
<span>{{ (isPublished() ? 'Unpublish' : 'Publish!') | translate }}</span>
}
</button>
</div>
}

Expand Down
19 changes: 8 additions & 11 deletions src/app/components/actionbar/actionbar.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
filter,
firstValueFrom,
map,
of,
shareReplay,
switchMap,
tap,
} from 'rxjs';
import { filter, firstValueFrom, map, of, shareReplay, switchMap, tap } from 'rxjs';

import { Component, computed, input, signal } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Expand Down Expand Up @@ -47,6 +39,7 @@ import {
} from 'src/app/services';
import { IsUserOfRolePipe } from '../../pipes/is-user-of-role.pipe';
import { TranslatePipe } from '../../pipes/translate.pipe';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';

@Component({
selector: 'app-actionbar',
Expand All @@ -62,6 +55,7 @@ import { TranslatePipe } from '../../pipes/translate.pipe';
MatInputModule,
MatSelectModule,
MatAutocompleteModule,
MatProgressSpinnerModule,
ReactiveFormsModule,
MatOptionModule,
RouterLink,
Expand Down Expand Up @@ -312,25 +306,28 @@ export class ActionbarComponent {
return element && 'online' in element ? !!element.online : false;
});

isUpdatingPublishState = signal(false);
public async togglePublished() {
this.isUpdatingPublishState.set(true);
const element = this.element();
if (isEntity(element)) {
this.backend
await this.backend
.pushEntity({ ...element, online: !element.online })
.then(result => {
console.log('Toggled?:', result);
if (isEntity(result)) this.updatedElement.set(result);
})
.catch(error => console.error(error));
} else if (isCompilation(element)) {
this.backend
await this.backend
.pushCompilation({ ...element, online: !element.online })
.then(result => {
console.log('Toggled?:', result);
if (isCompilation(result)) this.updatedElement.set(result);
})
.catch(error => console.error(error));
}
this.isUpdatingPublishState.set(false);
}

public copyEmbed() {
Expand Down
16 changes: 16 additions & 0 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ h5 {
width: 100%;
}

// Allows for @if/@else blocks inside of Angular Material buttons
.mdc-button span.mdc-button__label {
display: flex;
align-items: center;
gap: 4px;
}

// If progress spinner is inside of a disabled element (e.g. button), adapt color to disabled state
*[disabled] {
@include mat.progress-spinner-overrides(
(
active-indicator-color: gray,
)
);
}

.mat-mdc-fab.mat-primary,
.mat-mdc-unelevated-button.mat-primary,
.mat-mdc-mini-fab.mat-primary,
Expand Down
Loading