From 9f97c763bc5a2d3337aa1659e0bf1e37843c4cd4 Mon Sep 17 00:00:00 2001 From: Allan Kong Date: Sat, 13 Sep 2025 20:21:51 -0600 Subject: [PATCH 1/4] Home Page --- app/Http/Controllers/HomeController.php | 23 ++ app/Services/HomeStatisticsService.php | 60 +++++ ...er_science_resources_difficulty_to_set.php | 7 +- .../js/Components/ApplicationHeaderLogo.vue | 4 +- resources/js/Components/CoverflowGallery.vue | 217 +++++++++++++++ resources/js/Components/Navigation/Navbar.vue | 2 +- resources/js/Pages/Home.vue | 252 ++++++++++++++++++ routes/web.php | 5 +- 8 files changed, 564 insertions(+), 6 deletions(-) create mode 100644 app/Http/Controllers/HomeController.php create mode 100644 app/Services/HomeStatisticsService.php create mode 100644 resources/js/Components/CoverflowGallery.vue create mode 100644 resources/js/Pages/Home.vue diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php new file mode 100644 index 00000000..ff43bb59 --- /dev/null +++ b/app/Http/Controllers/HomeController.php @@ -0,0 +1,23 @@ +homeStatistics->getStatistics(); + + return Inertia::render('Home', + $stats + ); + } +} diff --git a/app/Services/HomeStatisticsService.php b/app/Services/HomeStatisticsService.php new file mode 100644 index 00000000..467343d3 --- /dev/null +++ b/app/Services/HomeStatisticsService.php @@ -0,0 +1,60 @@ +url($path) : null; + } + + private function resourceTop(): Collection + { + return DB::table('computer_science_resources') + ->whereNotNull('image_path') + ->limit(10) + ->get() + ->map(fn($res) => [ + 'id' => $res->id, + 'image_url' => $this->getPublicUrl($res->image_path), + ]); + } + + private function resourcesCount(): int + { + return DB::table('computer_science_resources')->count(); + } + + private function topTopics(): Collection + { + return DB::table('tag_frequencies')->where('type','topics_tags') + ->orderByDesc('count')->limit(10)->get(); + } + + private function topicsCount(): int + { + return DB::table('tag_frequencies')->where('type','topics_tags')->count(); + } + + + public function getStatistics() + { + return array( + "resources_top" => $this->resourceTop(), + "resources_count" => $this->resourcesCount(), + "topics_count" => $this->topicsCount(), + "topics_top" => $this->topTopics() + ); + } + +} diff --git a/database/migrations/2025_09_06_223541_change_computer_science_resources_difficulty_to_set.php b/database/migrations/2025_09_06_223541_change_computer_science_resources_difficulty_to_set.php index 4092301a..b22dcf7a 100644 --- a/database/migrations/2025_09_06_223541_change_computer_science_resources_difficulty_to_set.php +++ b/database/migrations/2025_09_06_223541_change_computer_science_resources_difficulty_to_set.php @@ -22,7 +22,12 @@ public function up(): void public function down(): void { - // Rollback: rename back and revert type + // Keep only the first value from the SET + DB::statement(" + UPDATE computer_science_resources + SET difficulties = SUBSTRING_INDEX(difficulties, ',', 1) + "); + DB::statement(" ALTER TABLE computer_science_resources CHANGE difficulties difficulty ENUM( diff --git a/resources/js/Components/ApplicationHeaderLogo.vue b/resources/js/Components/ApplicationHeaderLogo.vue index 12705d91..e2719d60 100644 --- a/resources/js/Components/ApplicationHeaderLogo.vue +++ b/resources/js/Components/ApplicationHeaderLogo.vue @@ -1,4 +1,4 @@ diff --git a/resources/js/Components/CoverflowGallery.vue b/resources/js/Components/CoverflowGallery.vue new file mode 100644 index 00000000..524e8118 --- /dev/null +++ b/resources/js/Components/CoverflowGallery.vue @@ -0,0 +1,217 @@ + + + + + + diff --git a/resources/js/Components/Navigation/Navbar.vue b/resources/js/Components/Navigation/Navbar.vue index 7dd947ea..b46081e2 100644 --- a/resources/js/Components/Navigation/Navbar.vue +++ b/resources/js/Components/Navigation/Navbar.vue @@ -26,7 +26,7 @@ const { isDark, toggleDark } = useDarkMode();
- +
diff --git a/resources/js/Pages/Home.vue b/resources/js/Pages/Home.vue new file mode 100644 index 00000000..ad897cca --- /dev/null +++ b/resources/js/Pages/Home.vue @@ -0,0 +1,252 @@ + + + diff --git a/routes/web.php b/routes/web.php index 5cb65b28..e6ec46fb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use App\Http\Controllers\CommentController; use App\Http\Controllers\ComputerScienceResourceController; +use App\Http\Controllers\HomeController; use App\Http\Controllers\ResourceEditsController; use App\Http\Controllers\ResourceReviewController; use App\Http\Controllers\TagFrequencyController; @@ -51,8 +52,8 @@ // Public // ----------------------- Route::middleware('guest.or.verified')->group(function () { - Route::get('/', function () { - return redirect('/resources'); + Route::controller(HomeController::class)->group(function () { + Route::get('/', 'show')->name('home.show'); }); Route::get('/about', function () { From 7a5af245a8128868397fe841197862054aeeb8b5 Mon Sep 17 00:00:00 2001 From: AllanKoder <74692833+AllanKoder@users.noreply.github.com> Date: Sun, 14 Sep 2025 02:22:17 +0000 Subject: [PATCH 2/4] Apply automatic changes --- app/Http/Controllers/HomeController.php | 3 +-- app/Services/HomeStatisticsService.php | 29 ++++++++++--------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index ff43bb59..722d51c7 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -3,14 +3,13 @@ namespace App\Http\Controllers; use App\Services\HomeStatisticsService; -use Illuminate\Http\Request; use Inertia\Inertia; class HomeController extends Controller { public function __construct( protected HomeStatisticsService $homeStatistics - ){} + ) {} public function show() { diff --git a/app/Services/HomeStatisticsService.php b/app/Services/HomeStatisticsService.php index 467343d3..c03de640 100644 --- a/app/Services/HomeStatisticsService.php +++ b/app/Services/HomeStatisticsService.php @@ -2,19 +2,16 @@ namespace App\Services; -use App\Models\ComputerScienceResource; use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; class HomeStatisticsService { - public function __construct() - { - - } + public function __construct() {} - function getPublicUrl(?string $path): ?string { + public function getPublicUrl(?string $path): ?string + { return $path ? Storage::disk('public')->url($path) : null; } @@ -24,7 +21,7 @@ private function resourceTop(): Collection ->whereNotNull('image_path') ->limit(10) ->get() - ->map(fn($res) => [ + ->map(fn ($res) => [ 'id' => $res->id, 'image_url' => $this->getPublicUrl($res->image_path), ]); @@ -37,24 +34,22 @@ private function resourcesCount(): int private function topTopics(): Collection { - return DB::table('tag_frequencies')->where('type','topics_tags') + return DB::table('tag_frequencies')->where('type', 'topics_tags') ->orderByDesc('count')->limit(10)->get(); } private function topicsCount(): int { - return DB::table('tag_frequencies')->where('type','topics_tags')->count(); + return DB::table('tag_frequencies')->where('type', 'topics_tags')->count(); } - public function getStatistics() { - return array( - "resources_top" => $this->resourceTop(), - "resources_count" => $this->resourcesCount(), - "topics_count" => $this->topicsCount(), - "topics_top" => $this->topTopics() - ); + return [ + 'resources_top' => $this->resourceTop(), + 'resources_count' => $this->resourcesCount(), + 'topics_count' => $this->topicsCount(), + 'topics_top' => $this->topTopics(), + ]; } - } From 09959e385cec15f60f9a68e550083abd92b2bd80 Mon Sep 17 00:00:00 2001 From: Allan Kong <74692833+AllanKoder@users.noreply.github.com> Date: Sat, 13 Sep 2025 20:24:49 -0600 Subject: [PATCH 3/4] Update database/migrations/2025_09_06_223541_change_computer_science_resources_difficulty_to_set.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- ...23541_change_computer_science_resources_difficulty_to_set.php | 1 + 1 file changed, 1 insertion(+) diff --git a/database/migrations/2025_09_06_223541_change_computer_science_resources_difficulty_to_set.php b/database/migrations/2025_09_06_223541_change_computer_science_resources_difficulty_to_set.php index b22dcf7a..6be509b3 100644 --- a/database/migrations/2025_09_06_223541_change_computer_science_resources_difficulty_to_set.php +++ b/database/migrations/2025_09_06_223541_change_computer_science_resources_difficulty_to_set.php @@ -26,6 +26,7 @@ public function down(): void DB::statement(" UPDATE computer_science_resources SET difficulties = SUBSTRING_INDEX(difficulties, ',', 1) + WHERE difficulties IS NOT NULL AND difficulties != '' "); DB::statement(" From a2492d439db126341a68691ef073ab9ad8e7a207 Mon Sep 17 00:00:00 2001 From: Allan Kong Date: Sat, 13 Sep 2025 20:26:46 -0600 Subject: [PATCH 4/4] nits --- resources/js/Components/CoverflowGallery.vue | 12 ++++++------ resources/js/Pages/Home.vue | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/resources/js/Components/CoverflowGallery.vue b/resources/js/Components/CoverflowGallery.vue index 524e8118..01fd7650 100644 --- a/resources/js/Components/CoverflowGallery.vue +++ b/resources/js/Components/CoverflowGallery.vue @@ -18,6 +18,7 @@ const root = ref(null) const containerWidth = ref(0) let rafId = null let lastTs = 0 +let roRef = null // compute slide width so exactly three slides can fit comfortably const slideGap = 14 // px gap between slides (slightly smaller gap) @@ -123,18 +124,17 @@ onMounted(() => { measure() window.addEventListener('resize', measure) // observe the root for layout changes (images/font load) - const ro = new ResizeObserver(measure) - if (root.value) ro.observe(root.value) - ;(root.value || {}).__ro = ro + roRef = new ResizeObserver(measure) + if (root.value) roRef.observe(root.value) play() }) onBeforeUnmount(() => { pause() window.removeEventListener('resize', measure) - if (root.value && root.value.__ro) { - try { root.value.__ro.disconnect() } catch (e) {} - delete root.value.__ro + if (roRef) { + try { roRef.disconnect() } catch (e) {} + roRef = null } }) diff --git a/resources/js/Pages/Home.vue b/resources/js/Pages/Home.vue index ad897cca..43d886a4 100644 --- a/resources/js/Pages/Home.vue +++ b/resources/js/Pages/Home.vue @@ -5,8 +5,8 @@ import AppLayout from "@/Layouts/AppLayout.vue"; import { Head } from "@inertiajs/vue3"; import CoverflowGallery from "@/Components/CoverflowGallery.vue"; import { Link } from "@inertiajs/vue3"; -import SecondaryButton from "@/Components/SecondaryButton.vue"; import ApplicationLogo from "@/Components/ApplicationLogo.vue"; +import PrimaryButton from "@/Components/PrimaryButton.vue"; const props = defineProps({ resources_top: Object, @@ -95,9 +95,9 @@ const fmt = (n) => new Intl.NumberFormat().format(Number(n || 0));
- + Explore Resources - +