Skip to content

Commit

Permalink
Show if photos are tagged or not
Browse files Browse the repository at this point in the history
  • Loading branch information
GeniJaho committed Jan 5, 2024
1 parent f689f0d commit 6e645df
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/Http/Controllers/PhotosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ public function index()
/** @var User $user */
$user = auth()->user();

$photos = $user->photos()->latest('id')->paginate(12);
$photos = $user
->photos()
->withExists('items')
->latest('id')
->paginate(12);

$photos->getCollection()->transform(function (Photo $photo) {
$photo->append('full_path');
Expand Down
12 changes: 10 additions & 2 deletions resources/js/Pages/Photos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ const photos = ref(props.photos);
<div class="p-6 lg:p-8 bg-white dark:bg-gray-800 dark:bg-gradient-to-bl dark:from-gray-700/50 dark:via-transparent border-b border-gray-200 dark:border-gray-700">

<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
<div v-for="photo in photos.data" :key="photo.id">
<div
v-for="photo in photos.data"
:key="photo.id"
class="relative"
>

<a :href="`/photos/${photo.id}`">
<img :src="photo.full_path" :alt="photo.id" class="w-full h-64 object-cover">
<img :src="photo.full_path" :alt="photo.id" class="w-full h-64 object-cover rounded-lg">
</a>

<span v-if="photo.items_exists" class="absolute top-2 right-2 flex items-center justify-center bg-gray-50/30 w-8 h-8 rounded-full">
<i class="fas fa-tags text-green-500 mt-0.5 ml-0.5"></i>
</span>

</div>
</div>

Expand Down
7 changes: 7 additions & 0 deletions tests/Feature/Photos/ListPhotosTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use App\Models\Item;
use App\Models\Photo;
use App\Models\PhotoItem;
use App\Models\User;
use Inertia\Testing\AssertableInertia;

Expand All @@ -9,6 +11,8 @@

$photoA = Photo::factory()->for($user)->create(['created_at' => now()]);
$photoB = Photo::factory()->for($user)->create(['created_at' => now()->addMinute()]);
$item = Item::factory()->create();
PhotoItem::factory()->for($item)->for($photoB)->create();

$response = $this->get('/my-photos');

Expand All @@ -17,7 +21,10 @@
->component('Photos')
->where('photos.data.0.id', $photoB->id)
->where('photos.data.0.full_path', $photoB->full_path)
->where('photos.data.0.items_exists', true)
->where('photos.data.1.id', $photoA->id)
->where('photos.data.1.full_path', $photoA->full_path)
->where('photos.data.1.items_exists', false)
->etc()
);
});

0 comments on commit 6e645df

Please sign in to comment.