Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/TaskStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
<span
class="text-xs font-bold"
:class="textColor">
{{ status }}
{{ statusAsText(status) }}
</span>
</div>
</template>

<script setup lang="ts">
import type { Status } from '@/types/common'
import { statusAsColor } from '@/utils/statusAsColor'
import { statusAsText } from '@/utils/statusAsText'
import { computed } from 'vue'

const { status, isActive } = defineProps<{
Expand Down
2 changes: 1 addition & 1 deletion src/components/lists/ListContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="w-full flex flex-col grow overflow-hidden">
<slot name="listBar" />

<div class="overflow-y-auto">
<div class="grow overflow-y-auto">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 커스텀 속성인가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아뇨 grow는 flex-grow:1을 부여하는 클래스로 상위 요소가 flex인 경우 다른 요소들이 차지하는 공간을 제외하고 나머지의 공간을 차지하게 하는 속성입니다.
grow를 하여 NoContent 컴포넌트를 위한 공간을 확보해주기 위한 클래스입니다!

<slot name="listCards" />
</div>
</div>
Expand Down
28 changes: 14 additions & 14 deletions src/components/lists/ListPagination.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<template>
<div class="w-fit flex items-center gap-2 relative">
<div
v-if="totalPage"
class="w-fit h-6 flex items-center gap-2 relative">
<div class="flex gap-1 absolute left-0 top-1/2 -translate-x-[calc(100%+8px)] -translate-y-1/2">
<button
v-if="pageSet[0] !== 0"
v-if="pageSet[0] !== 1"
@click="onPrevSetClick"
class="rounded hover:bg-primary2">
<CommonIcons :name="prevSetIcon" />
Expand All @@ -21,7 +23,7 @@
page === pageNumber ? 'text-white font-bold bg-primary1' : 'text-black hover:bg-primary2'
"
@click="onNumClick(page)">
{{ page + 1 }}
{{ page }}
</button>
<div class="flex gap-1 absolute right-0 top-1/2 translate-x-[calc(100%+8px)] -translate-y-1/2">
<button
Expand Down Expand Up @@ -49,7 +51,7 @@ const emit = defineEmits(['update:pageNumber'])

const pageSet = computed(() => {
const set: number[] = []
const startPage = Math.floor(pageNumber / 5) * 5
const startPage = Math.floor((pageNumber - 1) / 5) * 5 + 1
for (let i = 0; i < 5; i++) {
if (startPage + i > totalPage) break
set.push(startPage + i)
Expand All @@ -58,24 +60,22 @@ const pageSet = computed(() => {
})

const onPrevSetClick = () => {
const prevSetEnd = Math.floor(pageNumber / 5) * 5 - 1
emit('update:pageNumber', prevSetEnd)
const prevSetEnd = Math.floor((pageNumber - 1) / 5) * 5
emit('update:pageNumber', prevSetEnd - 1)
}
const onPrevClick = () => {
const prev = Math.max(pageNumber - 1, 0)
emit('update:pageNumber', prev)
const prev = Math.max(pageNumber - 1, 1)
emit('update:pageNumber', prev - 1)
}
const onNextClick = () => {
const next = Math.min(pageNumber + 1, totalPage)
emit('update:pageNumber', next)
emit('update:pageNumber', next - 1)
}
const onNextSetClick = () => {
const nextSetStart = Math.floor(pageNumber / 5) * 5 + 5
emit('update:pageNumber', Math.min(nextSetStart, totalPage))
const nextSetStart = Math.floor((pageNumber - 1) / 5) * 5 + 6
emit('update:pageNumber', nextSetStart - 1)
}
const onNumClick = (num: number) => {
emit('update:pageNumber', num)
emit('update:pageNumber', num - 1)
}
</script>

<style scoped></style>
9 changes: 9 additions & 0 deletions src/components/lists/NoContent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<div class="w-full h-full flex justify-center items-center">
<span class="text-lg text-disabled font-bold">{{ content }}</span>
</div>
</template>

<script setup lang="ts">
const { content = '표시할 항목이 없어요' } = defineProps<{ content?: string }>()
</script>
2 changes: 1 addition & 1 deletion src/components/my-request/MyRequestFilterBar.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="flex gap-4">
<div class="flex gap-4 z-30">
<FilterDropdown
title="조회 기간"
:option-list="TERM_LIST"
Expand Down
18 changes: 15 additions & 3 deletions src/components/my-request/MyRequestList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
v-for="info in data?.content"
:key="info.taskId"
:info="info" />
<NoContent v-if="data?.content.length === 0" />
</template>

<template #pagination>
<ListPagination
:page-number="params.page"
:total-page="data?.totalPages || 0"
:page-number="params.page + 1"
:total-page="totalPage"
@update:page-number="onPageChange" />
</template>
</ListContainer>
Expand All @@ -30,6 +31,8 @@ import axiosInstance from '@/utils/axios'
import { useQuery } from '@tanstack/vue-query'
import { useParseParams } from '../hooks/useParseParams'
import type { MyRequestResponse } from '@/types/user'
import { ref, watch } from 'vue'
import NoContent from '../lists/NoContent.vue'

const { params } = useRequestParamsStore()
const onPageChange = (value: number) => {
Expand All @@ -43,7 +46,7 @@ const fetchRequestList = async () => {
headers: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로그인 되면 해당 헤더 안쓰셔도 됩니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵! 일단 현재는 원시적으로 직접 토큰값을 저장하여 환경 변수로 사용하고 있는데 이후 로그인 구현 후 그에 맞게 수정하도록 하겠습니다!

Authorization: `Bearer ${import.meta.env.VITE_ACCESS_TOKEN}`
},
params: parsedParams
params: { ...parsedParams, pageSize: 1 }
})
return response.data
}
Expand All @@ -52,4 +55,13 @@ const { data } = useQuery<MyRequestResponse>({
queryKey: ['myRequest', params],
queryFn: fetchRequestList
})

watch(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 useEffect랑 depenency처럼 동작하는거 맞을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 맞습니다!
watch() 안에 watch가 주시할 변수를 지정하고, 안에 콜백 함수를 통해 해당 변수가 변화 했을 때의 행동을 정의하였습니다.
또한 once 옵션을 통해 처음에 data를 받아왔을 때의 totalPage를 한 번 설정하고, 이후 재설정을 막아 ListPagination 컴포넌트의 반복적인 리렌더링을 막고자 하였습니다!

data,
() => {
if (data.value?.totalPages) totalPage.value = data.value.totalPages
},
{ once: true }
)
const totalPage = ref(0)
</script>
5 changes: 3 additions & 2 deletions src/components/my-request/MyRequestListCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
import type { ListCardProps } from '@/types/common'
import ListCardTab from '../lists/ListCardTab.vue'
import type { MyRequestListData } from '@/types/user'
import { formatDate } from '@/utils/date'

const { info } = defineProps<{ info: MyRequestListData }>()
const myRequestTabList: ListCardProps[] = [
{ content: info.taskCode, width: 120, isTextXs: true },
{ content: info.requestedAt, width: 80 },
{ content: formatDate(info.requestedAt), width: 80 },
{ content: info.mainCategoryName, width: 80 },
{ content: info.categoryName, width: 80 },
{ content: info.title },
{ content: info.processorName, width: 120, profileImg: info.processorImg },
{ content: info.taskStatus, width: 64, isStatus: true },
{ content: info.finishedAt, width: 80 }
{ content: info.finishedAt ? formatDate(info.finishedAt) : '', width: 80 }
]
</script>
Loading