diff --git a/app/Http/Controllers/CollectionController.php b/app/Http/Controllers/CollectionController.php index 588340a35..4fc7dfe65 100644 --- a/app/Http/Controllers/CollectionController.php +++ b/app/Http/Controllers/CollectionController.php @@ -205,4 +205,36 @@ class CollectionController extends Controller ]; }); } + + public function deleteId(Request $request) + { + $this->validate($request, [ + 'collection_id' => 'required|int|min:1|exists:collections,id', + 'post_id' => 'required|int|min:1|exists:statuses,id' + ]); + + $profileId = Auth::user()->profile_id; + $collectionId = $request->input('collection_id'); + $postId = $request->input('post_id'); + + $collection = Collection::whereProfileId($profileId)->findOrFail($collectionId); + $count = $collection->items()->count(); + + if($count == 1) { + abort(400, 'You cannot delete the only post of a collection!'); + } + + $status = Status::whereScope('public') + ->whereIn('type', ['photo', 'photo:album', 'video']) + ->findOrFail($postId); + + $item = CollectionItem::whereCollectionId($collection->id) + ->whereObjectType('App\Status') + ->whereObjectId($status->id) + ->firstOrFail(); + + $item->delete(); + + return 200; + } } diff --git a/public/js/collections.js b/public/js/collections.js index 1d1498c92..7bba7df6d 100644 Binary files a/public/js/collections.js and b/public/js/collections.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index f0ac4d11b..cc4135fe0 100644 Binary files a/public/mix-manifest.json and b/public/mix-manifest.json differ diff --git a/resources/assets/js/components/CollectionComponent.vue b/resources/assets/js/components/CollectionComponent.vue index bf7c4b58f..18d6ccf5b 100644 --- a/resources/assets/js/components/CollectionComponent.vue +++ b/resources/assets/js/components/CollectionComponent.vue @@ -15,7 +15,7 @@

-     - +     @@ -66,14 +66,17 @@ - +

+ Edit Photos + +
-
+
@@ -89,9 +92,34 @@

Only local, public posts can be added

- + + +
+

Select a Photo to Delete

+
+
+
+
+
+
+
+
+ +
+
+ +
@@ -105,6 +133,16 @@ background: rgba(0,0,0,.68); z-index: 300; } + .scrollbar-hidden::-webkit-scrollbar { + display: none; + } + .delete-border { + border: 4px solid #ff0000; + } + .delete-border .square-content { + background-color: red; + background-blend-mode: screen; + } \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index a2dc0bc23..66284debb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -156,6 +156,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('bookmarks', 'InternalApiController@bookmarks'); Route::get('collection/items/{id}', 'CollectionController@getItems'); Route::post('collection/item', 'CollectionController@storeId'); + Route::delete('collection/item', 'CollectionController@deleteId'); Route::get('collection/{id}', 'CollectionController@get'); Route::post('collection/{id}', 'CollectionController@store'); Route::delete('collection/{id}', 'CollectionController@delete')->middleware('throttle:maxCollectionsPerHour,60')->middleware('throttle:maxCollectionsPerDay,1440')->middleware('throttle:maxCollectionsPerMonth,43800');