|
| 1 | +<script setup lang="ts"> |
| 2 | +import { HOME_HEADING_ID } from "~/constant"; |
| 3 | +import { useI18n, useFetch, useBreakpoint, computed, onMounted } from "#imports"; |
| 4 | +import { VFSection } from "#components"; |
| 5 | +
|
| 6 | +import StaffGrid from "./StaffGrid.vue"; |
| 7 | +import type { Staff } from "~~/server/api/staffs/index.get"; |
| 8 | +
|
| 9 | +const { t } = useI18n(); |
| 10 | +const bp = useBreakpoint(); |
| 11 | +
|
| 12 | +const { data: staffList } = await useFetch("/api/staffs", { deep: true }); |
| 13 | +
|
| 14 | +const leaderColumns = computed(() => { |
| 15 | + return bp.value === "pc" ? 3 : 2; |
| 16 | +}); |
| 17 | +
|
| 18 | +const coreColumns = computed(() => { |
| 19 | + return bp.value === "pc" ? 4 : 3; |
| 20 | +}); |
| 21 | +
|
| 22 | +onMounted(() => { |
| 23 | + if (!staffList.value) return; |
| 24 | + staffList.value.leaders = shuffleNonPinned(staffList.value.leaders); |
| 25 | + staffList.value.cores = shuffleNonPinned(staffList.value.cores); |
| 26 | +}); |
| 27 | +function shuffleArray<T>(array: T[]): T[] { |
| 28 | + const shuffled = [...array]; |
| 29 | + for (let i = shuffled.length - 1; i > 0; i--) { |
| 30 | + const j = Math.floor(Math.random() * (i + 1)); |
| 31 | + [shuffled[i]!, shuffled[j]!] = [shuffled[j]!, shuffled[i]!]; |
| 32 | + } |
| 33 | + return shuffled; |
| 34 | +} |
| 35 | +
|
| 36 | +function shuffleNonPinned(staffArray: Staff[]): Staff[] { |
| 37 | + const pinned = staffArray.filter(staff => staff.pinned); |
| 38 | + const nonPinned = staffArray.filter(staff => !staff.pinned); |
| 39 | + const shuffledNonPinned = shuffleArray(nonPinned); |
| 40 | + return [...pinned, ...shuffledNonPinned]; |
| 41 | +} |
| 42 | +</script> |
| 43 | + |
| 44 | +<template> |
| 45 | + <VFSection :id="HOME_HEADING_ID.staff" :title="t('staff.title')"> |
| 46 | + <p class="staff-description"> |
| 47 | + {{ t('staff.description') }} |
| 48 | + </p> |
| 49 | + <template v-if="staffList"> |
| 50 | + <StaffGrid |
| 51 | + :staff-list="staffList.leaders" |
| 52 | + grid-mode="leader" |
| 53 | + :columns="leaderColumns" |
| 54 | + /> |
| 55 | + <StaffGrid |
| 56 | + :staff-list="staffList.cores" |
| 57 | + grid-mode="core" |
| 58 | + :columns="coreColumns" |
| 59 | + /> |
| 60 | + |
| 61 | + <VFHeading id="volunteer-staff"> |
| 62 | + {{ t('staff.volunteer') }} |
| 63 | + </VFHeading> |
| 64 | + |
| 65 | + <StaffGrid |
| 66 | + :staff-list="staffList.volunteers" |
| 67 | + grid-mode="volunteer" |
| 68 | + /> |
| 69 | + </template> |
| 70 | + </VFSection> |
| 71 | +</template> |
| 72 | + |
| 73 | +<style scoped> |
| 74 | +.staff-description { |
| 75 | + margin: 2rem 0; |
| 76 | + word-break: break-all; |
| 77 | +} |
| 78 | +</style> |
0 commit comments