-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
117 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './revalidate-record-detail'; | ||
export * from './save-swim-data'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use server'; | ||
|
||
import { cookies } from 'next/headers'; | ||
|
||
import { PoolInfoDataProps, SwimTimeDataProps } from '../types'; | ||
|
||
interface SaveSwimDataProps { | ||
swimTimeData: SwimTimeDataProps; | ||
savedSwimTimeData?: SwimTimeDataProps; | ||
poolInfoData?: PoolInfoDataProps; | ||
savedPoolInfoData?: PoolInfoDataProps; | ||
} | ||
|
||
//cookie에 가장 최근 수영 기록 정보를 저장하는 함수 | ||
export const saveSwimData = ({ | ||
swimTimeData, | ||
savedSwimTimeData, | ||
poolInfoData, | ||
savedPoolInfoData, | ||
}: SaveSwimDataProps) => { | ||
if ( | ||
//저장된 수영 시간이 없거나 | ||
!savedSwimTimeData || | ||
//저장된 수영 시간이 있지만, 현재 생성한 기록의 수영 시간과 다르면 | ||
(savedSwimTimeData && | ||
(savedSwimTimeData.start !== swimTimeData.start || | ||
savedSwimTimeData.end !== swimTimeData.end)) | ||
) | ||
cookies().set( | ||
'swimTime', | ||
JSON.stringify({ start: swimTimeData.start, end: swimTimeData.end }), | ||
{ | ||
maxAge: Infinity, | ||
httpOnly: true, | ||
secure: true, | ||
}, | ||
); | ||
|
||
//현재 생성한 기록에 수영장 정보가 포함되어 있을 때 | ||
if (poolInfoData) { | ||
//저장된 수영장 정보가 없거나 | ||
if ( | ||
!savedPoolInfoData || | ||
//저장된 수영장 정보가 있지만, 현재 생성한 기록의 수영장 정보와 다르다면 | ||
(savedPoolInfoData && savedPoolInfoData.id !== poolInfoData.id) | ||
) { | ||
cookies().set( | ||
'poolInfo', | ||
JSON.stringify({ name: poolInfoData.name, id: poolInfoData.id }), | ||
{ | ||
maxAge: Infinity, | ||
httpOnly: true, | ||
secure: true, | ||
}, | ||
); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './form-section'; | ||
export * from './saved-swim-data'; | ||
export * from './stroke'; | ||
export * from './time'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//cookie에 저장될 수 있는 수영 기록 정보 types | ||
export interface SwimTimeDataProps { | ||
start: string; | ||
end: string; | ||
} | ||
|
||
export interface PoolInfoDataProps { | ||
name: string; | ||
id: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export * from './highlight-text'; | ||
export * from './is-future'; | ||
export * from './remove-special-symbols'; | ||
export * from './swim-data'; | ||
export * from './time'; |
This file was deleted.
Oops, something went wrong.