Skip to content

Commit d7e1770

Browse files
committed
♻️ [refactor] : 배열 수정용 onArrayChange 함수 구현 및 Filter width 기본값 지정
1 parent df215ce commit d7e1770

File tree

8 files changed

+18
-41
lines changed

8 files changed

+18
-41
lines changed

src/components/filters/FilterDropdown.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div
33
class="filter-container"
44
:style="{ width: width ? `${width}px` : '' }"
5-
:class="!width && 'grow'">
5+
:class="width === 'full' && 'grow'">
66
<span class="filter-title">{{ title }}</span>
77
<div
88
class="filter-dropdown"
@@ -31,9 +31,9 @@
3131
import type { Filter } from '@/types/common'
3232
import { ref } from 'vue'
3333
import { dropdownIcon } from '@/constants/iconPath'
34-
import CommonIcons from '../common/CommonIcons.vue';
34+
import CommonIcons from '../common/CommonIcons.vue'
3535
36-
const { title, value, width, optionList } = defineProps<Filter>()
36+
const { title, value, width = '120', optionList } = defineProps<Filter>()
3737
const emit = defineEmits(['update:value'])
3838
3939
const isDropdownOpened = ref(false)

src/components/filters/FilterDropdownMulti.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div
33
class="filter-container"
44
:style="{ width: width ? `${width}px` : '' }"
5-
:class="!width && 'grow'">
5+
:class="width === 'full' && 'grow'">
66
<span class="filter-title">{{ title }}</span>
77
<div
88
class="filter-dropdown"
@@ -34,9 +34,9 @@
3434
import type { Filter } from '@/types/common'
3535
import { ref } from 'vue'
3636
import { dropdownIcon } from '@/constants/iconPath'
37-
import CommonIcons from '../common/CommonIcons.vue';
37+
import CommonIcons from '../common/CommonIcons.vue'
3838
39-
const { title, width, optionList, value } = defineProps<Filter>()
39+
const { title, width = '120', optionList, value } = defineProps<Filter>()
4040
const emit = defineEmits(['update:value'])
4141
4242
const isDropdownOpened = ref(false)

src/components/filters/FilterInput.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div
33
class="filter-container"
44
:style="{ width: width ? `${width}px` : '' }"
5-
:class="!width && 'grow'">
5+
:class="width === 'full' && 'grow'">
66
<span class="filter-title">{{ title }}</span>
77
<input
88
@input="onValueChange"
@@ -13,7 +13,7 @@
1313
<script setup lang="ts">
1414
import type { Filter } from '@/types/common'
1515
16-
const { title, width } = defineProps<Filter>()
16+
const { title, width = '120' } = defineProps<Filter>()
1717
const emit = defineEmits(['update:value'])
1818
1919
const onValueChange = (event: Event) => {

src/components/hooks/useRequestParamsChange.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ import { useRequestParamsStore } from '@/stores/params'
33
export const useRequestParamsChange = () => {
44
const { params } = useRequestParamsStore()
55

6+
const onArrayChange = <Value extends number | string>(array: Value[], value: Value) => {
7+
return array.includes(value) ? array.filter(el => el !== value) : [...array, value]
8+
}
9+
610
const onTermChange = (value: string) => {
711
if (value === '') {
812
params.term = ''
13+
} else {
14+
params.term = Number(value)
915
}
10-
params.term = Number(value)
1116
}
1217
const onTitleChange = (value: string) => {
1318
params.title = value
@@ -16,27 +21,13 @@ export const useRequestParamsChange = () => {
1621
params.nickName = value
1722
}
1823
const onMainChange = (value: number) => {
19-
if (params.mainCategoryId.includes(value)) {
20-
params.mainCategoryId = [...params.mainCategoryId].filter(el => el !== value)
21-
} else {
22-
params.mainCategoryId.push(value)
23-
}
24+
params.mainCategoryId = onArrayChange(params.mainCategoryId, value)
2425
}
2526
const onSubChange = (value: number) => {
26-
if (params.categoryId.includes(value)) {
27-
params.categoryId = [...params.categoryId].filter(el => el !== value)
28-
} else {
29-
params.categoryId.push(value)
30-
}
27+
params.categoryId = onArrayChange(params.categoryId, value)
3128
}
3229
const onTaskStatusChange = (value: string) => {
33-
if (params.taskStatus) {
34-
if (params.taskStatus.includes(value)) {
35-
params.taskStatus = [...params.taskStatus].filter(el => el !== value)
36-
} else {
37-
params.taskStatus.push(value)
38-
}
39-
}
30+
params.taskStatus = onArrayChange(params.taskStatus!, value)
4031
}
4132
const onPageSizeChange = (value: string) => {
4233
params.pageSize = Number(value)

src/components/my-request/MyRequestFilterBar.vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<div class="flex gap-4">
33
<FilterDropdown
44
title="조회 기간"
5-
:width="120"
65
:option-list="TERM_LIST"
76
:value="String(store.params.term)"
87
@update:value="onParamsChange.onTermChange" />
@@ -14,23 +13,19 @@
1413
@update:sub="onParamsChange.onSubChange" />
1514
<FilterInput
1615
title="제목"
17-
:width="120"
1816
:value="store.params.title"
1917
@update:value="onParamsChange.onTitleChange" />
2018
<FilterInput
21-
:width="120"
2219
title="처리자"
2320
:value="store.params.nickName"
2421
@update:value="onParamsChange.onNickNameChange" />
2522
<FilterDropdownMulti
2623
title="상태"
27-
:width="120"
2824
:option-list="TASK_STATUS_LIST"
2925
:value="store.params.taskStatus!"
3026
@update:value="onParamsChange.onTaskStatusChange" />
3127
<FilterDropdown
3228
title="페이지 당 개수"
33-
:width="120"
3429
:option-list="PAGE_SIZE_LIST"
3530
:value="String(store.params.pageSize)"
3631
@update:value="onParamsChange.onPageSizeChange" />

src/components/request-history/RequestHistoryFilterBar.vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<div class="flex gap-4">
33
<FilterDropdown
44
title="조회 기간"
5-
:width="120"
65
:option-list="TERM_LIST"
76
:value="String(store.params.term)"
87
@update:value="onParamsChange.onTermChange" />
@@ -14,23 +13,19 @@
1413
@update:sub="onParamsChange.onSubChange" />
1514
<FilterInput
1615
title="제목"
17-
:width="120"
1816
:value="store.params.title"
1917
@update:value="onParamsChange.onTitleChange" />
2018
<FilterInput
21-
:width="120"
2219
title="이름"
2320
:value="store.params.nickName"
2421
@update:value="onParamsChange.onNickNameChange" />
2522
<FilterDropdownMulti
2623
title="상태"
27-
:width="120"
2824
:option-list="TASK_STATUS_LIST"
2925
:value="store.params.taskStatus!"
3026
@update:value="onParamsChange.onTaskStatusChange" />
3127
<FilterDropdown
3228
title="페이지 당 개수"
33-
:width="120"
3429
:option-list="PAGE_SIZE_LIST"
3530
:value="String(store.params.pageSize)"
3631
@update:value="onParamsChange.onPageSizeChange" />

src/components/requested/RequestedFilterBar.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<div class="flex gap-4">
33
<FilterDropdown
44
title="조회 기간"
5-
:width="120"
65
:option-list="TERM_LIST"
76
:value="String(store.params.term)"
87
@update:value="onParamsChange.onTermChange" />
@@ -14,17 +13,14 @@
1413
@update:sub="onParamsChange.onSubChange" />
1514
<FilterInput
1615
title="제목"
17-
:width="120"
1816
:value="store.params.title"
1917
@update:value="onParamsChange.onTitleChange" />
2018
<FilterInput
21-
:width="120"
2219
title="처리자"
2320
:value="store.params.nickName"
2421
@update:value="onParamsChange.onNickNameChange" />
2522
<FilterDropdown
2623
title="페이지 당 개수"
27-
:width="120"
2824
:option-list="PAGE_SIZE_LIST"
2925
:value="String(store.params.pageSize)"
3026
@update:value="onParamsChange.onPageSizeChange" />

src/types/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface TitleBarProps {
77

88
export interface Filter {
99
title: string
10-
width?: number
10+
width?: string
1111
optionList?: Option[]
1212
value: (Ref<string> | string) | (Ref<string[]> | string[])
1313
}

0 commit comments

Comments
 (0)