From d9729e5fb703373da104f2df39ded96f493f9511 Mon Sep 17 00:00:00 2001 From: Micah Shackelford Date: Sun, 14 Jan 2024 15:09:54 -0600 Subject: [PATCH] feat: group images on index, show reaction counts on index, show number of images in group on index --- app/Http/Controllers/ShotController.php | 13 ++++++++++- config/features.php | 2 +- resources/js/Pages/Shots/Index.vue | 30 +++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ShotController.php b/app/Http/Controllers/ShotController.php index fca60b9..7244613 100644 --- a/app/Http/Controllers/ShotController.php +++ b/app/Http/Controllers/ShotController.php @@ -17,7 +17,18 @@ class ShotController extends Controller public function index(Request $request) { return Inertia::render('Shots/Index', [ - 'shots' => fn () => $request->user()->shots()->orderByDesc("id")->get(), + 'shots' => fn () => $request->user()->shots() + ->orderByDesc("id") + ->whereNull("parent_shot_id") + ->with('childShots') + ->with('reactions', fn($reactionQuery) => $reactionQuery + ->select('reaction', DB::raw('count(*) as count'), 'shot_id') + ->groupBy('reaction', 'shot_id')) + ->get() + ->map(fn($shot) => array_merge($shot->toArray(), [ + 'reactions' => $shot['reactions'] + ->mapWithKeys(fn($result) => [$result['reaction'] => $result['count']]), + ])), ]); } diff --git a/config/features.php b/config/features.php index a6e4678..22dab06 100644 --- a/config/features.php +++ b/config/features.php @@ -4,5 +4,5 @@ * A collection of feature flags to enable/disable select functionality */ return [ - 'reactions' => env("FEATURE_REACTIONS", true), + 'reactions' => env("FEATURE_REACTIONS", false), ]; diff --git a/resources/js/Pages/Shots/Index.vue b/resources/js/Pages/Shots/Index.vue index 09f7ed9..c75aeed 100644 --- a/resources/js/Pages/Shots/Index.vue +++ b/resources/js/Pages/Shots/Index.vue @@ -4,8 +4,9 @@ import { Link, Head } from '@inertiajs/vue3' import Macy from "macy" import { ref } from 'vue'; import { onMounted } from 'vue'; +import { HandThumbUpIcon, HandThumbDownIcon, PhotoIcon } from "@heroicons/vue/24/outline" -defineProps({ +const props = defineProps({ shots: Array }) @@ -25,13 +26,38 @@ onMounted(() => { + + + You haven't uploaded any shots! + + - + + + + + + + {{ shot.reactions?.upvote }} + + + + {{ shot.reactions?.downvote }} + + + + + + {{ shot.child_shots.length + 1 }} + +