11<script setup lang="ts">
22import { HOME_HEADING_ID } from " ~/constant" ;
3- import { useI18n , useFetch , useBreakpoint , computed } from " #imports" ;
3+ import { useI18n , useFetch , useBreakpoint , computed , onMounted } from " #imports" ;
44import { VFSection } from " #components" ;
55
66import StaffGrid from " ./StaffGrid.vue" ;
7+ import type { Staff } from " ~~/server/api/staffs/index.get" ;
78
89const { t } = useI18n ();
910const bp = useBreakpoint ();
1011
11- const { data : staffList } = await useFetch (" /api/staffs" );
12+ const { data : staffList } = await useFetch (" /api/staffs" , { deep: true } );
1213
1314const leaderColumns = computed (() => {
1415 return bp .value === " pc" ? 3 : 2 ;
@@ -17,6 +18,27 @@ const leaderColumns = computed(() => {
1718const coreColumns = computed (() => {
1819 return bp .value === " pc" ? 4 : 3 ;
1920});
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+ }
2042 </script >
2143
2244<template >
0 commit comments