From a22f0c60bb11fc0cc76ba6271db0e32e614765da Mon Sep 17 00:00:00 2001 From: Allan Kong <74692833+AllanKoder@users.noreply.github.com> Date: Tue, 30 Dec 2025 15:13:39 -0700 Subject: [PATCH 1/8] Resource Edits, and Errors Flash (#59) * changes * Apply automatic changes * Update app/Http/Controllers/ResourceEditsController.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Controllers/ResourceEditsController.php | 4 +- app/Http/Middleware/HandleInertiaRequests.php | 1 + app/Models/ResourceEdits.php | 2 +- .../ComputerScienceResourceService.php | 15 ++++--- .../js/Components/Navigation/BackButton.vue | 2 +- resources/js/Components/News/NewsDialog.vue | 10 ++--- resources/js/Components/News/NewsSection.vue | 24 +++++----- resources/js/Components/NewsItem.vue | 44 ++++++++++++------- resources/js/Components/ToastHandler.vue | 8 ++++ resources/js/Pages/ResourceEdits/Create.vue | 4 +- resources/js/Pages/Resources/Index.vue | 5 ++- 11 files changed, 74 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/ResourceEditsController.php b/app/Http/Controllers/ResourceEditsController.php index b69fe3fd..f7390628 100644 --- a/app/Http/Controllers/ResourceEditsController.php +++ b/app/Http/Controllers/ResourceEditsController.php @@ -67,7 +67,7 @@ public function store(ComputerScienceResource $computerScienceResource, StoreRes 'data' => $validatedData, ]); - return redirect()->back()->withErrors(['error' => 'Failed to create resource edit. Please try again.']); + return redirect()->back()->with('error', 'Failed to create resource edit. Please try again.'); } } @@ -137,7 +137,7 @@ public function merge(ResourceEdits $resourceEdits) 'user_id' => Auth::id(), ]); - return redirect()->back()->withErrors(['error' => 'Failed to merge resource edits. Please try again.']); + return redirect()->back()->with('error', 'Failed to merge resource edits. Please try again.'); } } } diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index b0395db1..01fc61e6 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -39,6 +39,7 @@ public function share(Request $request): array 'flash' => [ 'success' => $request->session()->get('success'), 'warning' => $request->session()->get('warning'), + 'error' => $request->session()->get('error'), ], 'config' => [ 'COMMENT_MAX_DEPTH' => config('comment.max_depth'), diff --git a/app/Models/ResourceEdits.php b/app/Models/ResourceEdits.php index f7ac8c8f..3a3ce7fd 100644 --- a/app/Models/ResourceEdits.php +++ b/app/Models/ResourceEdits.php @@ -60,7 +60,7 @@ public function sluggable(): array { return [ 'slug' => [ - 'source' => ['edit_title', 'id'], + 'source' => ['edit_title'], 'unique' => true, ], ]; diff --git a/app/Services/ComputerScienceResourceService.php b/app/Services/ComputerScienceResourceService.php index 22827945..9ede5a6b 100644 --- a/app/Services/ComputerScienceResourceService.php +++ b/app/Services/ComputerScienceResourceService.php @@ -18,6 +18,7 @@ class ComputerScienceResourceService { + // TODO: Make a service for ComputerScienceResources public function __construct( protected CommentService $commentService, protected UpvoteService $upvoteService, @@ -36,19 +37,21 @@ public function __construct( */ public function getIndexData(Request $request): array { - $query = ComputerScienceResource::query(); + $resources_query = ComputerScienceResource::query(); // Apply filters and sorting through the dedicated filter service $filters = $request->query(); - $query = $this->filterService->applyFilters($query, $filters); + $resources_query = $this->filterService->applyFilters($resources_query, $filters); - $resources = $query->paginate(20)->appends($request->query()); + $resources = $resources_query->paginate(20)->appends($request->query()); - $news = NewsPost::limit(10)->get(); + // TODO (TEMP): will replace with user activity or something + $hot_resources_query = ComputerScienceResource::query()->with(['tags', 'votes', 'upvoteSummary', 'reviewSummary', 'commentsCountRelationship']); + $hot_resources = $this->resourceSortingManager->applySort($hot_resources_query, 'hot')->limit(10)->get(); return [ 'resources' => $resources, - 'news_posts' => $news, + 'hot_resources' => $hot_resources, ]; } @@ -152,7 +155,7 @@ function () use ($computerScienceResource, $sortBy, $request) { function () use ($computerScienceResource, $sortBy, $request) { try { $query = ResourceEdits::whereBelongsTo($computerScienceResource); - $query = $this->resourceSortingManager->applySort($query, $sortBy, ResourceEdits::class); + $query = $this->resourceSortingManager->applySort($query, $sortBy); return $query->with('user')->paginate(10)->appends($request->query()); } catch (Throwable $e) { diff --git a/resources/js/Components/Navigation/BackButton.vue b/resources/js/Components/Navigation/BackButton.vue index 5955674b..7599a795 100644 --- a/resources/js/Components/Navigation/BackButton.vue +++ b/resources/js/Components/Navigation/BackButton.vue @@ -18,6 +18,6 @@ const props = defineProps({ -
+
diff --git a/resources/js/Components/News/NewsDialog.vue b/resources/js/Components/News/NewsDialog.vue index 0738e6a4..05549af4 100644 --- a/resources/js/Components/News/NewsDialog.vue +++ b/resources/js/Components/News/NewsDialog.vue @@ -8,7 +8,7 @@ defineProps({ type: Boolean, required: true }, - newsItems: { + resourceItems: { type: Array, required: true } @@ -21,8 +21,8 @@ defineEmits(['close']); @@ -30,9 +30,9 @@ defineEmits(['close']);
diff --git a/resources/js/Components/News/NewsSection.vue b/resources/js/Components/News/NewsSection.vue index 6fc2d68a..4f2195f4 100644 --- a/resources/js/Components/News/NewsSection.vue +++ b/resources/js/Components/News/NewsSection.vue @@ -6,7 +6,7 @@ import { Icon } from "@iconify/vue"; import EmptyState from "../EmptyState.vue"; const props = defineProps({ - newsPosts: { + hotResources: { type: Array, required: true, }, @@ -16,7 +16,7 @@ const showNewsDialog = ref(false); diff --git a/resources/js/Components/NewsItem.vue b/resources/js/Components/NewsItem.vue index e29015b1..6c42692b 100644 --- a/resources/js/Components/NewsItem.vue +++ b/resources/js/Components/NewsItem.vue @@ -1,6 +1,8 @@ diff --git a/resources/js/Components/ToastHandler.vue b/resources/js/Components/ToastHandler.vue index 8fc4afa8..0d8ab73d 100644 --- a/resources/js/Components/ToastHandler.vue +++ b/resources/js/Components/ToastHandler.vue @@ -28,6 +28,14 @@ watch( detail: flash.warning, life: TOAST_LIFETIME, }); + + } else if (flash.error) { + toast.add({ + severity: "error", + summary: "Error", + detail: flash.error, + life: TOAST_LIFETIME, + }); } }, { deep: true }, diff --git a/resources/js/Pages/ResourceEdits/Create.vue b/resources/js/Pages/ResourceEdits/Create.vue index d8a9ffdb..cd22ff64 100644 --- a/resources/js/Pages/ResourceEdits/Create.vue +++ b/resources/js/Pages/ResourceEdits/Create.vue @@ -155,7 +155,9 @@ const submit = async () => { tab: 'edits', }) " - /> + > + Back to {{ props.resource.name }} + @@ -36,7 +36,8 @@ const props = defineProps({ - + +
From 2b5c9867f95927979a3e17b19c7402723102f612 Mon Sep 17 00:00:00 2001 From: AllanKoder <74692833+AllanKoder@users.noreply.github.com> Date: Tue, 30 Dec 2025 23:01:39 +0000 Subject: [PATCH 2/8] Apply automatic changes --- app/Services/ComputerScienceResourceService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Services/ComputerScienceResourceService.php b/app/Services/ComputerScienceResourceService.php index 9ede5a6b..84feb8a4 100644 --- a/app/Services/ComputerScienceResourceService.php +++ b/app/Services/ComputerScienceResourceService.php @@ -5,7 +5,6 @@ use App\Exceptions\Resources\ResourceAlreadyCreatedException; use App\Exceptions\Resources\ResourceInvalidTabException; use App\Models\ComputerScienceResource; -use App\Models\NewsPost; use App\Models\ResourceEdits; use App\Models\ResourceReview; use App\Services\SortingManagers\ResourceSortingManager; @@ -47,8 +46,9 @@ public function getIndexData(Request $request): array // TODO (TEMP): will replace with user activity or something - $hot_resources_query = ComputerScienceResource::query()->with(['tags', 'votes', 'upvoteSummary', 'reviewSummary', 'commentsCountRelationship']); + $hot_resources_query = ComputerScienceResource::query()->with(['tags', 'votes', 'upvoteSummary', 'reviewSummary', 'commentsCountRelationship']); $hot_resources = $this->resourceSortingManager->applySort($hot_resources_query, 'hot')->limit(10)->get(); + return [ 'resources' => $resources, 'hot_resources' => $hot_resources, From ed470d9c81a262789c64c52d251ead409dabbebe Mon Sep 17 00:00:00 2001 From: Allan Kong <74692833+AllanKoder@users.noreply.github.com> Date: Tue, 30 Dec 2025 16:18:45 -0700 Subject: [PATCH 3/8] Update resources/js/Components/NewsItem.vue Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- resources/js/Components/NewsItem.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/Components/NewsItem.vue b/resources/js/Components/NewsItem.vue index 6c42692b..d684fd7e 100644 --- a/resources/js/Components/NewsItem.vue +++ b/resources/js/Components/NewsItem.vue @@ -10,7 +10,7 @@ defineProps({