Skip to content

Commit

Permalink
Merge pull request #142 from ItRecode/FE-150
Browse files Browse the repository at this point in the history
[FE-150] feat: 마이 λ ˆμ½”λ“œ(였늘의 λ ˆμ½”λ“œ API 적용)
  • Loading branch information
sookyeonghwang authored Jan 24, 2023
2 parents 37aec33 + 0eada10 commit 8b7309e
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 73 deletions.
24 changes: 23 additions & 1 deletion src/apis/record.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { AxiosResponse } from 'axios'
import {
IMemoryRecordList,
IMyRecordRequestParam,
IRecordByDateList,
} from 'types/recordData'
import { baseInstance } from './instance'

const MEMORY_RECORD_SIZE = 7
Expand All @@ -20,7 +26,9 @@ export const getRecord = async (recordId: string | undefined) => {
}
}

export const getMemoryRecord = (pageParam: number) => {
export const getMemoryRecord = (
pageParam: number
): Promise<AxiosResponse<IMemoryRecordList>> => {
return baseInstance.get(`/record/memory`, {
params: {
memoryRecordPage: pageParam,
Expand All @@ -36,3 +44,17 @@ export const deleteRecord = async (recordId: string | undefined) => {
return res.data
}
}

export const getRecordByDate = ({
date,
page,
size,
}: IMyRecordRequestParam): Promise<AxiosResponse<IRecordByDateList>> => {
return baseInstance.get(`/record`, {
params: {
date,
page,
size,
},
})
}
3 changes: 3 additions & 0 deletions src/assets/myRecordIcon/calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/pages/MyRecord/MemoryRecord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function MemoryRecord() {
return <></>
}

if (!memoryRecord?.pages[0].data) {
if (!memoryRecord?.pages[0].data.totalCount) {
return (
<div className="ml-[2px] mt-6 flex gap-6 px-6">
<div
Expand Down
3 changes: 1 addition & 2 deletions src/pages/MyRecord/MemoryRecordItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ export default function MemoryRecordItem({
onClick={() => navigate(`/record/${recordId}`)}
>
<PlusIcons />
<p className="mt-[10px] w-[50px] text-primary-2">전체보기</p>
<p className="mt-[10px] w-max text-primary-2">전체보기</p>
</div>
)}
</div>
</div>
)
}
// e: React.MouseEvent<HTMLDivElement, MouseEvent>,
1 change: 0 additions & 1 deletion src/pages/MyRecord/MyRecord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default function MyRecord() {
<CloseIcon className="absolute right-[10px] cursor-pointer" />
</div>
</section>
<h1 className="mt-7 px-6 text-2xl font-semibold">마이 λ ˆμ½”λ“œ</h1>
<TodayRecord />
<h2 className="mt-3 px-6 text-lg font-semibold leading-[18px]">
λ‚˜λ§Œμ˜ μΆ”μ–΅ λ ˆμ½”λ“œ
Expand Down
17 changes: 17 additions & 0 deletions src/pages/MyRecord/MyRecordCalendar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import { ReactComponent as Calendar } from '@assets/myRecordIcon/calendar.svg'
import { useNavigate } from 'react-router-dom'

export default function MyRecordCalendar() {
const navigate = useNavigate()

return (
<div className="mt-7 flex items-center justify-between px-6">
<h1 className="text-2xl font-semibold">마이 λ ˆμ½”λ“œ</h1>
<Calendar
className="cursor-pointer"
onClick={() => navigate('/notservice')}
/>
</div>
)
}
121 changes: 71 additions & 50 deletions src/pages/MyRecord/TodayRecord.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,81 @@
import React from 'react'
import { useNavigate } from 'react-router-dom'
// import { ITodayRecord } from 'types/recordData'
// import { getChipIconName } from '@pages/DetailRecord/getChipIconName'
// import Chip from '@components/Chip'
// import recordIcons from '@assets/record_icons'
import { useMyRecord } from '@react-query/hooks/useMyRecord'
import { getChipIconName } from '@pages/DetailRecord/getChipIconName'
import Chip from '@components/Chip'
import recordIcons from '@assets/record_icons'
import { getFormattedDate } from '@utils/getFormattedDate'
import MyRecordCalendar from './MyRecordCalendar'

export default function TodayRecord() {
const navigate = useNavigate()
// const todayWriteRecord = null
// const background_color = `bg-${todayWriteRecord?.colorName}`
// const RecordIcon = recordIcons[`${todayWriteRecord?.iconName}`]
const { todayRecord, isLoading } = useMyRecord()
const background_color = `bg-${todayRecord?.colorName}`
const RecordIcon = recordIcons[`${todayRecord?.iconName}`]

if (isLoading) {
return <></>
}

if (!todayRecord) {
return (
<>
<MyRecordCalendar />
<div className="mt-10 mb-[49px] w-full text-center">
<span className="text-xs leading-5">
였늘 μ“΄ λ ˆμ½”λ“œκ°€ μ—†μ–΄μš”!
<br />
λ ˆμ½”λ“œλ₯Ό μ“°κ³  좔얡을 κ³΅μœ ν•΄λ³΄μ„Έμš”.
</span>
<div
className="mt-4 cursor-pointer text-sm font-semibold leading-5 text-primary-2 underline underline-offset-4"
onClick={() => navigate('/record/add')}
>
λ ˆμ½”λ“œ μΆ”κ°€ν•˜λŸ¬ κ°€κΈ°
</div>
</div>
</>
)
}

// if (!todayWriteRecord) {
return (
<div className="mt-10 mb-[49px] w-full text-center">
<span className="text-xs leading-5">
였늘 μ“΄ λ ˆμ½”λ“œκ°€ μ—†μ–΄μš”!
<br />
λ ˆμ½”λ“œλ₯Ό μ“°κ³  좔얡을 κ³΅μœ ν•΄λ³΄μ„Έμš”.
</span>
<div
className="mt-4 cursor-pointer text-sm font-semibold leading-5 text-primary-2 underline underline-offset-4"
onClick={() => navigate('/record/add')}
>
λ ˆμ½”λ“œ μΆ”κ°€ν•˜λŸ¬ κ°€κΈ°
<>
<MyRecordCalendar />
<div className="mt-4 mb-10 w-full px-6">
<div
className="cursor-pointer text-xs"
onClick={() => navigate(`/record/${todayRecord.recordId}`)}
>
{getFormattedDate(new Date(todayRecord.createdAt), 'point')}
</div>
<div
className="mt-4 flex w-fit cursor-pointer"
onClick={() => navigate(`/record/${todayRecord.recordId}`)}
>
<div
className={`${background_color} flex h-[86px] w-[86px] items-center rounded-2xl`}
>
<RecordIcon className="flex aspect-square w-full" />
</div>
<div className="ml-4 flex flex-col">
<div className="inline">
<Chip
property="small"
icon={getChipIconName(todayRecord.categoryName)}
message={`${todayRecord.categoryName}`}
active={true}
pointer={false}
/>
</div>
<h2 className="mt-3 text-lg font-semibold leading-[18px]">
{todayRecord.title}
</h2>
<div className="mt-[14px] text-xs leading-4">
λŒ“κΈ€ {todayRecord.commentCount}개
</div>
</div>
</div>
</div>
</div>
</>
)
// }

// return (
// <div className="mt-4 mb-10 w-full px-6">
// {/* TODO: λ ˆμ½”λ“œ λ§Œλ“  λ‚ μ§œ === 였늘 λ‚ μ§œ ν¬λ§·νŒ…ν•˜κΈ°*/}
// <div className="text-xs">{todayWriteRecord.createdAt}</div>
// <div className="mt-4 flex">
// <div
// className={`${background_color} flex h-[86px] w-[86px] items-center rounded-2xl`}
// >
// <RecordIcon className="flex aspect-square w-full" />
// </div>
// <div className="ml-4 flex flex-col">
// <Chip
// property="small"
// icon={getChipIconName(todayWriteRecord.categoryName)}
// message={`${todayWriteRecord.categoryName}`}
// active={true}
// pointer={false}
// />
// <h2 className="mt-3 text-lg font-semibold leading-[18px]">
// {todayWriteRecord.title}
// </h2>
// <div className="mt-[14px] text-xs leading-4">
// λŒ“κΈ€ {todayWriteRecord.commentCount}개
// </div>
// </div>
// </div>
// </div>
// )
}
3 changes: 0 additions & 3 deletions src/react-query/hooks/useMemoryRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export const useMemoryRecord = () => {
return null
},
retry: false,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
})

return {
Expand Down
26 changes: 26 additions & 0 deletions src/react-query/hooks/useMyRecord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { QUERY_KEYS } from '@react-query/queryKeys'
import { useQuery } from '@tanstack/react-query'
import { getRecordByDate } from '@apis/record'
import { getFormattedDate } from '@utils/getFormattedDate'

export const useMyRecord = () => {
const today = new Date()

const { data: records = null, isLoading } = useQuery(
[QUERY_KEYS.todayRecord],
async () =>
await getRecordByDate({
date: getFormattedDate(today, 'hyphen'),
page: 0,
size: 1,
}),
{
retry: false,
}
)

return {
todayRecord: records?.data.recordByDateDtos[0],
isLoading,
}
}
3 changes: 0 additions & 3 deletions src/react-query/hooks/useUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export const useUser = () => {
isLoading,
} = useQuery([QUERY_KEYS.user], async () => await getUserInfo(), {
retry: false,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
})

return { user, refetch, isLoading }
Expand Down
36 changes: 24 additions & 12 deletions src/types/recordData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@ export interface IRecordDataType {
imageUrls: string[]
}

export interface ITodayRecord {
title: string
categoryName: string
commentCount: number
iconName: string
colorName: string
createdAt: string
}

export interface IMemoryRecordList {
hasNextPage: boolean
isFirstPage: boolean
isLastPage: boolean
memoryRecordList: IMemoryRecord[]
totalCount: number
totalPage: number
}

export interface IMemoryRecord {
Expand All @@ -39,3 +29,25 @@ export interface IRecordMemoryComment {
commentId: number
content: string
}

export interface IRecordByDate {
recordId: number
title: string
categoryName: string
commentCount: number
iconName: string
colorName: string
createdAt: string
}

export interface IRecordByDateList {
recordByDateDtos: IRecordByDate[]
totalCount: number
totalPage: number
}

export interface IMyRecordRequestParam {
date: string
page: number
size: number
}
13 changes: 13 additions & 0 deletions src/utils/getFormattedDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const DATE_JOIN_POINT = 'point'

export const getFormattedDate = (date: Date, type: string) => {
const year = date.getFullYear()
const month = (date.getMonth() + 1).toString().padStart(2, '0')
const day = date.getDate().toString().padStart(2, '0')

if (type === DATE_JOIN_POINT) {
return `${year}.${month}.${day}`
}

return `${year}-${month}-${day}`
}

0 comments on commit 8b7309e

Please sign in to comment.