Improved mobile support on training report list
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { getTrainingReport, getTrainingReports } from '@/api/trainingReport';
|
||||
import { CourseAttendee, CourseEventDetails, CourseEventSummary } from '@shared/types/course';
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from '@/components/ui/table'
|
||||
import { ArrowUpDown, ChevronDown, ChevronUp, Funnel, Link, Plus, Search, X } from 'lucide-vue-next';
|
||||
import { ArrowUpDown, ChevronDown, ChevronLeft, ChevronUp, Funnel, Link, Plus, Search, X } from 'lucide-vue-next';
|
||||
import Button from '@/components/ui/button/Button.vue';
|
||||
import TrainingReportForm from '@/components/trainingReport/trainingReportForm.vue';
|
||||
import Checkbox from '@/components/ui/checkbox/Checkbox.vue';
|
||||
@@ -49,6 +49,21 @@ const sidePanel = computed<sidePanelState>(() => {
|
||||
return sidePanelState.closed;
|
||||
})
|
||||
|
||||
const isMobile = ref(false);
|
||||
const mobilePanel = ref<sidePanelState>(sidePanelState.closed);
|
||||
let mobileMediaQuery: MediaQueryList | null = null;
|
||||
|
||||
function syncMobileMode() {
|
||||
isMobile.value = mobileMediaQuery?.matches ?? window.innerWidth < 1024;
|
||||
if (!isMobile.value) {
|
||||
mobilePanel.value = sidePanelState.closed;
|
||||
}
|
||||
}
|
||||
|
||||
const effectivePanel = computed<sidePanelState>(() => {
|
||||
return isMobile.value ? mobilePanel.value : sidePanel.value;
|
||||
})
|
||||
|
||||
watch(() => route.params.id, async (newID) => {
|
||||
if (!newID) {
|
||||
focusedTrainingReport.value = null;
|
||||
@@ -82,6 +97,41 @@ async function closeTrainingReport() {
|
||||
focusedTrainingReport.value = null;
|
||||
}
|
||||
|
||||
async function openTrainingReport(id: number) {
|
||||
if (isMobile.value) {
|
||||
focusedTrainingReport.value = null;
|
||||
TRLoaded.value = false;
|
||||
expanded.value = null;
|
||||
mobilePanel.value = sidePanelState.view;
|
||||
await viewTrainingReport(id);
|
||||
return;
|
||||
}
|
||||
|
||||
router.push(`/trainingReport/${id}`);
|
||||
}
|
||||
|
||||
function openCreatePanel() {
|
||||
if (isMobile.value) {
|
||||
mobilePanel.value = sidePanelState.create;
|
||||
focusedTrainingReport.value = null;
|
||||
return;
|
||||
}
|
||||
|
||||
router.push('/trainingReport/new');
|
||||
}
|
||||
|
||||
async function closePanel() {
|
||||
if (isMobile.value) {
|
||||
mobilePanel.value = sidePanelState.closed;
|
||||
focusedTrainingReport.value = null;
|
||||
TRLoaded.value = false;
|
||||
expanded.value = null;
|
||||
return;
|
||||
}
|
||||
|
||||
await closeTrainingReport();
|
||||
}
|
||||
|
||||
const sortMode = ref<string>("descending");
|
||||
const searchString = ref<string>("");
|
||||
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
@@ -105,12 +155,20 @@ async function loadTrainingReports() {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
mobileMediaQuery = window.matchMedia('(max-width: 1023px)');
|
||||
syncMobileMode();
|
||||
mobileMediaQuery.addEventListener('change', syncMobileMode);
|
||||
|
||||
await loadTrainingReports();
|
||||
if (route.params.id)
|
||||
viewTrainingReport(Number(route.params.id))
|
||||
loaded.value = true;
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
mobileMediaQuery?.removeEventListener('change', syncMobileMode);
|
||||
})
|
||||
|
||||
const TRLoaded = ref(false);
|
||||
|
||||
const pageNum = ref<number>(1);
|
||||
@@ -119,6 +177,16 @@ const pageData = ref<pagination>();
|
||||
const pageSize = ref<number>(15)
|
||||
const pageSizeOptions = [10, 15, 30]
|
||||
|
||||
function formatDate(date: Date | string): string {
|
||||
if (!date) return '';
|
||||
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
||||
return dateObj.toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
});
|
||||
}
|
||||
|
||||
function setPageSize(size: number) {
|
||||
pageSize.value = size
|
||||
pageNum.value = 1;
|
||||
@@ -134,21 +202,22 @@ const expanded = ref<number>(null);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="px-20 mx-auto max-w-[100rem] w-full flex mt-5">
|
||||
<div class="mx-auto mt-5 flex w-full max-w-[100rem] flex-col px-3 sm:px-4 lg:flex-row lg:px-8 xl:px-20">
|
||||
<!-- training report list -->
|
||||
<div class="px-4 my-3" :class="sidePanel == sidePanelState.closed ? 'w-full' : 'w-2/5'">
|
||||
<div v-show="!isMobile || effectivePanel === sidePanelState.closed" class="my-3 px-0 lg:px-4"
|
||||
:class="effectivePanel == sidePanelState.closed ? 'w-full' : 'w-full lg:w-2/5'">
|
||||
<div class="flex justify-between mb-4">
|
||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Training Reports</p>
|
||||
<Button @click="router.push('/trainingReport/new')">
|
||||
<Button @click="openCreatePanel()">
|
||||
<Plus></Plus> New Training Report
|
||||
</Button>
|
||||
</div>
|
||||
<!-- search/filter -->
|
||||
<div class="flex justify-between">
|
||||
<div class="flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
|
||||
<!-- <Search></Search>
|
||||
<Funnel></Funnel> -->
|
||||
<div></div>
|
||||
<div class="flex flex-row gap-5">
|
||||
<div class="flex flex-col gap-3 sm:flex-row sm:gap-5">
|
||||
<div>
|
||||
<label class="text-muted-foreground">Search</label>
|
||||
<Input v-model="searchString" placeholder="Search..."></Input>
|
||||
@@ -172,7 +241,24 @@ const expanded = ref<number>(null);
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="overflow-y-auto max-h-[70vh] mt-5 scrollbar-themed">
|
||||
<div class="mt-5">
|
||||
<div class="space-y-2 md:hidden">
|
||||
<button v-for="report in trainingReports" :key="`mobile-report-${report.event_id}`"
|
||||
class="w-full rounded-lg border bg-card px-3 py-2 text-left transition-colors hover:bg-muted/40"
|
||||
@click="openTrainingReport(report.event_id)">
|
||||
<p class="font-semibold text-foreground">
|
||||
{{ report.course_name.length > 35 ? report.course_shortname : report.course_name }}
|
||||
</p>
|
||||
<p class="mt-1 text-sm text-muted-foreground">{{ formatDate(report.date) }}</p>
|
||||
<div class="mt-2 flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<span class="font-medium">Posted by:</span>
|
||||
<MemberCard v-if="report.created_by" :member-id="report.created_by"></MemberCard>
|
||||
<span v-else>Unknown User</span>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="hidden md:block">
|
||||
<Table>
|
||||
<TableHeader class="">
|
||||
<TableRow>
|
||||
@@ -187,12 +273,12 @@ const expanded = ref<number>(null);
|
||||
</TableHeader>
|
||||
<TableBody v-if="loaded">
|
||||
<TableRow class="cursor-pointer" v-for="report in trainingReports" :key="report.event_id"
|
||||
@click="router.push(`/trainingReport/${report.event_id}`)">
|
||||
@click="openTrainingReport(report.event_id)">
|
||||
<TableCell class="font-medium">{{ report.course_name.length > 30 ? report.course_shortname :
|
||||
report.course_name }}</TableCell>
|
||||
<TableCell>{{ report.date.split('T')[0] }}</TableCell>
|
||||
<TableCell class="text-right">
|
||||
<MemberCard v-if="report.created_by_name" :member-id="report.created_by"></MemberCard>
|
||||
<MemberCard v-if="report.created_by" :member-id="report.created_by"></MemberCard>
|
||||
<span v-else>Unknown User</span>
|
||||
</TableCell>
|
||||
<!-- <TableCell class="text-right">{{ report.created_by_name === null ? "Unknown User" :
|
||||
@@ -201,10 +287,11 @@ const expanded = ref<number>(null);
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-between"
|
||||
:class="sidePanel !== sidePanelState.closed ? 'flex-col items-center' : 'items-center justify-between'">
|
||||
<div></div>
|
||||
<div class="mt-5 flex flex-col gap-3 md:flex-row md:items-center md:justify-between"
|
||||
:class="effectivePanel !== sidePanelState.closed ? 'items-center' : ''">
|
||||
<div class="hidden md:block"></div>
|
||||
<Pagination v-slot="{ page }" :items-per-page="pageData?.pageSize || 10" :total="pageData?.total || 10"
|
||||
:default-page="2" :page="pageNum" @update:page="setPage">
|
||||
<PaginationContent v-slot="{ items }">
|
||||
@@ -219,8 +306,9 @@ const expanded = ref<number>(null);
|
||||
<PaginationNext />
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
<div class="flex items-center gap-3 text-sm" :class="sidePanel !== sidePanelState.closed ? 'mt-3' : ''">
|
||||
<p class="text-muted-foreground text-nowrap">Per page:</p>
|
||||
<div class="flex flex-wrap items-center justify-end gap-2 text-sm"
|
||||
:class="effectivePanel !== sidePanelState.closed ? 'w-full justify-center md:w-auto md:justify-end' : ''">
|
||||
<p class="text-muted-foreground">Per page:</p>
|
||||
|
||||
<button v-for="size in pageSizeOptions" :key="size" @click="setPageSize(size)"
|
||||
class="px-2 py-1 rounded transition-colors" :class="{
|
||||
@@ -234,31 +322,35 @@ const expanded = ref<number>(null);
|
||||
|
||||
</div>
|
||||
<!-- view training report section -->
|
||||
<div v-if="focusedTrainingReport != null && sidePanel == sidePanelState.view" class="pl-9 my-3 border-l w-3/5">
|
||||
<div v-if="focusedTrainingReport != null && effectivePanel == sidePanelState.view"
|
||||
:class="isMobile
|
||||
? 'fixed inset-0 z-[60] overflow-y-auto bg-background px-3 py-3'
|
||||
: 'my-3 mt-2 w-full lg:mt-0 lg:w-3/5 lg:border-l lg:pl-9'">
|
||||
<div class="flex justify-between items-center">
|
||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Training Report Details</p>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button class="cursor-pointer" variant="ghost" size="icon" @click="CopyLink()">
|
||||
<Button v-if="isMobile" @click="closePanel" class="cursor-pointer" variant="outline" size="sm">
|
||||
<ChevronLeft class="size-4"></ChevronLeft> Back
|
||||
</Button>
|
||||
<Button v-else class="cursor-pointer" variant="ghost" size="icon" @click="CopyLink()">
|
||||
<Link class="size-4" />
|
||||
</Button>
|
||||
<Button @click="closeTrainingReport" class="cursor-pointer" variant="ghost" size="icon">
|
||||
<Button v-if="!isMobile" @click="closePanel" class="cursor-pointer" variant="ghost" size="icon">
|
||||
<X class="size-6"></X>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="TRLoaded" class="max-h-[70vh] overflow-auto scrollbar-themed my-5">
|
||||
<div v-if="TRLoaded" :class="isMobile ? 'my-3 pb-8' : 'max-h-[70vh] overflow-auto scrollbar-themed my-5'">
|
||||
<div class="flex flex-col mb-5 border rounded-lg bg-muted/70 p-2 py-3 px-4">
|
||||
<p class="scroll-m-20 text-xl font-semibold tracking-tight">{{ focusedTrainingReport.course_name }}
|
||||
</p>
|
||||
<div class="flex gap-10 items-center">
|
||||
<p class="text-muted-foreground">{{ focusedTrainingReport.event_date.split('T')[0] }}</p>
|
||||
<p class="flex gap-2 items-center">Created by:
|
||||
<p class="text-muted-foreground">{{ formatDate(focusedTrainingReport.event_date) }}</p>
|
||||
<div class="flex gap-2 items-center">Created by:
|
||||
<MemberCard v-if="focusedTrainingReport.created_by"
|
||||
:member-id="focusedTrainingReport.created_by" />
|
||||
<p v-else>{{ focusedTrainingReport.created_by_name === null ? "Unknown User" :
|
||||
focusedTrainingReport.created_by_name
|
||||
}}</p>
|
||||
</p>
|
||||
<span v-else>Unknown User</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-8 ">
|
||||
@@ -452,18 +544,31 @@ const expanded = ref<number>(null);
|
||||
<Spinner class="size-8"></Spinner>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="sidePanel == sidePanelState.create" class="pl-7 border-l w-3/5 max-w-5xl">
|
||||
<div v-if="effectivePanel == sidePanelState.create" :class="isMobile
|
||||
? 'fixed inset-0 z-[60] overflow-y-auto bg-background px-3 py-3'
|
||||
: 'mt-2 w-full max-w-5xl lg:mt-0 lg:w-3/5 lg:border-l lg:pl-7'">
|
||||
<div class="flex justify-between items-center my-3">
|
||||
<div class="flex pl-2 gap-5">
|
||||
<div class="flex gap-5 lg:pl-2">
|
||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">New Training Report</p>
|
||||
</div>
|
||||
<Button @click="closeTrainingReport" class="cursor-pointer" variant="ghost" size="icon">
|
||||
<Button v-if="isMobile" @click="closePanel" class="cursor-pointer" variant="outline" size="sm">
|
||||
<ChevronLeft class="size-4"></ChevronLeft> Back
|
||||
</Button>
|
||||
<Button v-else @click="closePanel" class="cursor-pointer" variant="ghost" size="icon">
|
||||
<X class="size-6"></X>
|
||||
</Button>
|
||||
</div>
|
||||
<div class="overflow-y-auto max-h-[70vh] mt-5 scrollbar-themed">
|
||||
<TrainingReportForm class="w-full pl-2"
|
||||
@submit="(newID) => { router.push(`/trainingReport/${newID}`); loadTrainingReports() }">
|
||||
<div :class="isMobile ? 'mt-3 pb-8' : 'overflow-y-auto max-h-[70vh] mt-5 scrollbar-themed'">
|
||||
<TrainingReportForm class="w-full lg:pl-2"
|
||||
@submit="async (newID) => {
|
||||
if (isMobile) {
|
||||
await viewTrainingReport(newID);
|
||||
mobilePanel = sidePanelState.view;
|
||||
} else {
|
||||
router.push(`/trainingReport/${newID}`);
|
||||
}
|
||||
loadTrainingReports()
|
||||
}">
|
||||
</TrainingReportForm>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user