feat: 검색조건 변경 시 선택아이템 초기화
This commit is contained in:
parent
94ce738a73
commit
e482ba1400
@ -13,7 +13,7 @@ export default function Suitable() {
|
||||
const [searchValue, setSearchValue] = useState('')
|
||||
|
||||
const { getSuitableCommCode, clearSuitableSearch } = useSuitable()
|
||||
const { suitableCommCode, selectedCategory, setSelectedCategory, setSearchKeyword, clearSearchKeyword } = useSuitableStore()
|
||||
const { suitableCommCode, selectedCategory, setSelectedCategory, setSearchKeyword } = useSuitableStore()
|
||||
|
||||
const handleInputSearch = async () => {
|
||||
if (!searchValue.trim()) {
|
||||
@ -25,13 +25,13 @@ export default function Suitable() {
|
||||
|
||||
const handleInputClear = () => {
|
||||
setSearchValue('')
|
||||
clearSearchKeyword()
|
||||
clearSuitableSearch({ items: true, keyword: true})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getSuitableCommCode()
|
||||
return () => {
|
||||
clearSuitableSearch()
|
||||
clearSuitableSearch({ items: true, category: true, keyword: true })
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
@ -6,8 +6,8 @@ import { useSuitableStore } from '@/store/useSuitableStore'
|
||||
|
||||
export default function SuitableButton() {
|
||||
const popupController = usePopupController()
|
||||
const { getSuitableIds } = useSuitable()
|
||||
const { selectedItems, addAllSelectedItem, clearSelectedItems } = useSuitableStore()
|
||||
const { getSuitableIds, clearSuitableSearch } = useSuitable()
|
||||
const { selectedItems, addAllSelectedItem } = useSuitableStore()
|
||||
|
||||
const handleSelectAll = async () => {
|
||||
addAllSelectedItem(await getSuitableIds())
|
||||
@ -30,7 +30,7 @@ export default function SuitableButton() {
|
||||
全選択<i className="btn-arr"></i>
|
||||
</button>
|
||||
) : (
|
||||
<button className="btn-frame n-blue icon" onClick={clearSelectedItems}>
|
||||
<button className="btn-frame n-blue icon" onClick={() => clearSuitableSearch({ items: true })}>
|
||||
全て解除<i className="btn-arr"></i>
|
||||
</button>
|
||||
)}
|
||||
|
||||
@ -118,6 +118,7 @@ export function useSuitable() {
|
||||
queryKey: ['suitables', 'list', selectedCategory, searchKeyword],
|
||||
queryFn: async (context) => {
|
||||
const pageParam = context.pageParam as number
|
||||
if (pageParam === 1) clearSuitableSearch({ items: true })
|
||||
return await getSuitables({
|
||||
pageNumber: pageParam,
|
||||
...(selectedCategory && { category: selectedCategory }),
|
||||
@ -146,10 +147,10 @@ export function useSuitable() {
|
||||
])
|
||||
}
|
||||
|
||||
const clearSuitableSearch = () => {
|
||||
clearSelectedItems()
|
||||
clearSearchKeyword()
|
||||
clearSelectedCategory()
|
||||
const clearSuitableSearch = ({ items = false, category = false, keyword = false }: { items?: boolean; category?: boolean; keyword?: boolean }) => {
|
||||
if (items) clearSelectedItems()
|
||||
if (category) clearSelectedCategory()
|
||||
if (keyword) clearSearchKeyword()
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user