diff --git a/pages/schedule/index.vue b/pages/schedule/index.vue index 56398b7..849e763 100644 --- a/pages/schedule/index.vue +++ b/pages/schedule/index.vue @@ -78,9 +78,10 @@ const getAllLocation = () => { useFetch('/kota/semua', { baseURL: SHOLAT_API, transform: (data: any) => { - const newData = data.data.map((d: ILocations) => { - return { id: d.id, lokasi: d.lokasi.toLowerCase() } - }) + const newData = data.data.map(({ id, lokasi }: ILocations) => ({ + id, + lokasi: lokasi.toLowerCase(), + })) return newData }, }).then((res) => { @@ -103,7 +104,6 @@ const getIdCity = () => { // Handle select manual location const handleSelectLocation = (location: ILocations) => { locationSelected.value = location - indexActiveTab.value = 0 isLoading.value = true idCity.value = location.id @@ -131,17 +131,14 @@ const getPrayerTimeOneMonth = () => { useFetch(`/jadwal/${idCity.value}/${date.join('/')}`, { baseURL: SHOLAT_API, transform: (data: any) => { - const date = new Date() - const newData = data.data.jadwal.map((data: ISchedule, index: any) => { - const value = { ...data } - value.tanggal = index + 1 < 10 ? `0${index + 1}` : index + 1 - - if (index + 1 === date.getDate()) { - value.class = 'bg-teal-600/20 dark:bg-teal-500/20 rounded-lg' - } - - return value - }) + const newData = data.data.jadwal.map((data: ISchedule, index: number) => ({ + ...data, + tanggal: (index + 1).toString().padStart(2, '0'), + class: + index + 1 === new Date().getDate() + ? 'active-row bg-teal-600/20 dark:bg-teal-500/20 rounded-lg' + : '', + })) return newData }, @@ -150,6 +147,21 @@ const getPrayerTimeOneMonth = () => { }) } +watch(indexActiveTab, (val) => { + if (val === 1) scrollToActiveRow() +}) + +// Function for scroll to element with classname active-row +const scrollToActiveRow = () => { + setTimeout(() => { + const element = document.querySelector('.active-row') + if (element) element.scrollIntoView({ behavior: 'smooth' }) + }, 250) +} + +// Change index active tab +const onChangeTab = (index: number) => (indexActiveTab.value = index) + // Created getAllLocation() @@ -162,18 +174,20 @@ useHead({