-
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.
Merge pull request #223 from boostcampwm2023/develop
[Deploy] Week5 ver1 배포
- Loading branch information
Showing
90 changed files
with
1,731 additions
and
436 deletions.
There are no files selected for viewing
Binary file not shown.
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,12 +1,24 @@ | ||
FROM node:20-alpine | ||
FROM node:20-alpine AS builder | ||
|
||
WORKDIR /app | ||
|
||
ADD . /app | ||
|
||
RUN SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm_config_arch=x64 npm_config_platform=linuxmusl yarn workspace server add sharp@0.32.1 | ||
RUN SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm_config_arch=x64 npm_config_platform=linux yarn workspace server add sharp@0.32.6 | ||
RUN yarn workspace server build | ||
|
||
FROM node:20-alpine AS runner | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /app/packages/server/dist /app/packages/server/dist | ||
COPY --from=builder /app/packages/server/package.json /app/packages/server/package.json | ||
COPY --from=builder /app/.yarn /app/.yarn | ||
COPY --from=builder /app/.pnp.cjs /app/.pnp.cjs | ||
COPY --from=builder /app/.yarnrc.yml /app/.yarnrc.yml | ||
COPY --from=builder /app/yarn.lock /app/yarn.lock | ||
COPY --from=builder /app/package.json /app/package.json | ||
|
||
EXPOSE 3000 | ||
|
||
ENTRYPOINT ["yarn", "workspace", "server", "start:prod"] |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,112 @@ | ||
import { useEffect, useReducer, useState } from 'react'; | ||
import { Heart } from 'lucide-react'; | ||
import { Button } from 'shared/ui'; | ||
import theme from 'shared/ui/styles/theme'; | ||
import { BASE_URL } from '@constants'; | ||
import { useFetch } from 'shared/hooks'; | ||
import instance from 'shared/apis/AxiosInterceptor'; | ||
|
||
interface PropsType { | ||
postId: string; | ||
count: number; | ||
} | ||
|
||
const LIKE = 'LIKE'; | ||
const UNLIKE = 'UNLIKE'; | ||
const SET_LIKE = 'SET_LIKE'; | ||
|
||
const likeReducer = ( | ||
state: { isLiked: boolean; likeCount: number }, | ||
action: { type: string; bool?: boolean }, | ||
): { isLiked: boolean; likeCount: number } => { | ||
switch (action.type) { | ||
case LIKE: | ||
return { | ||
...state, | ||
isLiked: true, | ||
likeCount: state.likeCount + 1, | ||
}; | ||
case UNLIKE: | ||
return { | ||
...state, | ||
isLiked: false, | ||
likeCount: state.likeCount - 1, | ||
}; | ||
case SET_LIKE: | ||
return { | ||
...state, | ||
isLiked: action.bool ?? state.isLiked, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default function Like({ postId, count }: PropsType) { | ||
const [state, dispatch] = useReducer(likeReducer, { | ||
isLiked: false, | ||
likeCount: count, | ||
}); | ||
const [isButtonDisabled, setButtonDisabled] = useState(false); | ||
|
||
useEffect(() => { | ||
const fetchLike = async () => { | ||
const { data, error } = useFetch<boolean>( | ||
`${BASE_URL}post/${postId}/is-liked`, | ||
); | ||
if (error) return; | ||
dispatch({ type: SET_LIKE, bool: data }); | ||
}; | ||
fetchLike(); | ||
}, []); | ||
|
||
const clickLike = async () => { | ||
if (isButtonDisabled) return; | ||
|
||
try { | ||
setButtonDisabled(true); | ||
const res = await instance({ | ||
method: 'patch', | ||
url: `/post/${postId}/is-liked`, | ||
}); | ||
if (res.status === 200) dispatch({ type: LIKE }); | ||
} finally { | ||
setButtonDisabled(false); | ||
} | ||
}; | ||
|
||
const cancelLike = async () => { | ||
if (isButtonDisabled) return; | ||
|
||
try { | ||
setButtonDisabled(true); | ||
const res = await instance({ | ||
method: 'patch', | ||
url: `/post/${postId}/unlike`, | ||
}); | ||
if (res.status === 200) dispatch({ type: UNLIKE }); | ||
} finally { | ||
setButtonDisabled(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Button | ||
size="m" | ||
buttonType={state.isLiked ? 'warning-border' : 'Button'} | ||
onClick={state.isLiked ? cancelLike : clickLike} | ||
disabled={isButtonDisabled} | ||
> | ||
<Heart | ||
style={{ marginRight: '10px' }} | ||
color={ | ||
state.isLiked | ||
? theme.colors.warning.pressed | ||
: theme.colors.stroke.default | ||
} | ||
fill={state.isLiked ? theme.colors.warning.pressed : 'none'} | ||
/> | ||
{state.likeCount} | ||
</Button> | ||
); | ||
} |
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,11 +1,10 @@ | ||
import instance from 'shared/apis/AxiosInterceptor'; | ||
import { BASE_URL } from '@constants'; | ||
|
||
export const deletePost = async (postId: string) => { | ||
const { data } = await instance({ | ||
const res = await instance({ | ||
method: 'DELETE', | ||
url: `${BASE_URL}/post/${postId}`, | ||
url: `/post/${postId}`, | ||
}); | ||
|
||
return data; | ||
return res; | ||
}; |
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
Oops, something went wrong.