Mengerjakan QC Kak Inno & Kak Ayu Tanggal 16 Oktober
Fix Search
This commit is contained in:
@@ -1,16 +1,4 @@
|
||||
[
|
||||
{
|
||||
"id": "cmds8w2q60002vnbe6i8qhkuo",
|
||||
"name": "Telephone Desa Darmasaba",
|
||||
"iconUrl": "081239580000",
|
||||
"imageId": "cmff3nv180003vn6h5jvedidq"
|
||||
},
|
||||
{
|
||||
"id": "cmds8z7u20005vnbegyyvnbk0",
|
||||
"name": "Email Desa Darmasaba",
|
||||
"iconUrl": "desadarmasaba@badungkab.go.id",
|
||||
"imageId": "cmff3ll130001vn6hkhls3f5y"
|
||||
},
|
||||
{
|
||||
"id": "cmds9023u0008vnbe3oxmhwyf",
|
||||
"name": "Desa Darmasaba",
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 266 KiB After Width: | Height: | Size: 378 KiB |
@@ -22,21 +22,19 @@ interface FileItem {
|
||||
const [search, setSearch] = useState('');
|
||||
const [page, setPage] = useState(1);
|
||||
const [totalPages, setTotalPages] = useState(1);
|
||||
const limit = 9; // ✅ ambil 12 data per page
|
||||
|
||||
// Handle search and pagination changes
|
||||
const loadData = useCallback((pageNum: number, searchTerm: string) => {
|
||||
const loadData = useCallback(async (pageNum: number, searchTerm: string) => {
|
||||
setLoading(true);
|
||||
// Using the load function from the component's scope
|
||||
const loadFn = async () => {
|
||||
try {
|
||||
const response = await ApiFetch.api.fileStorage.findMany.get({
|
||||
query: {
|
||||
const query: Record<string, string> = {
|
||||
category: 'image',
|
||||
page: pageNum.toString(),
|
||||
limit: '10',
|
||||
...(searchTerm && { search: searchTerm })
|
||||
}
|
||||
});
|
||||
limit: limit.toString(),
|
||||
};
|
||||
if (searchTerm) query.search = searchTerm;
|
||||
|
||||
const response = await ApiFetch.api.fileStorage.findMany.get({ query });
|
||||
|
||||
if (response.status === 200 && response.data) {
|
||||
setFiles(response.data.data || []);
|
||||
@@ -50,78 +48,41 @@ interface FileItem {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
loadFn();
|
||||
}, []);
|
||||
|
||||
// Initial load and URL change handler
|
||||
// ✅ Initial load + update when URL/search changes
|
||||
useEffect(() => {
|
||||
const handleRouteChange = () => {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const urlSearch = urlParams.get('search') || '';
|
||||
const urlPage = parseInt(urlParams.get('page') || '1');
|
||||
|
||||
setSearch(urlSearch);
|
||||
setPage(urlPage);
|
||||
loadData(urlPage, urlSearch);
|
||||
};
|
||||
|
||||
// Handle search updates from the search bar
|
||||
const handleSearchUpdate = (e: Event) => {
|
||||
const { search } = (e as CustomEvent).detail;
|
||||
|
||||
setSearch(search);
|
||||
setPage(1); // Reset to first page on new search
|
||||
setPage(1);
|
||||
loadData(1, search);
|
||||
};
|
||||
|
||||
// Initial load
|
||||
handleRouteChange();
|
||||
|
||||
// Set up event listeners
|
||||
window.addEventListener('popstate', handleRouteChange);
|
||||
window.addEventListener('searchUpdate', handleSearchUpdate as EventListener);
|
||||
|
||||
// Cleanup
|
||||
return () => {
|
||||
window.removeEventListener('popstate', handleRouteChange);
|
||||
window.removeEventListener('searchUpdate', handleSearchUpdate as EventListener);
|
||||
};
|
||||
}, [loadData]);
|
||||
|
||||
// ✅ Fetch data
|
||||
// ✅ Update when page/search changes
|
||||
useEffect(() => {
|
||||
const fetchFiles = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const query: Record<string, string> = {
|
||||
category: 'image',
|
||||
page: page.toString(),
|
||||
limit: '10',
|
||||
};
|
||||
if (search) query.search = search;
|
||||
loadData(page, search);
|
||||
}, [page, search, loadData]);
|
||||
|
||||
const response = await ApiFetch.api.fileStorage.findMany.get({ query });
|
||||
|
||||
if (response.status === 200 && response.data) {
|
||||
setFiles(response.data.data || []);
|
||||
setTotalPages(response.data.meta?.totalPages || 1);
|
||||
} else {
|
||||
setFiles([]);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Fetch error:', err);
|
||||
setFiles([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (page > 0) fetchFiles(); // jangan fetch jika page belum valid
|
||||
}, [search, page]);
|
||||
|
||||
// ✅ Update URL
|
||||
const updateURL = (newSearch: string, newPage: number) => {
|
||||
const url = new URL(window.location.href);
|
||||
if (newSearch) url.searchParams.set('search', newSearch);
|
||||
@@ -148,7 +109,14 @@ interface FileItem {
|
||||
<Box pt={20} px={{ base: 'md', md: 100 }}>
|
||||
<SimpleGrid cols={{ base: 1, md: 3 }}>
|
||||
{files.map((file) => (
|
||||
<Paper key={file.id} mb={50} p="md" radius={26} bg={colors['white-trans-1']} style={{ height: '100%' }}>
|
||||
<Paper
|
||||
key={file.id}
|
||||
mb={50}
|
||||
p="md"
|
||||
radius={26}
|
||||
bg={colors['white-trans-1']}
|
||||
style={{ height: '100%' }}
|
||||
>
|
||||
<Box style={{ height: '250px', overflow: 'hidden', borderRadius: '12px' }}>
|
||||
<Image
|
||||
src={file.link}
|
||||
@@ -159,7 +127,6 @@ interface FileItem {
|
||||
loading="lazy"
|
||||
/>
|
||||
</Box>
|
||||
<Box>
|
||||
<Stack gap="sm" py={10}>
|
||||
<Text fw="bold" fz={{ base: 'h4', md: 'h3' }}>
|
||||
{file.realName || file.name}
|
||||
@@ -172,7 +139,6 @@ interface FileItem {
|
||||
})}
|
||||
</Text>
|
||||
</Stack>
|
||||
</Box>
|
||||
</Paper>
|
||||
))}
|
||||
</SimpleGrid>
|
||||
|
||||
@@ -146,24 +146,24 @@ function Page() {
|
||||
<Title order={3}>Ajukan Permohonan</Title>
|
||||
<TextInput
|
||||
label={<Text fz="sm" fw="bold">Nama</Text>}
|
||||
placeholder="masukkan nama"
|
||||
placeholder="Masukkan nama"
|
||||
onChange={(val) => (stateCreate.create.form.nama = val.target.value)}
|
||||
/>
|
||||
<TextInput
|
||||
type="number"
|
||||
label={<Text fz="sm" fw="bold">NIK</Text>}
|
||||
placeholder="masukkan NIK"
|
||||
placeholder="Masukkan NIK"
|
||||
onChange={(val) => (stateCreate.create.form.nik = val.target.value)}
|
||||
/>
|
||||
<TextInput
|
||||
label={<Text fz="sm" fw="bold">Alamat</Text>}
|
||||
placeholder="masukkan alamat"
|
||||
placeholder="Masukkan alamat"
|
||||
onChange={(val) => (stateCreate.create.form.alamat = val.target.value)}
|
||||
/>
|
||||
<TextInput
|
||||
type="number"
|
||||
label={<Text fz="sm" fw="bold">Nomor KK</Text>}
|
||||
placeholder="masukkan Nomor KK"
|
||||
placeholder="Masukkan Nomor KK"
|
||||
onChange={(val) => (stateCreate.create.form.nomorKk = val.target.value)}
|
||||
/>
|
||||
<Select
|
||||
|
||||
@@ -72,21 +72,21 @@ function Page() {
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Stack pos={"relative"} bg={colors.Bg} py={"xl"} gap={"22"}>
|
||||
<Box px={{ base: 'md', md: 100 }}>
|
||||
<Stack pos="relative" bg={colors.Bg} py="xl" gap="22" style={{ overflow: 'auto' }}>
|
||||
<Box px={{ base: 'md', md: 50, lg: 100 }}>
|
||||
<BackButton />
|
||||
</Box>
|
||||
<Box px={{ base: 'md', md: 100 }} >
|
||||
<Box px={{ base: 'md', md: 50, lg: 100 }} >
|
||||
<Text ta={"center"} fz={{ base: "h1", md: "2.5rem" }} c={colors["blue-button"]} fw={"bold"}>
|
||||
Jumlah Penduduk Usia Kerja Yang Menganggur
|
||||
</Text>
|
||||
</Box>
|
||||
<Box px={{ base: "md", md: 100 }}>
|
||||
<Box px={{ base: "md", md: 50, lg: 100 }}>
|
||||
<Stack gap={'lg'} justify='center'>
|
||||
<Paper p={'lg'}>
|
||||
<Text fw={'bold'} fz={'h3'}>Pengangguran Berdasarkan Usia</Text>
|
||||
{mounted && donutGrafikNganggurData.length > 0 ? (<Box style={{ width: '100%', height: 'auto', minHeight: 200 }}>
|
||||
<Box w="100%" style={{ maxWidth: 400, margin: "0 auto" }}>
|
||||
<Box w="100%" maw={{ base: '100%', md: 400 }} mx="auto">
|
||||
<PieChart
|
||||
w="100%"
|
||||
h={250} // lebih kecil biar aman di mobile
|
||||
@@ -133,7 +133,7 @@ function Page() {
|
||||
<Box w="100%" style={{ maxWidth: 400, margin: "0 auto" }}>
|
||||
<PieChart
|
||||
w="100%"
|
||||
h={250} // lebih kecil biar aman di mobile
|
||||
h="min(250px, 50vh)" // lebih kecil biar aman di mobile
|
||||
withLabelsLine
|
||||
labelsPosition="outside"
|
||||
labelsType="percent"
|
||||
|
||||
@@ -199,7 +199,7 @@ function Page() {
|
||||
<TableTd ta={'center'}>{item.totalUnemployment}</TableTd>
|
||||
<TableTd ta={'center'}>{item.educatedUnemployment}</TableTd>
|
||||
<TableTd ta={'center'}>{item.uneducatedUnemployment}</TableTd>
|
||||
<TableTd ta={'center'}>{item.percentageChange}</TableTd>
|
||||
<TableTd ta={'center'}>{item.percentageChange}%</TableTd>
|
||||
</TableTr>
|
||||
))}
|
||||
</TableTbody>
|
||||
|
||||
@@ -75,8 +75,10 @@ const chartData = data
|
||||
</Paper>
|
||||
)
|
||||
})}
|
||||
<Paper p={'xl'}>
|
||||
<Text pb={10} fw={'bold'} fz={'h4'}>Statistik Sektor Unggulan Darmasaba</Text>
|
||||
<Box style={{ width: '100%', overflowX: 'auto' }}>
|
||||
<Paper p="xl">
|
||||
<Text pb={10} fw="bold" fz="h4">Statistik Sektor Unggulan Darmasaba</Text>
|
||||
<Box style={{ width: '100%', minWidth: '600px' }}>
|
||||
<BarChart
|
||||
p={10}
|
||||
h={300}
|
||||
@@ -86,8 +88,17 @@ const chartData = data
|
||||
{ name: 'Ton', color: colors['blue-button'] },
|
||||
]}
|
||||
tickLine="y"
|
||||
tooltipAnimationDuration={200}
|
||||
withTooltip
|
||||
style={{
|
||||
fontFamily: 'inherit',
|
||||
}}
|
||||
xAxisLabel="Sektor"
|
||||
yAxisLabel="Ton"
|
||||
/>
|
||||
</Box>
|
||||
</Paper>
|
||||
</Box>
|
||||
</Stack>
|
||||
</Box>
|
||||
</Stack>
|
||||
|
||||
@@ -50,10 +50,12 @@ function Page() {
|
||||
</Text>
|
||||
</Box>
|
||||
<TextInput
|
||||
placeholder='Cari kontak darurat, nama, atau nomor...'
|
||||
leftSection={<IconSearch size={20} />}
|
||||
radius={"lg"}
|
||||
placeholder='Cari Kontak Darurat'
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.currentTarget.value)}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
leftSection={<IconSearch size={20} />}
|
||||
w={{ base: "100%", md: "25%" }}
|
||||
/>
|
||||
</Group>
|
||||
<Box px={{ base: "md", md: 100 }}>
|
||||
@@ -95,10 +97,12 @@ function Page() {
|
||||
</Text>
|
||||
</Box>
|
||||
<TextInput
|
||||
placeholder='Cari kontak darurat, nama, atau nomor...'
|
||||
leftSection={<IconSearch size={20} />}
|
||||
radius={"lg"}
|
||||
placeholder='Cari Kontak Darurat'
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.currentTarget.value)}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
leftSection={<IconSearch size={20} />}
|
||||
w={{ base: "50%", md: "100%" }}
|
||||
/>
|
||||
</Group>
|
||||
<Box px={{ base: "md", md: 100 }}>
|
||||
|
||||
@@ -4,7 +4,7 @@ import colors from '@/con/colors';
|
||||
import { Box, Button, Center, ColorSwatch, Flex, Group, Modal, Pagination, Paper, SimpleGrid, Skeleton, Stack, Text, TextInput, Title } from '@mantine/core';
|
||||
import { DateTimePicker } from '@mantine/dates';
|
||||
import { useDebouncedValue, useDisclosure, useShallowEffect } from '@mantine/hooks';
|
||||
import { IconArrowRight, IconPlus } from '@tabler/icons-react';
|
||||
import { IconArrowRight, IconPlus, IconSearch } from '@tabler/icons-react';
|
||||
import { useState } from 'react';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
import BackButton from '../../desa/layanan/_com/BackButto';
|
||||
@@ -56,9 +56,12 @@ function Page() {
|
||||
<Flex justify="space-between" align="center">
|
||||
<BackButton />
|
||||
<TextInput
|
||||
placeholder="Cari laporan"
|
||||
radius={"lg"}
|
||||
placeholder='Cari Laporan Publik'
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.currentTarget.value)}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
leftSection={<IconSearch size={20} />}
|
||||
w={{ base: "50%", md: "100%" }}
|
||||
/>
|
||||
</Flex>
|
||||
</Box>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
'use client'
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { Transition } from '@mantine/core';
|
||||
import gotongRoyongState from '@/app/admin/(dashboard)/_state/lingkungan/gotong-royong';
|
||||
import {
|
||||
Badge,
|
||||
@@ -23,12 +27,11 @@ import {
|
||||
} from '@mantine/core';
|
||||
import { IconArrowRight, IconCalendar } from '@tabler/icons-react';
|
||||
import { useTransitionRouter } from 'next-view-transitions';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
|
||||
export default function Content({ kategori }: { kategori: string }) {
|
||||
const router = useTransitionRouter();
|
||||
const [page, setPage] = useState(1);
|
||||
const [animateKey, setAnimateKey] = useState(0);
|
||||
|
||||
const state = useProxy(gotongRoyongState.kegiatanDesa);
|
||||
const featuredState = useProxy(gotongRoyongState.kegiatanDesa.findFirst);
|
||||
@@ -37,29 +40,44 @@ export default function Content({ kategori }: { kategori: string }) {
|
||||
const paginatedNews = state.findMany.data || [];
|
||||
const totalPages = state.findMany.totalPages || 1;
|
||||
|
||||
// Load data
|
||||
// Load data awal
|
||||
useEffect(() => {
|
||||
gotongRoyongState.kegiatanDesa.findFirst.load(kategori);
|
||||
}, [kategori]);
|
||||
|
||||
// Load daftar berita
|
||||
useEffect(() => {
|
||||
state.findMany.load(page, 3, '', kategori);
|
||||
setAnimateKey((prev) => prev + 1); // trigger animasi halus saat page berubah
|
||||
}, [page, kategori]);
|
||||
|
||||
// Tampilan kosong
|
||||
if (!featuredState.loading && !featured) {
|
||||
return (
|
||||
<Center py={100}>
|
||||
<Stack align="center" gap="sm">
|
||||
<Title order={3}>Belum Ada Data Gotong Royong</Title>
|
||||
<Text c="dimmed">Tidak ada data gotong royong yang tersedia saat ini.</Text>
|
||||
</Stack>
|
||||
</Center>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box py={20}>
|
||||
<Container size="xl" px={{ base: 'md', md: 'xl' }}>
|
||||
{/* === Gotong Royong Utama === */}
|
||||
{featuredState.loading ? (
|
||||
<Center><Skeleton h={400} /></Center>
|
||||
) : featured ? (
|
||||
<Transition mounted={!featuredState.loading} transition="fade" duration={250} timingFunction="ease">
|
||||
{(styles) => (
|
||||
<div style={styles}>
|
||||
{featured ? (
|
||||
<Box mb={50}>
|
||||
<Text fz="h2" fw={700} mb="md">Gotong Royong Utama</Text>
|
||||
<Paper shadow="md" radius="md" withBorder>
|
||||
<Grid gutter={0}>
|
||||
<GridCol span={{ base: 12, md: 6 }}>
|
||||
<Image
|
||||
src={featured.image?.link}
|
||||
src={featured.image?.link || '/images/placeholder.jpg'}
|
||||
alt={featured.judul || 'Berita Utama'}
|
||||
height={400}
|
||||
fit="cover"
|
||||
@@ -75,7 +93,12 @@ export default function Content({ kategori }: { kategori: string }) {
|
||||
{featured.kategoriKegiatan?.nama || kategori}
|
||||
</Badge>
|
||||
<Title order={2} mb="md">{featured.judul}</Title>
|
||||
<Text c="dimmed" lineClamp={3} mb="md" dangerouslySetInnerHTML={{ __html: featured.deskripsiLengkap }} />
|
||||
<Text
|
||||
c="dimmed"
|
||||
lineClamp={3}
|
||||
mb="md"
|
||||
dangerouslySetInnerHTML={{ __html: featured.deskripsiLengkap }}
|
||||
/>
|
||||
</div>
|
||||
<Group justify="apart" mt="auto">
|
||||
<Group gap="xs">
|
||||
@@ -91,7 +114,9 @@ export default function Content({ kategori }: { kategori: string }) {
|
||||
<Button
|
||||
variant="light"
|
||||
rightSection={<IconArrowRight size={16} />}
|
||||
onClick={() => router.push(`/darmasaba/lingkungan/gotong-royong/${kategori}/${featured.id}`)}
|
||||
onClick={() =>
|
||||
router.push(`/darmasaba/lingkungan/gotong-royong/${kategori}/${featured.id}`)
|
||||
}
|
||||
>
|
||||
Baca Selengkapnya
|
||||
</Button>
|
||||
@@ -101,21 +126,41 @@ export default function Content({ kategori }: { kategori: string }) {
|
||||
</Grid>
|
||||
</Paper>
|
||||
</Box>
|
||||
) : null}
|
||||
) : (
|
||||
<Skeleton h={400} radius="md" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Transition>
|
||||
|
||||
{/* === Daftar Gotong Royong === */}
|
||||
{/* === Daftar Gotong Royong (Pagination + Fade-in Halus) === */}
|
||||
<Box mt={50}>
|
||||
<Title order={2} mb="md">Daftar Gotong Royong</Title>
|
||||
<Divider mb="xl" />
|
||||
|
||||
<AnimatePresence mode="wait">
|
||||
<motion.div
|
||||
key={animateKey}
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: -10 }}
|
||||
transition={{ duration: 0.25, ease: 'easeInOut' }}
|
||||
>
|
||||
{state.findMany.loading ? (
|
||||
<SimpleGrid cols={{ base: 1, sm: 2, lg: 3 }} spacing="xl">
|
||||
{Array(3).fill(0).map((_, i) => (
|
||||
{Array(3)
|
||||
.fill(0)
|
||||
.map((_, i) => (
|
||||
<Skeleton key={i} h={300} radius="md" />
|
||||
))}
|
||||
</SimpleGrid>
|
||||
) : paginatedNews.length === 0 ? (
|
||||
<Text c="dimmed" ta="center">Belum ada gotong royong di kategori "{kategori}".</Text>
|
||||
<Center py={50}>
|
||||
<Stack align="center" gap="sm">
|
||||
<Title order={3}>Tidak Ada Data</Title>
|
||||
<Text c="dimmed">Belum ada data gotong royong yang tersedia.</Text>
|
||||
</Stack>
|
||||
</Center>
|
||||
) : (
|
||||
<SimpleGrid cols={{ base: 1, sm: 2, lg: 3 }} spacing="xl" verticalSpacing="xl">
|
||||
{paginatedNews.map((item) => (
|
||||
@@ -129,13 +174,28 @@ export default function Content({ kategori }: { kategori: string }) {
|
||||
style={{ cursor: 'pointer' }}
|
||||
>
|
||||
<Card.Section>
|
||||
<Image src={item.image?.link} height={200} alt={item.judul} fit="cover" loading="lazy"/>
|
||||
<Image
|
||||
src={item.image?.link || '/images/placeholder-small.jpg'}
|
||||
height={200}
|
||||
alt={item.judul}
|
||||
fit="cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
</Card.Section>
|
||||
<Badge color="blue" variant="light" mt="md">
|
||||
{item.kategoriKegiatan?.nama || kategori}
|
||||
</Badge>
|
||||
<Text fw={600} size="lg" mt="sm" lineClamp={2}>{item.judul}</Text>
|
||||
<Text size="sm" c="dimmed" lineClamp={3} style={{wordBreak: "break-word", whiteSpace: "normal"}} mt="xs" dangerouslySetInnerHTML={{ __html: item.deskripsiLengkap }} />
|
||||
<Text fw={600} size="lg" mt="sm" lineClamp={2}>
|
||||
{item.judul}
|
||||
</Text>
|
||||
<Text
|
||||
size="sm"
|
||||
c="dimmed"
|
||||
lineClamp={3}
|
||||
style={{ wordBreak: 'break-word', whiteSpace: 'normal' }}
|
||||
mt="xs"
|
||||
dangerouslySetInnerHTML={{ __html: item.deskripsiLengkap }}
|
||||
/>
|
||||
<Group justify="apart" mt="md" gap="xs">
|
||||
<Text size="xs" c="dimmed">
|
||||
{new Date(item.createdAt).toLocaleDateString('id-ID', {
|
||||
@@ -150,6 +210,8 @@ export default function Content({ kategori }: { kategori: string }) {
|
||||
))}
|
||||
</SimpleGrid>
|
||||
)}
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
|
||||
{/* Pagination */}
|
||||
<Center mt="xl">
|
||||
|
||||
@@ -1,47 +1,64 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
'use client'
|
||||
'use client';
|
||||
|
||||
import gotongRoyongState from '@/app/admin/(dashboard)/_state/lingkungan/gotong-royong';
|
||||
import { Badge, Box, Button, Card, Center, Container, Divider, Flex, Grid, GridCol, Group, Image, Pagination, Paper, SimpleGrid, Skeleton, Stack, Text, Title } from '@mantine/core';
|
||||
import {
|
||||
Badge,
|
||||
Box,
|
||||
Button,
|
||||
Card,
|
||||
Center,
|
||||
Container,
|
||||
Divider,
|
||||
Flex,
|
||||
Grid,
|
||||
GridCol,
|
||||
Group,
|
||||
Image,
|
||||
Pagination,
|
||||
Paper,
|
||||
SimpleGrid,
|
||||
Skeleton,
|
||||
Stack,
|
||||
Text,
|
||||
Title,
|
||||
Transition,
|
||||
} from '@mantine/core';
|
||||
import { IconArrowRight, IconCalendar } from '@tabler/icons-react';
|
||||
import { useTransitionRouter } from 'next-view-transitions';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { motion } from 'framer-motion';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { useEffect } from 'react';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
|
||||
function Page() {
|
||||
export default function Page() {
|
||||
const searchParams = useSearchParams();
|
||||
const router = useTransitionRouter();
|
||||
const router = useRouter();
|
||||
|
||||
// Parameter URL
|
||||
const search = searchParams.get('search') || '';
|
||||
const page = parseInt(searchParams.get('page') || '1');
|
||||
|
||||
// Gunakan proxy untuk state
|
||||
const state = useProxy(gotongRoyongState.kegiatanDesa);
|
||||
const featured = useProxy(gotongRoyongState.kegiatanDesa.findFirst); // ✅ Berita utama
|
||||
const featured = useProxy(gotongRoyongState.kegiatanDesa.findFirst);
|
||||
const loadingGrid = state.findMany.loading;
|
||||
const loadingFeatured = featured.loading;
|
||||
|
||||
// Load berita utama (hanya sekali)
|
||||
useEffect(() => {
|
||||
if (!featured.data && !loadingFeatured) {
|
||||
gotongRoyongState.kegiatanDesa.findFirst.load();
|
||||
}
|
||||
}, [featured.data, loadingFeatured]);
|
||||
|
||||
// Load berita terbaru (untuk grid) saat page/search berubah
|
||||
useEffect(() => {
|
||||
const limit = 3; // Sesuaikan dengan tampilan grid
|
||||
const limit = 3;
|
||||
state.findMany.load(page, limit, search);
|
||||
}, [page, search]);
|
||||
|
||||
// Update URL saat page berubah
|
||||
const handlePageChange = (newPage: number) => {
|
||||
const url = new URLSearchParams(searchParams.toString());
|
||||
if (search) url.set('search', search);
|
||||
if (newPage > 1) url.set('page', newPage.toString());
|
||||
else url.delete('page'); // biar page=1 ga muncul di URL
|
||||
|
||||
else url.delete('page');
|
||||
router.replace(`?${url.toString()}`);
|
||||
};
|
||||
|
||||
@@ -49,14 +66,34 @@ function Page() {
|
||||
const paginatedNews = state.findMany.data || [];
|
||||
const totalPages = state.findMany.totalPages || 1;
|
||||
|
||||
// Animasi transisi halus tapi tetap instant load
|
||||
const MotionBox = motion(Box as any);
|
||||
|
||||
// fallback kosong
|
||||
if (!loadingGrid && !loadingFeatured && paginatedNews.length === 0) {
|
||||
return (
|
||||
<Box py={20}>
|
||||
<Container size="xl" px={{ base: "md", md: "xl" }}>
|
||||
{/* === Gotong royong Utama (Tetap) === */}
|
||||
{loadingFeatured ? (
|
||||
<Center><Skeleton h={400} /></Center>
|
||||
) : featuredData ? (
|
||||
<Box mb={50}>
|
||||
<Container size="xl" py={80} ta="center">
|
||||
<Title order={2} mb="md">Belum Ada Data Gotong Royong</Title>
|
||||
<Text c="dimmed">Tidak ada data gotong royong yang tersedia saat ini.</Text>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<MotionBox
|
||||
key={`${page}-${search}`}
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: -10 }}
|
||||
transition={{ duration: 0.2, ease: 'easeOut' }}
|
||||
py={20}
|
||||
>
|
||||
<Container size="xl" px={{ base: 'md', md: 'xl' }}>
|
||||
{/* === Gotong Royong Utama === */}
|
||||
<Transition mounted={!loadingFeatured} transition="fade" duration={200} timingFunction="ease-out">
|
||||
{(styles) =>
|
||||
featuredData ? (
|
||||
<Box mb={50} style={styles}>
|
||||
<Text fz="h2" fw={700} mb="md">Gotong royong Utama</Text>
|
||||
<Paper shadow="md" radius="md" withBorder>
|
||||
<Grid gutter={0}>
|
||||
@@ -78,7 +115,12 @@ function Page() {
|
||||
{featuredData.kategoriKegiatan?.nama || 'Gotong royong'}
|
||||
</Badge>
|
||||
<Title order={2} mb="md">{featuredData.judul}</Title>
|
||||
<Text c="dimmed" lineClamp={3} mb="md" dangerouslySetInnerHTML={{ __html: featuredData.deskripsiSingkat }} />
|
||||
<Text
|
||||
c="dimmed"
|
||||
lineClamp={3}
|
||||
mb="md"
|
||||
dangerouslySetInnerHTML={{ __html: featuredData.deskripsiSingkat }}
|
||||
/>
|
||||
</div>
|
||||
<Group justify="apart" mt="auto">
|
||||
<Group gap="xs">
|
||||
@@ -87,14 +129,18 @@ function Page() {
|
||||
{new Date(featuredData.createdAt).toLocaleDateString('id-ID', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric'
|
||||
year: 'numeric',
|
||||
})}
|
||||
</Text>
|
||||
</Group>
|
||||
<Button
|
||||
variant="light"
|
||||
rightSection={<IconArrowRight size={16} />}
|
||||
onClick={() => router.push(`/darmasaba/lingkungan/gotong-royong/${featuredData.kategoriKegiatan?.nama}/${featuredData.id}`)}
|
||||
onClick={() =>
|
||||
router.push(
|
||||
`/darmasaba/lingkungan/gotong-royong/${featuredData.kategoriKegiatan?.nama}/${featuredData.id}`
|
||||
)
|
||||
}
|
||||
>
|
||||
Baca Selengkapnya
|
||||
</Button>
|
||||
@@ -104,31 +150,36 @@ function Page() {
|
||||
</Grid>
|
||||
</Paper>
|
||||
</Box>
|
||||
) : null}
|
||||
) : (
|
||||
<Skeleton h={400} radius="md" mb="xl" />
|
||||
)
|
||||
}
|
||||
</Transition>
|
||||
|
||||
{/* === Gotong royong Terbaru (Berubah Saat Pagination) === */}
|
||||
{/* === Gotong royong Terbaru === */}
|
||||
<Box mt={50}>
|
||||
<Title order={2} mb="md">Gotong royong Terbaru</Title>
|
||||
<Divider mb="xl" />
|
||||
|
||||
{loadingGrid ? (
|
||||
<Transition mounted={!loadingGrid} transition="fade" duration={200} timingFunction="ease-out">
|
||||
{(styles) =>
|
||||
loadingGrid ? (
|
||||
<SimpleGrid cols={{ base: 1, sm: 2, lg: 3 }} spacing="xl">
|
||||
{Array(3).fill(0).map((_, i) => (
|
||||
{Array(3)
|
||||
.fill(0)
|
||||
.map((_, i) => (
|
||||
<Skeleton key={i} h={300} radius="md" />
|
||||
))}
|
||||
</SimpleGrid>
|
||||
) : paginatedNews.length === 0 ? (
|
||||
<Text c="dimmed" ta="center">Tidak ada gotong royong ditemukan.</Text>
|
||||
<Text c="dimmed" ta="center">
|
||||
Tidak ada gotong royong ditemukan.
|
||||
</Text>
|
||||
) : (
|
||||
<Box style={styles}>
|
||||
<SimpleGrid cols={{ base: 1, sm: 2, lg: 3 }} spacing="xl" verticalSpacing="xl">
|
||||
{paginatedNews.map((item) => (
|
||||
<Card
|
||||
key={item.id}
|
||||
shadow="sm"
|
||||
p="lg"
|
||||
radius="md"
|
||||
withBorder
|
||||
>
|
||||
<Card key={item.id} shadow="sm" p="lg" radius="md" withBorder>
|
||||
<Card.Section>
|
||||
<Image
|
||||
src={item.image?.link || '/images/placeholder-small.jpg'}
|
||||
@@ -143,27 +194,49 @@ function Page() {
|
||||
{item.kategoriKegiatan?.nama || 'Gotong royong'}
|
||||
</Badge>
|
||||
|
||||
<Text fw={600} size="lg" mt="sm" lineClamp={2}>{item.judul}</Text>
|
||||
<Text fw={600} size="lg" mt="sm" lineClamp={2}>
|
||||
{item.judul}
|
||||
</Text>
|
||||
|
||||
<Text size="sm" c="dimmed" lineClamp={3} mt="xs" dangerouslySetInnerHTML={{ __html: item.deskripsiSingkat }} />
|
||||
<Text
|
||||
size="sm"
|
||||
c="dimmed"
|
||||
lineClamp={3}
|
||||
mt="xs"
|
||||
dangerouslySetInnerHTML={{ __html: item.deskripsiSingkat }}
|
||||
/>
|
||||
|
||||
<Flex align="center" justify="apart" mt="md" gap="xs">
|
||||
<Text size="xs" c="dimmed">
|
||||
{new Date(item.createdAt).toLocaleDateString('id-ID', {
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
year: 'numeric'
|
||||
year: 'numeric',
|
||||
})}
|
||||
</Text>
|
||||
|
||||
<Button p="xs" variant="light" rightSection={<IconArrowRight size={16} />} onClick={() => router.push(`/darmasaba/lingkungan/gotong-royong/${item.kategoriKegiatan?.nama}/${item.id}`)}>Baca Selengkapnya</Button>
|
||||
<Button
|
||||
p="xs"
|
||||
variant="light"
|
||||
rightSection={<IconArrowRight size={16} />}
|
||||
onClick={() =>
|
||||
router.push(
|
||||
`/darmasaba/lingkungan/gotong-royong/${item.kategoriKegiatan?.nama}/${item.id}`
|
||||
)
|
||||
}
|
||||
>
|
||||
Baca Selengkapnya
|
||||
</Button>
|
||||
</Flex>
|
||||
</Card>
|
||||
))}
|
||||
</SimpleGrid>
|
||||
)}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
</Transition>
|
||||
|
||||
{/* Pagination hanya untuk berita terbaru */}
|
||||
{/* Pagination */}
|
||||
<Center mt="xl">
|
||||
<Pagination
|
||||
total={totalPages}
|
||||
@@ -176,9 +249,6 @@ function Page() {
|
||||
</Center>
|
||||
</Box>
|
||||
</Container>
|
||||
</Box>
|
||||
</MotionBox>
|
||||
);
|
||||
}
|
||||
|
||||
export default Page;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
import stateBimbinganBelajarDesa from '@/app/admin/(dashboard)/_state/pendidikan/bimbingan-belajar-desa';
|
||||
import colors from '@/con/colors';
|
||||
import { Box, Paper, SimpleGrid, Skeleton, Stack, Text, Title, Tooltip, Divider, Badge } from '@mantine/core';
|
||||
import { Box, Paper, SimpleGrid, Skeleton, Stack, Text, Title, Tooltip, Divider, Badge, Group } from '@mantine/core';
|
||||
import { useShallowEffect } from '@mantine/hooks';
|
||||
import { useProxy } from 'valtio/utils';
|
||||
import { IconMapPin, IconCalendarTime, IconBook2 } from '@tabler/icons-react';
|
||||
@@ -49,46 +49,46 @@ function Page() {
|
||||
<SimpleGrid cols={{ base: 1, md: 3 }} spacing="xl">
|
||||
<Paper p="xl" radius="lg" shadow="md" withBorder bg={colors['white-trans-1']}>
|
||||
<Stack gap="sm">
|
||||
<Box>
|
||||
<Badge variant="gradient" gradient={{ from: colors['blue-button'], to: 'cyan' }} size="lg" radius="sm" mb="sm">
|
||||
{stateTujuanProgram.findById.data?.judul}
|
||||
</Badge>
|
||||
<Group>
|
||||
<Tooltip label="Gambaran manfaat utama program" position="top-start" withArrow>
|
||||
<Box>
|
||||
<IconBook2 size={36} stroke={1.5} color={colors['blue-button']} />
|
||||
</Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
<Badge variant="gradient" gradient={{ from: colors['blue-button'], to: 'cyan' }} size="lg" radius="sm" mb="sm">
|
||||
{stateTujuanProgram.findById.data?.judul}
|
||||
</Badge>
|
||||
</Group>
|
||||
<Text fz="md" style={{wordBreak: "break-word", whiteSpace: "normal"}} lh={1.6} dangerouslySetInnerHTML={{ __html: stateTujuanProgram.findById.data?.deskripsi }} />
|
||||
</Stack>
|
||||
</Paper>
|
||||
<Paper p="xl" radius="lg" shadow="md" withBorder bg={colors['white-trans-1']}>
|
||||
<Stack gap="sm">
|
||||
<Box>
|
||||
<Badge variant="gradient" gradient={{ from: colors['blue-button'], to: 'cyan' }} size="lg" radius="sm" mb="sm">
|
||||
{stateLokasiDanJadwal.findById.data?.judul}
|
||||
</Badge>
|
||||
<Group>
|
||||
<Tooltip label="Tempat dan waktu pelaksanaan" position="top-start" withArrow>
|
||||
<Box>
|
||||
<IconMapPin size={36} stroke={1.5} color={colors['blue-button']} />
|
||||
</Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
<Badge variant="gradient" gradient={{ from: colors['blue-button'], to: 'cyan' }} size="lg" radius="sm" mb="sm">
|
||||
{stateLokasiDanJadwal.findById.data?.judul}
|
||||
</Badge>
|
||||
</Group>
|
||||
<Text fz="md" lh={1.6} style={{wordBreak: "break-word", whiteSpace: "normal"}} dangerouslySetInnerHTML={{ __html: stateLokasiDanJadwal.findById.data?.deskripsi }} />
|
||||
</Stack>
|
||||
</Paper>
|
||||
<Paper p="xl" radius="lg" shadow="md" withBorder bg={colors['white-trans-1']}>
|
||||
<Stack gap="sm">
|
||||
<Box>
|
||||
<Badge variant="gradient" gradient={{ from: colors['blue-button'], to: 'cyan' }} size="lg" radius="sm" mb="sm">
|
||||
{stateFasilitas.findById.data?.judul}
|
||||
</Badge>
|
||||
<Group>
|
||||
<Tooltip label="Sarana yang disediakan untuk peserta" position="top-start" withArrow>
|
||||
<Box>
|
||||
<IconCalendarTime size={36} stroke={1.5} color={colors['blue-button']} />
|
||||
</Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
<Badge variant="gradient" gradient={{ from: colors['blue-button'], to: 'cyan' }} size="lg" radius="sm" mb="sm">
|
||||
{stateFasilitas.findById.data?.judul}
|
||||
</Badge>
|
||||
</Group>
|
||||
<Text fz="md" lh={1.6} style={{wordBreak: "break-word", whiteSpace: "normal"}} dangerouslySetInnerHTML={{ __html: stateFasilitas.findById.data?.deskripsi }} />
|
||||
</Stack>
|
||||
</Paper>
|
||||
|
||||
@@ -56,7 +56,7 @@ export default function Content() {
|
||||
try {
|
||||
await state.dataPerpustakaan.findMany.load(
|
||||
currentPage,
|
||||
10,
|
||||
3,
|
||||
searchQuery,
|
||||
''
|
||||
);
|
||||
|
||||
@@ -1,6 +1,63 @@
|
||||
'use client'
|
||||
import { ActionIcon, Anchor, Box, Button, Center, Container, Divider, Flex, Group, Image, Paper, SimpleGrid, Stack, Text, TextInput, Title } from '@mantine/core';
|
||||
import { IconAt, IconBrandFacebook, IconBrandInstagram, IconBrandTwitter, IconBrandWhatsapp } from '@tabler/icons-react';
|
||||
import { IconAt, IconBrandFacebook, IconBrandInstagram, IconBrandTiktok, IconBrandYoutube } from '@tabler/icons-react';
|
||||
|
||||
const sosialMedia = [
|
||||
{
|
||||
title: "Facebook",
|
||||
link: "https://www.facebook.com/DarmasabaDesaku",
|
||||
icon: IconBrandFacebook,
|
||||
},
|
||||
{
|
||||
title: "Instagram",
|
||||
link: "https://www.instagram.com/ddarmasaba/",
|
||||
icon: IconBrandInstagram,
|
||||
},
|
||||
{
|
||||
title: "Youtube",
|
||||
link: "https://www.youtube.com/channel/UCtPw9WOQO7d2HIKzKgel4Xg",
|
||||
icon: IconBrandYoutube,
|
||||
},
|
||||
{
|
||||
title: "Tiktok",
|
||||
link: "https://www.tiktok.com/@desa.darmasaba?is_from_webapp=1&sender_device=pc",
|
||||
icon: IconBrandTiktok,
|
||||
},
|
||||
]
|
||||
|
||||
const layanandesa = [
|
||||
{
|
||||
title: "Administrasi Kependudukan",
|
||||
link: "/darmasaba/desa/layanan/",
|
||||
},
|
||||
{
|
||||
title: "Layanan Sosial",
|
||||
link: "/darmasaba/ekonomi/program-kemiskinan",
|
||||
},
|
||||
{
|
||||
title: "Pengaduan Masyarakat",
|
||||
link: "/darmasaba/keamanan/laporan-publik",
|
||||
},
|
||||
{
|
||||
title: "Informasi Publik",
|
||||
link: "/darmasaba/ppid/daftar-informasi-publik-desa-darmasaba",
|
||||
},
|
||||
]
|
||||
|
||||
const tautanPenting = [
|
||||
{
|
||||
title: "Portal Badung",
|
||||
link: "/darmasaba/desa/berita/semua",
|
||||
},
|
||||
{
|
||||
title: "E-Government",
|
||||
link: "/darmasaba/inovasi/desa-digital-smart-village",
|
||||
},
|
||||
{
|
||||
title: "Transparansi",
|
||||
link: "/darmasaba/ppid/daftar-informasi-publik-desa-darmasaba",
|
||||
}
|
||||
]
|
||||
|
||||
function Footer() {
|
||||
return (
|
||||
@@ -64,31 +121,39 @@ function Footer() {
|
||||
Darmasaba adalah desa budaya yang kaya akan tradisi dan nilai-nilai warisan Bali.
|
||||
</Text>
|
||||
<Flex gap="md" mt="sm" c="#F3F2EC">
|
||||
<ActionIcon variant="subtle" color="white"><IconBrandFacebook size={22} /></ActionIcon>
|
||||
<ActionIcon variant="subtle" color="white"><IconBrandInstagram size={22} /></ActionIcon>
|
||||
<ActionIcon variant="subtle" color="white"><IconBrandTwitter size={22} /></ActionIcon>
|
||||
<ActionIcon variant="subtle" color="white"><IconBrandWhatsapp size={22} /></ActionIcon>
|
||||
{sosialMedia.map((item) => (
|
||||
<ActionIcon
|
||||
key={item.title}
|
||||
component="a"
|
||||
href={item.link}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
variant="subtle"
|
||||
color="white"
|
||||
>
|
||||
<item.icon size={22} />
|
||||
</ActionIcon>
|
||||
))}
|
||||
</Flex>
|
||||
|
||||
</Stack>
|
||||
</Box>
|
||||
|
||||
<Box>
|
||||
<Stack gap="xs">
|
||||
<Text c="white" fz="md" fw={700}>Layanan Desa</Text>
|
||||
<Anchor c="#F3F2EC" fz="xs">Administrasi Kependudukan</Anchor>
|
||||
<Anchor c="#F3F2EC" fz="xs">Layanan Sosial</Anchor>
|
||||
<Anchor c="#F3F2EC" fz="xs">Pengaduan Masyarakat</Anchor>
|
||||
<Anchor c="#F3F2EC" fz="xs">Informasi Publik</Anchor>
|
||||
{layanandesa.map((item) => (
|
||||
<Anchor key={item.title} c="#F3F2EC" fz="xs" href={item.link}>{item.title}</Anchor>
|
||||
))}
|
||||
</Stack>
|
||||
</Box>
|
||||
|
||||
<Box>
|
||||
<Stack gap="xs">
|
||||
<Text c="white" fz="md" fw={700}>Tautan Penting</Text>
|
||||
<Anchor c="#F3F2EC" fz="xs">Portal Badung</Anchor>
|
||||
<Anchor c="#F3F2EC" fz="xs">E-Government</Anchor>
|
||||
<Anchor c="#F3F2EC" fz="xs">Transparansi</Anchor>
|
||||
<Anchor c="#F3F2EC" fz="xs">Unduhan</Anchor>
|
||||
{tautanPenting.map((item) => (
|
||||
<Anchor key={item.title} c="#F3F2EC" fz="xs" href={item.link}>{item.title}</Anchor>
|
||||
))}
|
||||
</Stack>
|
||||
</Box>
|
||||
|
||||
|
||||
@@ -11,16 +11,20 @@ export function NavbarSearch() {
|
||||
// Close when clicking outside
|
||||
useEffect(() => {
|
||||
function handleClickOutside(event: MouseEvent) {
|
||||
if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
|
||||
const target = event.target as HTMLElement;
|
||||
// Only close if clicking outside both the search input and results
|
||||
if (
|
||||
containerRef.current &&
|
||||
!containerRef.current.contains(target) &&
|
||||
!target.closest('.search-result-item') // Add a class to your search result items
|
||||
) {
|
||||
setIsOpen(false);
|
||||
stateNav.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Add event listener
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () => {
|
||||
// Clean up
|
||||
document.removeEventListener('mousedown', handleClickOutside);
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
'use client';
|
||||
import searchState, { debouncedFetch } from '@/app/api/[[...slugs]]/_lib/search/searchState';
|
||||
import { Box, Center, Loader, Modal, Text, TextInput } from '@mantine/core';
|
||||
import { Box, Center, Loader, Popover, Text, TextInput } from '@mantine/core';
|
||||
import { IconX } from '@tabler/icons-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useSnapshot } from 'valtio';
|
||||
@@ -8,14 +9,14 @@ import getDetailUrl from './searchUrl';
|
||||
|
||||
export default function GlobalSearch() {
|
||||
const snap = useSnapshot(searchState);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [opened, setOpened] = useState(false);
|
||||
|
||||
// Toggle modal when there's a query
|
||||
// buka popover saat ada query
|
||||
useEffect(() => {
|
||||
setIsOpen(!!snap.query);
|
||||
setOpened(!!snap.query);
|
||||
}, [snap.query]);
|
||||
|
||||
// Infinite scroll
|
||||
// infinite scroll
|
||||
useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
const bottom = window.innerHeight + window.scrollY >= document.body.offsetHeight - 200;
|
||||
@@ -25,8 +26,49 @@ export default function GlobalSearch() {
|
||||
return () => window.removeEventListener('scroll', handleScroll);
|
||||
}, [snap.loading]);
|
||||
|
||||
const handleSelect = async (e: React.MouseEvent, item: any) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
const url = getDetailUrl(item);
|
||||
if (!url) return;
|
||||
|
||||
// Immediately close the search dropdown
|
||||
setOpened(false);
|
||||
searchState.results = []; // Clear results immediately
|
||||
searchState.loading = false;
|
||||
|
||||
// Use window.location for navigation to ensure full page reload
|
||||
window.location.href = url;
|
||||
};
|
||||
|
||||
return (
|
||||
<Box style={{ position: 'relative', width: '100%' }}>
|
||||
<Box pos="relative">
|
||||
<Popover
|
||||
opened={opened && !!snap.query}
|
||||
onChange={(isOpen) => {
|
||||
if (!isOpen) {
|
||||
// Clear search state when popover is closed
|
||||
searchState.query = '';
|
||||
searchState.results = [];
|
||||
searchState.page = 1;
|
||||
searchState.nextPage = null;
|
||||
}
|
||||
setOpened(isOpen);
|
||||
}}
|
||||
width="target"
|
||||
position="bottom"
|
||||
shadow="md"
|
||||
withinPortal
|
||||
radius="md"
|
||||
zIndex={1000} // Add this line to ensure it appears above other elements
|
||||
styles={{
|
||||
dropdown: {
|
||||
zIndex: 1000, // Add this to ensure the dropdown appears above other elements
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Popover.Target>
|
||||
<TextInput
|
||||
placeholder="Cari apapun..."
|
||||
value={snap.query}
|
||||
@@ -35,6 +77,7 @@ export default function GlobalSearch() {
|
||||
debouncedFetch();
|
||||
}}
|
||||
radius="xl"
|
||||
size="md"
|
||||
rightSection={
|
||||
snap.query ? (
|
||||
<IconX
|
||||
@@ -43,54 +86,43 @@ export default function GlobalSearch() {
|
||||
onClick={() => {
|
||||
searchState.query = '';
|
||||
searchState.results = [];
|
||||
searchState.page = 1;
|
||||
searchState.nextPage = null;
|
||||
setOpened(false);
|
||||
}}
|
||||
/>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
</Popover.Target>
|
||||
|
||||
{/* Modal for search results */}
|
||||
<Modal
|
||||
opened={isOpen && !!snap.query}
|
||||
onClose={() => {
|
||||
searchState.query = '';
|
||||
searchState.results = [];
|
||||
}}
|
||||
withCloseButton={false}
|
||||
size="lg"
|
||||
padding={0}
|
||||
radius="md"
|
||||
style={{ position: 'absolute', top: '100%', left: 0, right: 0, zIndex: 1000 }}
|
||||
styles={{
|
||||
content: { // Changed from 'modal' to 'content'
|
||||
backgroundColor: 'white',
|
||||
boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)',
|
||||
borderRadius: '0.5rem',
|
||||
maxHeight: '400px',
|
||||
overflow: 'hidden',
|
||||
},
|
||||
<Popover.Dropdown
|
||||
p={0}
|
||||
style={{
|
||||
maxHeight: 350,
|
||||
overflowY: 'auto',
|
||||
borderRadius: 12,
|
||||
zIndex: 1000, // Add this line to ensure dropdown stays above other elements
|
||||
position: 'relative', // Add this to contain child elements
|
||||
}}
|
||||
>
|
||||
<Box style={{ maxHeight: '400px', overflowY: 'auto' }}>
|
||||
{snap.results.map((item, i) => (
|
||||
{snap.results.length > 0 ? (
|
||||
snap.results.map((item, i) => (
|
||||
<Box
|
||||
key={i}
|
||||
p="sm"
|
||||
className="search-result-item" // Add this class
|
||||
style={{
|
||||
borderBottom: '1px solid #eee',
|
||||
cursor: 'pointer',
|
||||
transition: 'background 0.2s',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
maxWidth: '100%',
|
||||
position: 'relative', // Add this
|
||||
zIndex: 1, // Add this to ensure proper stacking context
|
||||
backgroundColor: 'white', // Ensure background is set
|
||||
}}
|
||||
onMouseEnter={(e) => (e.currentTarget.style.background = '#f5f5f5')}
|
||||
onMouseEnter={(e) => (e.currentTarget.style.background = '#f7f7f7')}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.background = 'transparent')}
|
||||
onClick={() => {
|
||||
const url = getDetailUrl(item);
|
||||
window.location.href = url;
|
||||
}}
|
||||
onClick={(e) => handleSelect(e, item)} // Pass the event here
|
||||
>
|
||||
<Text size="sm" fw={500}>
|
||||
{item.judul || item.namaPasar || item.nama || item.name}
|
||||
@@ -99,14 +131,14 @@ export default function GlobalSearch() {
|
||||
dari modul: {item.type}
|
||||
</Text>
|
||||
</Box>
|
||||
))}
|
||||
{snap.loading && (
|
||||
))
|
||||
) : (
|
||||
<Center py="md">
|
||||
<Loader size="sm" />
|
||||
{snap.loading ? <Loader size="sm" /> : <Text fz="sm">Tidak ada hasil</Text>}
|
||||
</Center>
|
||||
)}
|
||||
</Box>
|
||||
</Modal>
|
||||
</Popover.Dropdown>
|
||||
</Popover>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -42,7 +42,6 @@ export default function ProfileView({ data }: ProfileViewProps) {
|
||||
loading="lazy"
|
||||
style={{
|
||||
objectPosition: 'bottom center',
|
||||
transform: 'translateY(10px)', // sedikit turun biar natural
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
|
||||
@@ -62,26 +62,26 @@ const getDetailUrl = (item: { type?: string; id: string | number; [key: string]:
|
||||
programPenghijauan: '/darmasaba/lingkungan/program-penghijauan',
|
||||
dataLingkunganDesa: '/darmasaba/lingkungan/data-lingkungan-desa',
|
||||
gotongRoyong: '/darmasaba/lingkungan/gotong-royong',
|
||||
tujuanEdukasiLingkungan: '/darmasaba/lingkungan/tujuan-edukasi-lingkungan',
|
||||
materiEdukasiLingkungan: '/darmasaba/lingkungan/materi-edukasi-lingkungan',
|
||||
contohEdukasiLingkungan: '/darmasaba/lingkungan/contoh-edukasi-lingkungan',
|
||||
filosofiTriHita: '/darmasaba/lingkungan/filosofi-tri-hita',
|
||||
bentukKonservasiBerdasarkanAdat: '/darmasaba/lingkungan/bentuk-konservasi-berdasarkan-adat',
|
||||
nilaiKonservasiAdat: '/darmasaba/lingkungan/nilai-konservasi-adat',
|
||||
jenjangPendidikan: '/darmasaba/inovasi/jenjang-pendidikan',
|
||||
lembaga: '/darmasaba/inovasi/lembaga',
|
||||
siswa: '/darmasaba/inovasi/siswa',
|
||||
pengajar: '/darmasaba/inovasi/pengajar',
|
||||
keunggulanProgram: '/darmasaba/inovasi/keunggulan-program',
|
||||
tujuanProgram: '/darmasaba/inovasi/tujuan-program',
|
||||
programUnggulan: '/darmasaba/inovasi/program-unggulan',
|
||||
lokasiJadwalBimbinganBelajarDesa: '/darmasaba/inovasi/lokasi-jadwal-bimbingan-belajar-desa',
|
||||
fasilitasBimbinganBelajarDesa: '/darmasaba/inovasi/fasilitas-bimbingan-belajar-desa',
|
||||
tujuanPendidikanNonFormal: '/darmasaba/inovasi/tujuan-pendidikan-non-formal',
|
||||
tempatKegiatan: '/darmasaba/inovasi/tempat-kegiatan',
|
||||
jenisProgramYangDiselenggarakan: '/darmasaba/inovasi/jenis-program-yang-diselenggarakan',
|
||||
dataPerpustakaan: '/darmasaba/inovasi/data-perpustakaan',
|
||||
dataPendidikan: '/darmasaba/inovasi/data-pendidikan',
|
||||
tujuanEdukasiLingkungan: '/darmasaba/lingkungan/edukasi-lingkungan',
|
||||
materiEdukasiLingkungan: '/darmasaba/lingkungan/edukasi-lingkungan',
|
||||
contohEdukasiLingkungan: '/darmasaba/lingkungan/edukasi-lingkungan',
|
||||
filosofiTriHita: '/darmasaba/lingkungan/konservasi-adat-bali',
|
||||
bentukKonservasiBerdasarkanAdat: '/darmasaba/lingkungan/konservasi-adat-bali',
|
||||
nilaiKonservasiAdat: '/darmasaba/lingkungan/konservasi-adat-bali',
|
||||
jenjangPendidikan: '/darmasaba/pendidikan/info-sekolah/semua',
|
||||
lembaga: '/darmasaba/pendidikan/info-sekolah/semua/lembaga',
|
||||
siswa: '/darmasaba/pendidikan/info-sekolah/semua/siswa',
|
||||
pengajar: '/darmasaba/pendidikan/info-sekolah/semua/pengajar',
|
||||
keunggulanProgram: '/darmasaba/pendidikan/beasiswa-desa',
|
||||
tujuanProgram: '/darmasaba/pendidikan/program-pendidikan-anak',
|
||||
programUnggulan: '/darmasaba/pendidikan/program-pendidikan-anak',
|
||||
lokasiJadwalBimbinganBelajarDesa: '/darmasaba/pendidikan/bimbingan-belajar-desa',
|
||||
fasilitasBimbinganBelajarDesa: '/darmasaba/pendidikan/bimbingan-belajar-desa',
|
||||
tujuanPendidikanNonFormal: '/darmasaba/pendidikan/pendidikan-non-formal',
|
||||
tempatKegiatan: '/darmasaba/pendidikan/pendidikan-non-formal',
|
||||
jenisProgramYangDiselenggarakan: '/darmasaba/pendidikan/pendidikan-non-formal',
|
||||
dataPerpustakaan: '/darmasaba/pendidikan/perpustakaan-digital/semua',
|
||||
dataPendidikan: '/darmasaba/pendidikan/data-pendidikan',
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
-webkit-backdrop-filter: blur(40px);
|
||||
backdrop-filter: blur(40px);
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
z-index: 50;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user