Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#438 Add option to delete an image #441

Merged
merged 5 commits into from
Nov 21, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
show delete button only to user that uploaded the image
NejcS committed Nov 3, 2022
commit 7f789ce9905d372eb327ad5367345bb19ed67797
2 changes: 1 addition & 1 deletion src/app/common/image-full/image-full.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="full-container">
<div class="buttons-row">
<!-- add check if the user is the author or an admin, else hide the button -->
<button mat-icon-button (click)="onDeleteClick()">
<button mat-icon-button (click)="onDeleteClick()" *ngIf="currentUser && image.user && currentUser.id === image.user.id">
<mat-icon>delete</mat-icon>
</button>
<button mat-icon-button (click)="onCloseClick()">
18 changes: 14 additions & 4 deletions src/app/common/image-full/image-full.component.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
import { Component, HostListener, Inject } from '@angular/core';
import { Component, HostListener, Inject, OnInit } from '@angular/core';
import {
MatDialog,
MatDialogRef,
MAT_DIALOG_DATA,
} from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { take } from 'rxjs';
import { AuthService } from 'src/app/auth/auth.service';
import { ConfirmationDialogComponent } from 'src/app/shared/components/confirmation-dialog/confirmation-dialog.component';
import { environment } from 'src/environments/environment';
import { DeleteImageGQL, Image } from 'src/generated/graphql';
import { DeleteImageGQL, Image, User } from 'src/generated/graphql';

@Component({
selector: 'app-image-full',
templateUrl: './image-full.component.html',
styleUrls: ['./image-full.component.scss'],
})
export class ImageFullComponent {
export class ImageFullComponent implements OnInit {
storageUrl = environment.storageUrl;

images: Image[];

currentImageIndex: number;
image: Image;
currentUser: User;

constructor(
public dialogRef: MatDialogRef<ImageFullComponent>,
@Inject(MAT_DIALOG_DATA)
public data: { images: Image[]; currentImageIndex: number },
private deleteImageGQL: DeleteImageGQL,
private snackBar: MatSnackBar,
private dialog: MatDialog
private dialog: MatDialog,
private authService: AuthService
) {
this.images = this.data.images;
this.currentImageIndex = this.data.currentImageIndex;
this.image = this.images[this.currentImageIndex];
}

ngOnInit() {
this.authService.currentUser
.pipe(take(1))
.subscribe((user) => (this.currentUser = user));
}

/**
* Generate renderSizes parameter here, to make it more readable
* Image is alway rendered 'by width' by the browser.
3 changes: 3 additions & 0 deletions src/app/pages/crag/crag-by-slug.query.graphql
Original file line number Diff line number Diff line change
@@ -92,6 +92,9 @@ query CragBySlug($crag: String!) {
aspectRatio
maxIntrinsicWidth
author
user {
id
}
}
user {
id
3 changes: 3 additions & 0 deletions src/app/pages/route/route.query.graphql
Original file line number Diff line number Diff line change
@@ -65,6 +65,9 @@ query RouteBySlug($cragSlug: String!, $routeSlug: String!) {
aspectRatio
maxIntrinsicWidth
author
user {
id
}
}
sector {
id