'use client' import { useState } from 'react' import InquiryItems from './InquiryItems' import InquiryFilter from './InquiryFilter' import LoadMoreButton from '../LoadMoreButton' const inquiryDummyData = [ { id: 1, title: 'post', content: 'content', file: 'file.png', createdAt: '2024-01-01', writer: 'writer', category: 'A', }, { id: 2, title: 'post', content: 'content', file: 'file.png', createdAt: '2024-01-01', writer: 'writer1', category: 'B', }, { id: 3, title: 'post', content: 'content', file: null, createdAt: '2024-01-01', writer: 'writer1', category: 'C', }, { id: 4, title: 'post', content: 'content', file: null, createdAt: '2024-01-01', writer: 'writer1', category: 'A', }, { id: 5, title: 'post', content: 'content', file: null, createdAt: '2024-01-01', writer: 'writer1', category: 'B', }, { id: 6, title: 'post', content: 'content', file: null, createdAt: '2024-01-01', writer: 'writer1', category: 'C', }, { id: 7, title: 'post', content: 'content', file: 'file.png', createdAt: '2024-01-01', writer: 'writer', category: 'A', }, { id: 8, title: 'post', content: 'content', file: 'file.png', createdAt: '2024-01-01', writer: 'writer1', category: 'B', }, { id: 9, title: 'post', content: 'content', file: null, createdAt: '2024-01-01', writer: 'writer1', category: 'C', }, { id: 10, title: 'post', content: 'content', file: 'file.png', createdAt: '2024-01-01', writer: 'writer1', category: 'A', }, { id: 11, title: 'post', content: 'content', file: 'file.png', createdAt: '2024-01-01', writer: 'writer', category: 'B', }, { id: 12, title: 'post', content: 'content', file: null, createdAt: '2024-01-01', writer: 'writer1', category: 'C', }, ] export default function InquiryList() { const [visibleItems, setVisibleItems] = useState(5) const [isMyPostsOnly, setIsMyPostsOnly] = useState(false) const [category, setCategory] = useState('') const [search, setSearch] = useState('') const [hasMore, setHasMore] = useState(inquiryDummyData.length > 5) const inquriyData = () => { if (isMyPostsOnly) { return inquiryDummyData.filter((item) => item.writer === 'writer') } if (category.trim().length > 0) { return inquiryDummyData.filter((item) => item.category === category) } if (search.trim().length > 0) { return inquiryDummyData.filter((item) => item.title.includes(search)) } return inquiryDummyData } const handleLoadMore = () => { const newVisibleItems = Math.min(visibleItems + 5, inquriyData().length) setVisibleItems(newVisibleItems) setHasMore(newVisibleItems < inquriyData().length) } const handleSearch = (e: React.ChangeEvent) => { setSearch(e.target.value) } const handleScrollToTop = () => { window.scrollTo({ top: 0, behavior: 'smooth' }) } return (
setIsMyPostsOnly(e.target.checked)} />
total {inquriyData().length}
) }