Skip to content

Commit 29fce9a

Browse files
authored
feat(resource): 2-column note spread on PC, floating scroll-to-top and universal comment quick jump (#461)
1 parent 6f63887 commit 29fce9a

2 files changed

Lines changed: 69 additions & 9 deletions

File tree

‎resources/js/components/resources/NoteReader.vue‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const goToNext = () => {
4343
</script>
4444

4545
<template>
46-
<div class="relative mx-auto w-full sm:max-w-xl md:max-w-2xl">
46+
<div class="relative mx-auto w-full">
4747
<!-- Minimal Top Info -->
4848
<div
4949
class="mb-4 flex items-center justify-between px-1 text-xs text-slate-400 dark:text-gray-500"
@@ -54,8 +54,14 @@ const goToNext = () => {
5454
<span class="text-[11px]"> (ছবিতে ক্লিক করে জুম করুন) </span>
5555
</div>
5656

57-
<!-- Continuous Document Pages (Clean, natural document flow) -->
58-
<div class="space-y-6 sm:space-y-8">
57+
<!-- Continuous Document Pages (1 column on mobile, 2 columns on PC for balance) -->
58+
<div
59+
:class="[
60+
items.length > 1
61+
? 'grid grid-cols-1 items-start gap-6 sm:gap-8 md:grid-cols-2'
62+
: 'mx-auto max-w-2xl space-y-6',
63+
]"
64+
>
5965
<div
6066
v-for="(item, index) in items"
6167
:key="item.id || index"

‎resources/js/pages/Resource.vue‎

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { Head, Link, router, usePage } from '@inertiajs/vue3';
33
import {
44
ArrowLeft,
5+
ArrowUp,
56
ArrowBigUp,
67
User as UserIcon,
78
X,
@@ -12,7 +13,7 @@ import {
1213
Pencil,
1314
MessageSquare,
1415
} from 'lucide-vue-next';
15-
import { computed, ref, watch } from 'vue';
16+
import { computed, ref, watch, onMounted, onUnmounted } from 'vue';
1617
1718
import NoteReader from '@/components/resources/NoteReader.vue';
1819
import PdfViewer from '@/components/resources/PdfViewer.vue';
@@ -247,6 +248,42 @@ const totalCommentsCount = computed(() => {
247248
248249
return count;
249250
});
251+
252+
// Scroll to Top state & handlers
253+
const showScrollTop = ref(false);
254+
255+
const handleScroll = () => {
256+
if (typeof window === 'undefined') {
257+
return;
258+
}
259+
260+
const scrollPos =
261+
window.scrollY ||
262+
document.documentElement?.scrollTop ||
263+
document.body?.scrollTop ||
264+
0;
265+
showScrollTop.value = scrollPos > 300;
266+
};
267+
268+
const scrollToTop = () => {
269+
if (typeof window === 'undefined') {
270+
return;
271+
}
272+
273+
window.scrollTo({
274+
top: 0,
275+
behavior: 'smooth',
276+
});
277+
};
278+
279+
onMounted(() => {
280+
window.addEventListener('scroll', handleScroll, { passive: true });
281+
handleScroll();
282+
});
283+
284+
onUnmounted(() => {
285+
window.removeEventListener('scroll', handleScroll);
286+
});
250287
</script>
251288

252289
<template>
@@ -569,12 +606,8 @@ const totalCommentsCount = computed(() => {
569606
</p>
570607
</div>
571608

572-
<!-- Quick Jump to Comments Bar (Ideal for long multi-image notes) -->
609+
<!-- Quick Jump to Comments Bar (Available for all resource types) -->
573610
<div
574-
v-if="
575-
primaryFormat === 'image' &&
576-
(resource.items || []).length > 2
577-
"
578611
class="mt-4 flex items-center justify-between rounded-2xl border border-slate-200/90 bg-white px-4 py-2.5 shadow-2xs dark:border-gray-800 dark:bg-gray-900"
579612
>
580613
<div
@@ -738,4 +771,25 @@ const totalCommentsCount = computed(() => {
738771
:subjects="subjects || []"
739772
@save="() => {}"
740773
/>
774+
775+
<!-- Floating Scroll to Top Button -->
776+
<Transition
777+
enter-active-class="transition duration-150 ease-out"
778+
enter-from-class="opacity-0 translate-y-2 scale-95"
779+
enter-to-class="opacity-100 translate-y-0 scale-100"
780+
leave-active-class="transition duration-100 ease-in"
781+
leave-from-class="opacity-100 translate-y-0 scale-100"
782+
leave-to-class="opacity-0 translate-y-2 scale-95"
783+
>
784+
<button
785+
v-if="showScrollTop"
786+
type="button"
787+
@click="scrollToTop"
788+
title="উপরে যান"
789+
aria-label="Scroll to top"
790+
class="fixed right-4 bottom-[calc(4.5rem+env(safe-area-inset-bottom)+0.5rem)] z-50 flex h-9.5 w-9.5 cursor-pointer items-center justify-center rounded-full bg-slate-900/90 text-white shadow-lg ring-1 ring-black/10 backdrop-blur-xs transition duration-150 hover:scale-105 hover:bg-indigo-600 active:scale-95 sm:right-6 sm:bottom-6 sm:h-10 sm:w-10 dark:bg-gray-800/90 dark:text-gray-100 dark:ring-white/10 dark:hover:bg-indigo-600 dark:hover:text-white"
791+
>
792+
<ArrowUp class="h-4 w-4 stroke-[2.3]" />
793+
</button>
794+
</Transition>
741795
</template>

0 commit comments

Comments
 (0)