Skip to content
Merged
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
48 changes: 27 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,33 @@
<!-- 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()) {
<ng-container>
<mat-progress-spinner mode="indeterminate" diameter="14" />
<span>{{ 'Updating' | translate }}...</span>
</ng-container>
} @else if (isPublished()) {
<ng-container>
<mat-icon>flip_to_back</mat-icon>
<span>{{ 'Unpublish' | translate }}</span>
</ng-container>
} @else {
<ng-container>
<mat-icon>publish</mat-icon>
<span>{{ 'Publish!' | translate }}</span>
</ng-container>
}
</button>
</div>
}

Expand Down
9 changes: 7 additions & 2 deletions src/app/components/actionbar/actionbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,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 @@ -54,6 +55,7 @@ import { TranslatePipe } from '../../pipes/translate.pipe';
MatInputModule,
MatSelectModule,
MatAutocompleteModule,
MatProgressSpinnerModule,
ReactiveFormsModule,
MatOptionModule,
RouterLink,
Expand Down Expand Up @@ -304,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