Skip to content

Commit de6c570

Browse files
committed
add route for resource viewing with resource viewing support
1 parent ed3fd06 commit de6c570

3 files changed

Lines changed: 128 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Resource;
6+
use Illuminate\Http\Request;
7+
use Inertia\Inertia;
8+
9+
class ResourceController extends Controller
10+
{
11+
//
12+
13+
function show (Resource $resource){
14+
return Inertia::render('Resource', [
15+
'resource'=>$resource
16+
]);
17+
}
18+
}

‎resources/js/pages/Resource.vue‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<script setup>
2+
import {
3+
FileText,
4+
Image as ImageIcon,
5+
Download,
6+
AlertCircle,
7+
ArrowLeft
8+
} from 'lucide-vue-next';
9+
10+
defineProps({
11+
resource: {
12+
type: Object,
13+
required: true,
14+
},
15+
});
16+
17+
// Safe browser back trigger
18+
const handleBack = () => {
19+
if (typeof window !== 'undefined') {
20+
window.history.back();
21+
}
22+
};
23+
</script>
24+
25+
<template>
26+
<div class="mx-auto max-w-4xl px-4 pt-8 pb-20 sm:px-6 sm:pt-12 min-h-[75vh] flex flex-col justify-start">
27+
28+
<div class="mb-6">
29+
<button
30+
@click="handleBack"
31+
class="inline-flex items-center gap-2 text-xs font-bold text-slate-500 transition-colors hover:text-indigo-600 group"
32+
>
33+
<ArrowLeft class="h-4 w-4 transition-transform duration-200 group-hover:-translate-x-0.5" />
34+
Back
35+
</button>
36+
</div>
37+
38+
<div class="w-full overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm">
39+
40+
<div class="border-b border-slate-100 bg-slate-50/50 p-5 sm:p-6">
41+
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
42+
<div class="min-w-0">
43+
<span class="inline-flex items-center gap-1.5 rounded-md bg-slate-100 px-2 py-1 text-xs font-bold uppercase tracking-wider text-slate-600">
44+
<FileText v-if="resource.resource_type === 'note'" class="h-3 w-3" />
45+
<ImageIcon v-else-if="resource.resource_type === 'image'" class="h-3 w-3" />
46+
<Download v-else class="h-3 w-3" />
47+
{{ resource.resource_type }}
48+
</span>
49+
<h1 class="mt-2 text-xl font-black tracking-tight text-slate-950 sm:text-2xl">
50+
{{ resource.title }}
51+
</h1>
52+
</div>
53+
</div>
54+
</div>
55+
56+
<div v-if="resource.resource_type === 'note'" class="p-6 sm:p-8">
57+
<div class="prose max-w-none text-sm font-medium leading-relaxed text-slate-700 sm:text-base">
58+
<p class="whitespace-pre-line selection:bg-indigo-100 selection:text-indigo-900">
59+
{{ resource.content }}
60+
</p>
61+
</div>
62+
</div>
63+
64+
<div v-else-if="resource.resource_type === 'image'" class="bg-slate-950/5 p-4 sm:p-8 flex justify-center">
65+
<div class="relative overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm transition-shadow duration-300 hover:shadow-md">
66+
<img
67+
:src="resource.file_url"
68+
:alt="resource.title"
69+
class="max-h-[70vh] w-auto object-contain select-none"
70+
/>
71+
</div>
72+
</div>
73+
74+
<div v-else class="p-6 sm:p-10 text-center">
75+
<div class="mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-amber-50 text-amber-600 border border-amber-200">
76+
<AlertCircle class="h-6 w-6 stroke-[2.2]" />
77+
</div>
78+
79+
<h3 class="mt-4 text-base font-bold text-slate-900">
80+
Unsupported Preview: <span class="capitalize text-indigo-600">{{ resource.resource_type }}</span>
81+
</h3>
82+
<p class="mx-auto mt-2 max-w-sm text-xs font-medium text-slate-500 sm:text-sm">
83+
This file configuration isn't built for inline web reading. Grab a direct copy to view it on your system.
84+
</p>
85+
86+
<div class="mt-6 flex justify-center">
87+
<a
88+
v-if="resource.file_url"
89+
:href="resource.file_url"
90+
download
91+
target="_blank"
92+
class="inline-flex touch-manipulation items-center gap-2 rounded-xl bg-indigo-600 px-5 py-3 text-xs font-bold text-white shadow-sm transition-all duration-200 hover:bg-indigo-700 active:scale-[0.98]"
93+
>
94+
<Download class="h-4 w-4 stroke-[2.5]" />
95+
Download File Resource
96+
</a>
97+
<div
98+
v-else
99+
class="rounded-lg border border-dashed border-slate-200 bg-slate-50 px-4 py-2 text-xs font-semibold text-slate-400"
100+
>
101+
No download target generated for this asset.
102+
</div>
103+
</div>
104+
</div>
105+
106+
</div>
107+
</div>
108+
</template>

‎routes/web.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
22

33
use App\Http\Controllers\NodeController;
4+
use App\Http\Controllers\ResourceController;
45
use App\Http\Controllers\SubjectController;
56
use Illuminate\Support\Facades\Route;
67

78
Route::get('/', [SubjectController::class, 'index']);
9+
Route::get('/resources/{resource:id}', [ResourceController::class, 'show']);
810
Route::get('/{subject:slug}', [SubjectController::class, 'show']);
911
Route::get('/{subject:slug}/{path}', [NodeController::class, 'show'])->where('path', '.*');

0 commit comments

Comments
 (0)